0
我的電報機器人代碼(使用NetTelegramBotApi)如下,我需要在評論中提到的問題的幫助預覽:如何顯示接收到的信息(代碼修正要求)
- 顯示的預覽(例如:您的地址:74 Green Street,您的電話號碼:123456 &您的公司名稱:MyCo。請檢查並確認信息是正確的。
UI:Image
using NetTelegramBotApi;
using NetTelegramBotApi.Requests;
using NetTelegramBotApi.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace mybot
{
class Program
{
private static ReplyKeyboardMarkup mainMenu;
private static ReplyKeyboardMarkup confirmMenu;
private static string botToken = "***";
static void Main(string[] args)
{
mainMenu = new ReplyKeyboardMarkup
{
Keyboard = new KeyboardButton[][] {
new KeyboardButton[]
{
new KeyboardButton("Address"),
new KeyboardButton("Phone"),
new KeyboardButton("Company Name")
}
}
};
confirmMenu = new ReplyKeyboardMarkup
{
Keyboard = new KeyboardButton[][] {
new KeyboardButton[]
{
new KeyboardButton("Confirm"),
new KeyboardButton("Restart")
}
}
};
Task.Run(() => RunBot());
Console.ReadLine();
}
public static async Task RunBot()
{
var bot = new TelegramBot(botToken);
var me = await bot.MakeRequestAsync(new GetMe());
Console.Write("username is {0}", me.Username);
long offset = 0;
while (true)
{
var updates = await bot.MakeRequestAsync(new GetUpdates() { Offset = offset });
foreach (var update in updates)
{
offset = update.UpdateId + 1;
var text = update.Message.Text;
if (text == "/start" || text == "Restart")
{
var req = new SendMessage(update.Message.Chat.Id, "Please use the Menu") { ReplyMarkup = mainMenu };
await bot.MakeRequestAsync(req);
continue;
}
else if (text == "Address")
{
var req = new SendMessage(update.Message.Chat.Id, "Please enter your address:");
await bot.MakeRequestAsync(req);
continue;
}
else if (text == "Phone")
{
var req = new SendMessage(update.Message.Chat.Id, "Please enter your phone number:");
await bot.MakeRequestAsync(req);
continue;
}
else if (text == "Company Name")
{
var req = new SendMessage(update.Message.Chat.Id, "Please enter your company name:");
await bot.MakeRequestAsync(req);
/* Now, I need to show him the preview of received information to confirm.
Example:
Your Address: ***
Your Phone Number: ***
& Your Company Name: ***
Please check and confirm that the information are correct ('confirmMenu' keyboard could be used).
*/
continue;
}
else
{
var req = new SendMessage(update.Message.Chat.Id, "Error! Please follow the instructions") { ReplyMarkup = mainMenu };
await bot.MakeRequestAsync(req);
continue;
}
}
}
}
}
}
親愛的tashakori,請你糾正代碼? – ProMedia