【问题标题】:Send result query Oracle to telegram bot in python在python中将结果查询Oracle发送到电报机器人
【发布时间】:2019-11-07 11:36:15
【问题描述】:

伙计们,

有没有人有任何执行 oracle 查询并通过 python 中的电报机器人发送消息的示例?

【问题讨论】:

    标签: python oracle python-telegram-bot


    【解决方案1】:

    我只能回答你问题的一半,即通过python中的电报机器人发送消息。

    创建您的机器人

    1. 在 Telegram 上搜索@BotFather,向他发送“/start”消息

    2. 发送另一条“/newbot”消息,然后按照说明设置名称和用户名

    3. 您的机器人现已准备就绪,请务必保存 API 令牌的备份,并且更正,此 API 令牌是您的 bot_token

    获取您的聊天 ID

    1. 在 Telegram 上,搜索您的机器人(通过您刚刚创建的用户名),按“开始”按钮或发送“/开始”消息

    2. 用你的浏览器打开一个新标签页,输入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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      • 2017-06-16
      相关资源
      最近更新 更多