using System; using System.Threading.Tasks; using System.Windows.Forms; using TelegramBotSharp; using TelegramBotSharp.Types; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public static TelegramBot bot; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { bot = new TelegramBot("146900***********************-FyoSPg"); new Task(PollMessages1).Start(); } static async void PollMessages1() { while (true) { var result = await bot.GetMessages(); foreach (Message m in result) { if (m.Chat != null) { Console.WriteLine("[{0}] {1} : {2}", m.Chat.Title, m.From.Username, m.Text); } else { Console.WriteLine("{0}: {1}", m.From.Username, m.Text); } ControlMessages1(m); } } } private static void ControlMessages1(Message m) { if (m.Text == null) return; MessageTarget target = (MessageTarget)m.Chat ?? m.From; bot.SendMessage(target, "hello"); } } }
System.Windows.Forms.Message
TelegramBotSharp.Types.Message
using TelegramBotSharpMessage = TelegramBotSharp.Types.Message
System.Windows.Forms
TelegramBotSharp
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)