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

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

问题描述

我想在 C# 中使用 Telegram API 向一个号码发送一条简单的消息.我在 GitHub 上找到了一些库,但我无法使用它们.

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 创建一个机器人
  3. 使用/token 命令获取 api 密钥(仍在 botfather 中)
  4. 使用此代码:

var bot = new Api("你的 api 密钥在这里");var t = await bot.SendTextMessage("@channelname or chat_id", "text message");

您现在可以传递频道用户名(格式为@channelusername)在所有方法中代替 chat_id(而不是 from_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天全站免登陆