如何在C#中使用Telegram API发送消息 [英] How to use Telegram API in C# to send a message

查看:632
本文介绍了如何在C#中使用Telegram API发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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 ?

推荐答案

  1. 安装包Telegram.Bot
  2. 使用Botfather创建一个Bot
  3. 使用/token命令获取api密钥(仍在botfather中)
  4. 使用此代码:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆