How to use Telegram API in C# to send a message

Hadi Delphi picture Hadi Delphi · Jul 7, 2015 · Viewed 93.9k times · Source

I want use Telegram API in C# for send a simple message to a number. I found some lib's on GitHub but I am not able to use them.

Can anyone give a simple code ? Can I simply make HTTP calls ?

Answer

arlak picture arlak · Nov 6, 2015
  1. Install-Package Telegram.Bot
  2. Create a bot using the botfather
  3. get the api key using the /token command (still in botfather)
  4. use this code:

var bot = new Api("your api key here"); var t = await bot.SendTextMessage("@channelname or chat_id", "text message");

You can now pass a channel username (in the format @channelusername) in the place of chat_id in all methods (and instead of from_chat_id in forwardMessage). For this to work, the bot must be an administrator in the channel.

https://core.telegram.org/bots/api