From ab0ef19fcfe1c57ef7869f9128f8c6287e8be33b Mon Sep 17 00:00:00 2001 From: luotuan Date: Sun, 26 Feb 2023 19:25:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(*):=20telegram=20bot=E6=8E=A5=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/telegram/telegram_channel.py | 12 +++++------- config-template.json | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/channel/telegram/telegram_channel.py b/channel/telegram/telegram_channel.py index 7edfa3f..fc08d15 100644 --- a/channel/telegram/telegram_channel.py +++ b/channel/telegram/telegram_channel.py @@ -1,4 +1,3 @@ -from telebot import util from concurrent.futures import ThreadPoolExecutor import io import requests @@ -12,8 +11,9 @@ thread_pool = ThreadPoolExecutor(max_workers=8) @bot.message_handler(commands=['help']) def send_welcome(message): - bot.send_message(message.chat.id, "

使用普通文本消息进行查询

‘画’开头使用绘画功能

", parse_mode = "HTML") + bot.send_message(message.chat.id, "我是chatGPT机器人,开始和我聊天吧!", parse_mode = "HTML") +# 处理文本类型消息 @bot.message_handler(content_types=['text']) def send_welcome(msg): # telegram消息处理 @@ -23,11 +23,12 @@ class TelegramChannel(Channel): def __init__(self): pass def startup(self): - logger.info("开始启动telegram机器人") + logger.info("开始启动[telegram]机器人") bot.infinity_polling() def handle(self, msg): 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: thread_pool.submit(self._do_send_img, msg, str(msg.chat.id)) else: @@ -59,10 +60,7 @@ class TelegramChannel(Channel): # 图片发送 logger.info('[Telegrame] sendImage, receiver={}'.format(reply_user_id)) - # splitted_text = util.split_string(image_storage, 3000) - # for text in splitted_text: - # bot.send_message(msg.chat.id, text) - bot.reply_to(msg,pic_res) + bot.send_photo(msg.chat.id,image_storage) except Exception as e: logger.exception(e) diff --git a/config-template.json b/config-template.json index aec1cd3..4a527c6 100644 --- a/config-template.json +++ b/config-template.json @@ -2,8 +2,8 @@ "model": { "type" : "openai", "openai": { - "api_key": "1313212", - "conversation_max_tokens": 2000, + "api_key": "YOUR API KEY", + "conversation_max_tokens": 1000, "character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。" } }, @@ -32,7 +32,7 @@ "host_password": "GMAIL ACCESS KEY" }, "telegram":{ - "bot_token": "5684663516:AAFRYGIcDalEZzExyoBwt-t33BZjxcTISxg" + "bot_token": "xx:xx" } } }