Python Bot电报-在外部调用命令时出现问题

时间:2019-07-06 22:18:13

标签: python telegram-bot python-telegram-bot

我用名为“ command1”的自定义命令创建了Telegram机器人。

该命令通过Telegram界面完美执行: working-command 但是,如果我想从外部服务调用该命令,则该命令将不起作用: error-command

以下是漫游器代码:

import telebot
from telebot import types

import logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)
logger = logging.getLogger(__name__)

API_TOKEN = '12345'

bot = telebot.TeleBot(API_TOKEN)


# Handle '/start' and '/help'
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
    logger.info('send_welcome')
    msg = bot.reply_to(message, "Hi there, I am Example bot.")


# Handle '/command1'
@bot.message_handler(commands=['command1'])
def command1(message):
    msg = bot.reply_to(message, 'command1 executed!')
    logger.info('command1')

bot.polling()

这是“外部服务”:

import requests

def telegram_bot_sendtext(bot_message):

    bot_token = '12345'
    bot_chatID = '8200000001'
    send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&text=' + bot_message

    response = requests.get(send_text)

    return response.json()


test = telegram_bot_sendtext("/command1") # tested also with "command1" sintax
print(test)

为什么在外部调用该命令时不执行该命令?

任何帮助将不胜感激。

0 个答案:

没有答案