2017-08-06 51 views
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; 
        } 
       } 
      } 
     } 
    } 
} 

回答

0

电话号码和位置,您可以添加可选的值传送到keyboardbutton,使用户可以通过按下该按钮送他/她的号码/位置:

<“request_contact”:true>代表电话号码,<“request_location”:true>代表位置。

确认:收到用户信息后,用InlineKeyboardButton显示收到的信息,其中包含2个是/否按钮。

+0

亲爱的tashakori,请你纠正代码? – ProMedia