docs: update README.md

This commit is contained in:
zhayujie
2023-02-26 20:20:12 +08:00
parent 99117c31a3
commit 83c8cdf937
3 changed files with 40 additions and 25 deletions

View File

@@ -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"
}
}
```

View File

@@ -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, "<a>我是chatGPT机器人开始和我聊天吧!</a>", parse_mode = "HTML")
bot.send_message(message.chat.id, "<a>我是chatGPT机器人开始和我聊天吧!</a>", 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):

View File

@@ -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"
}