将参数传递给python电报bot callback_data

时间:2019-07-12 12:41:30

标签: python-telegram-bot

我正在使用python telegram bot创建一个频道管理bot。该用户向bot发送照片,然后bot将照片发送给管理员,如果管理员确认,则bot将照片发送到电报频道。我还想向用户发送反馈,以确认您的照片是否经过确认。但我无法在我的函数中访问用户chat_id。

我的代码如下:

#function to get image from user
def get_images(bot,update):
    chat_id = update.message.chat_id
    username = update.message.from_user.username
    users.update({chat_id:username})
    print(users)
    caption = str(update.message.caption) + '\n' + space_text  +  '\n' + ' @some_id'
    admin_id = find_admin_id(users)


    bot.send_message(chat_id=update.message.chat_id, text=send_image)
    admin_check(bot,update,admin_id,update.message.photo[-1],caption)

#function to send photo to admin with inline keyboard

def admin_check(bot,update,admin_id,photo,caption):
    button_list = [
    InlineKeyboardButton("ok", callback_data='m1'),
    InlineKeyboardButton("not ok", callback_data='m2')
    ]
    reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=2))
    bot.send_photo(admin_id,update.message.photo[-1],caption= caption,\
                   reply_markup=reply_markup)
    print('reply',reply_markup)

#my functions to action depend on admin response

def ok(bot, update):
    query = update.callback_query
    bot.send_photo(chat_id='@testiut',photo= query.message.photo[-1],\
                 caption=query.message.caption)
    query.message.reply_text("sent to channel.")


def not_ok(bot, update):
    query = update.callback_query
    querydata = query.data
    print('0',querydata)
    msg = "why do you refuse?"
    reply_markup = telegram.ReplyKeyboardRemove()
    bot.send_message(chat_id=query.message.chat_id,
                     message_id=query.message.message_id,
                     text=msg, reply_markup=reply_markup)

#and finally add handlers
updater.dispatcher.add_handler(CallbackQueryHandler(ok, pattern='m1'))
updater.dispatcher.add_handler(CallbackQueryHandler(not_ok, pattern='m2'))

我不知道要在“ ok”和“ not_ok”功能中访问chat_id。

0 个答案:

没有答案