Skip to content
Alex edited this page Jun 25, 2017 · 4 revisions

SendMessage Method

This method sends a text message to a user or group. You can use this message to reply a message from a user.

Minimum required arguments for this method are: chatId (chat_id) and text.

chatId: identifier of the user or group to send this message to. text: your message text.

The sample code below, will receive all messages sent to your bot and will send them a "Hello" message:

        static void Main(string[] args)
        {
            var client = new TelegramBotClient()
            {
                Token = "",
                CheckInterval = 1000
            };
            client.UpdatesReceived += client_UpdatesReceived;
            client.StartCheckingUpdates();
//  IMPORTANT: If your program ends here, you won't get updates! You need a message loop to keep your program running.
        }

        static void client_UpdatesReceived(object sender, TelegramUpdateEventArgs e)
        {
            var client = (TelegramBotClient)sender;
            foreach (var update in e.Updates)
            {
                client.SendMessage(update.Message.Chat.Id, "Hello");
            }
        }