如何在C#中使用Telegram API发送消息 [英] How to use Telegram API in C# to send a message
问题描述
我想在C#中使用电报API向数字发送简单消息.我在GitHub上找到了一些lib,但是我无法使用它们.
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.
任何人都可以给出一个简单的代码吗?我可以简单地进行HTTP调用吗?
Can anyone give a simple code ? Can I simply make HTTP calls ?
推荐答案
- 安装包Telegram.Bot
- 使用Botfather创建一个Bot
- 使用/token命令获取api密钥(仍在botfather中)
- 使用此代码:
var bot = new Api("your api key here");
var t = await bot.SendTextMessage("@channelname or chat_id", "text message");
var bot = new Api("your api key here");
var t = await bot.SendTextMessage("@channelname or chat_id", "text message");
您现在可以传递频道用户名(格式为@channelusername) 在所有方法中都用chat_id代替(而不是在 转发信息).为此,该漫游器必须是以下站点的管理员 频道.
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
这篇关于如何在C#中使用Telegram API发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!