【发布时间】:2019-11-07 11:36:15
【问题描述】:
伙计们,
有没有人有任何执行 oracle 查询并通过 python 中的电报机器人发送消息的示例?
【问题讨论】:
标签: python oracle python-telegram-bot
伙计们,
有没有人有任何执行 oracle 查询并通过 python 中的电报机器人发送消息的示例?
【问题讨论】:
标签: python oracle python-telegram-bot
我只能回答你问题的一半,即通过python中的电报机器人发送消息。
创建您的机器人
在 Telegram 上搜索@BotFather,向他发送“/start”消息
发送另一条“/newbot”消息,然后按照说明设置名称和用户名
获取您的聊天 ID
在 Telegram 上,搜索您的机器人(通过您刚刚创建的用户名),按“开始”按钮或发送“/开始”消息
用你的浏览器打开一个新标签页,输入https://api.telegram.org/bot/getUpdates,替换为你的API令牌,按回车,你应该会看到如下内容:
{"ok":true,"result":[{"update_id":77xxxxxxx,
"message":{"message_id":550,"from":{"id":34xxxxxxx,"is_bot":false,"first_name":"Man Hay","last_name":"Hong","username":"manhay212","language_code":"en-HK"}
查找“id”,例如上面的 34xxxxxxx 是我的聊天 id。查找您的并将其作为您的 bot_chatID 放在上面的代码中
Python 代码:
import requests
def telegram_bot_sendtext(bot_message):
bot_token = '<INSERT_API_KEY>'
bot_chatID = '<INSERT_CHATID>'
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message
response = requests.get(send_text)
return response.json()
test = telegram_bot_sendtext("Testing Telegram bot")
print(test)
【讨论】: