From 83c8cdf93724cdff7111989b17bdf6f52cd7a95b Mon Sep 17 00:00:00 2001 From: zhayujie Date: Sun, 26 Feb 2023 20:20:12 +0800 Subject: [PATCH] docs: update README.md --- README.md | 53 +++++++++++++++++----------- channel/telegram/telegram_channel.py | 8 +++-- config-template.json | 4 ++- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 9cd6be0..c3feb1e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ - [x] 个人微信 - [x] 公众号 (个人/企业) - [ ] 企业微信 - - [ ] Telegram + - [x] Telegram - [ ] QQ - [ ] 钉钉 - [ ] 飞书 @@ -221,14 +221,41 @@ Hit Ctrl-C to quit. 注意:需将服务器ip地址配置在 "IP白名单" 内,否则用户将收不到主动推送的消息。 -### 5. Gmail + +### 5.Telegram + +**Contributor:** [brucelt1993](https://github.com/brucelt1993) + +**5.1 获取token** + +telegram机器人申请主要是获取机器人的token id,参考[文档](https://juejin.cn/s/telegram%20bot%20token%20%E8%8E%B7%E5%8F%96)。 + +**5.2 依赖安装** + +```bash +pip3 install pyTelegramBotAPI +``` + +**5.3 配置** + +```bash +"channel": { + "type": "telegram", + "telegram":{ + "bot_token": "YOUR BOT TOKEN ID" + } + } +``` + +### 6.Gmail **需要:** 一个服务器、一个Gmail account -Follow [官方文档](https://support.google.com/mail/answer/185833?hl=en) to create APP password for google account, config as below, then cheers!!! (contributed by [Simon](https://github.com/413675377) -) +**Contributor:** [Simon](https://github.com/413675377) -```json +Follow [官方文档](https://support.google.com/mail/answer/185833?hl=en) to create APP password for google account, config as below, then cheers!!! + +```bash "channel": { "type": "gmail", "gmail": { @@ -238,19 +265,3 @@ Follow [官方文档](https://support.google.com/mail/answer/185833?hl=en) to cr } } ``` -### 6. Telegram - -telegram 机器人申请可以自行谷歌下,很简单。重要的是获取机器人的token id。 - -**依赖安装** pip install pyTelegramBotAPI - -**配置** - -```json -"channel": { - "type": "telegram", - "telegram":{ - "bot_token": "你的bot token id" - } - } -``` \ No newline at end of file diff --git a/channel/telegram/telegram_channel.py b/channel/telegram/telegram_channel.py index fc08d15..5cf1707 100644 --- a/channel/telegram/telegram_channel.py +++ b/channel/telegram/telegram_channel.py @@ -11,7 +11,7 @@ thread_pool = ThreadPoolExecutor(max_workers=8) @bot.message_handler(commands=['help']) def send_welcome(message): - bot.send_message(message.chat.id, "我是chatGPT机器人,开始和我聊天吧!", parse_mode = "HTML") + bot.send_message(message.chat.id, "我是chatGPT机器人,开始和我聊天吧!", parse_mode = "HTML") # 处理文本类型消息 @bot.message_handler(content_types=['text']) @@ -22,11 +22,13 @@ def send_welcome(msg): class TelegramChannel(Channel): def __init__(self): pass + def startup(self): logger.info("开始启动[telegram]机器人") bot.infinity_polling() + def handle(self, msg): - logger.debug("[Telegram]receive msg: " + msg.text) + logger.debug("[Telegram] receive msg: " + msg.text) img_match_prefix = self.check_prefix(msg, channel_conf_val(const.TELEGRAM, 'image_create_prefix')) # 如果是图片请求 if img_match_prefix: @@ -38,7 +40,7 @@ class TelegramChannel(Channel): context= dict() context['from_user_id'] = str(msg.chat.id) reply_text = super().build_reply_content(query, context) - logger.info('[Telegram]] reply content: {}'.format(reply_text)) + logger.info('[Telegram] reply content: {}'.format(reply_text)) bot.reply_to(msg,reply_text) def _do_send_img(self, msg, reply_user_id): diff --git a/config-template.json b/config-template.json index 4a527c6..264e875 100644 --- a/config-template.json +++ b/config-template.json @@ -7,8 +7,9 @@ "character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。" } }, + "channel": { - "type": "telegram", + "type": "terminal", "single_chat_prefix": ["bot", "@bot"], "single_chat_reply_prefix": "[bot] ", "group_chat_prefix": ["@bot"], @@ -31,6 +32,7 @@ "host_email": "xxxx@gmail.com", "host_password": "GMAIL ACCESS KEY" }, + "telegram":{ "bot_token": "xx:xx" }