mirror of
https://github.com/zhayujie/bot-on-anything.git
synced 2026-02-08 17:52:02 +08:00
telegram
This commit is contained in:
@@ -28,6 +28,9 @@ def create_channel(channel_type):
|
||||
elif channel_type == const.GMAIL:
|
||||
from channel.gmail.gmail_channel import GmailChannel
|
||||
return GmailChannel()
|
||||
elif channel_type == const.TELEGRAM:
|
||||
from channel.telegram.telegram_channel import TelegramChannel
|
||||
return TelegramChannel()
|
||||
|
||||
else:
|
||||
raise RuntimeError
|
||||
|
||||
30
channel/telegram/telegram_channel.py
Normal file
30
channel/telegram/telegram_channel.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import json
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import io
|
||||
import requests
|
||||
import telebot
|
||||
from common.log import logger
|
||||
from channel.channel import Channel
|
||||
BOT_TOKEN = '5684663516:AAFRYGIcDalEZzExyoBwt-t33BZjxcTISxg'
|
||||
bot = telebot.TeleBot(BOT_TOKEN)
|
||||
thread_pool = ThreadPoolExecutor(max_workers=8)
|
||||
|
||||
|
||||
@bot.message_handler(commands=['ask'])
|
||||
def send_welcome(msg):
|
||||
TelegramChannel().handle(msg)
|
||||
|
||||
class TelegramChannel(Channel):
|
||||
def __init__(self):
|
||||
pass
|
||||
def startup(self):
|
||||
logger.info("开始启动telegram机器人")
|
||||
def handle(self, msg):
|
||||
logger.debug("[Telegram]receive msg: " + msg.text)
|
||||
thread_pool.submit(self._dosend,msg.text.replace("/ask",""),msg)
|
||||
def _dosend(self,query,msg):
|
||||
context= dict()
|
||||
context['from_user_id'] = '1111'
|
||||
reply_text = super().build_reply_content(query, context)
|
||||
logger.info('[Telegram]] reply content: {}'.format(reply_text))
|
||||
bot.reply_to(msg,reply_text)
|
||||
@@ -4,6 +4,7 @@ WECHAT = "wechat"
|
||||
WECHAT_MP = "wechat_mp"
|
||||
WECHAT_MP_SERVICE = "wechat_mp_service"
|
||||
GMAIL = "gmail"
|
||||
TELEGRAM = "telegram"
|
||||
|
||||
# model
|
||||
OPEN_AI = "openai"
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
"model": {
|
||||
"type" : "openai",
|
||||
"openai": {
|
||||
"api_key": "YOUR API KEY",
|
||||
"conversation_max_tokens": 1000,
|
||||
"api_key": "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",
|
||||
"conversation_max_tokens": 2000,
|
||||
"character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。"
|
||||
}
|
||||
},
|
||||
"channel": {
|
||||
"type": "terminal",
|
||||
"type": "telegram",
|
||||
"single_chat_prefix": ["bot", "@bot"],
|
||||
"single_chat_reply_prefix": "[bot] ",
|
||||
"group_chat_prefix": ["@bot"],
|
||||
|
||||
Reference in New Issue
Block a user