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 ?
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 ?
9
Answers
Just look and learn how to make a POST HTTP request with your favorite language.
Then learn how to use Telegram Bot API with the documentation:
I’ve written a client library for accessing Telegram bot’s API and its source code is available in the Github. You can browse to the Telebot.cs file to see a sample of how to send a message to the bot API.
Github URL: github.com/mrtaikandi/Telebot
Nuget URL: nuget.org/packages/Telebot
https://core.telegram.org/bots/api
1-first create a channel in telegram (for example @mychanel)
2-create a telegram bot (for example @myTestBot) and get api token for next step
3-add @myTestBot to your channel(@mychanel) as administrator user
4-use below code for send message:
use this code 🙂
with https://github.com/sochix/TLSharp
Here is the easiest way I found so far. I found it here, thanks to Paolo Montalto https://medium.com/@xabaras/sending-a-message-to-a-telegram-channel-the-easy-way-eb0a0b32968
After creating a Telegram bot via BotFather and getting your destination IDs
via
https://api.telegram.org/bot[YourApiToken]/getUpdates
you can send a message to your IDs by issuing an HTTP GET request to Telegram BOT API using the following URL
https://api.telegram.org/bot[YourApiToken]/sendMessage?chat_id=[DestitationID]&text=[MESSAGE_TEXT]
Details on a simple way to create a bot and get IDs may be found here: https://programmingistheway.wordpress.com/2015/12/03/send-telegram-messages-from-c/
You can test those url strings even directly in browser.
Here is a simple method I use in C# to send messages, without dependency on any bot api related dll and async calls complication:
Same unexplicable errors.
Solution: elevate the framework dastination to minimum 4.6; errors disappear.
Perhaps official support pages at
https://telegrambots.github.io/book/1/quickstart.html
are a little bit confusing saying: “…a .NET project targeting versions 4.5+”
bye
this code work for me:
There is now WTelegramClient, using the latest Telegram Client API protocol (connecting as a user, not bot).
The library is very complete but also very easy to use. Follow the README on GitHub for an easy introduction.
To send a message to someone can be as simple as: