Ejemplo n.º 1
0
def files_callback(update, context):
    file = context.bot.getFile(update.message.document.file_id)
    file_path = CONFIG.tmp_path / update.effective_message.document.file_name
    file.download(file_path)

    text = update.effective_message.caption
    file_ext = update.effective_message.document.mime_type
    file_type = CONFIG.get_file_type(file_ext)
    url = CONFIG.get_webhook(file_type)
    chat_id = update.effective_chat.id
    params = parse_args(text)
    data = {'chat_id': chat_id, 'params': params}
    with open(str(file_path), 'rb') as f:
        resp = service_client.post(url=url, body=data, file=f)
    LOG.info(resp)
    context.bot.send_message(chat_id=update.effective_chat.id,
                             text=str(resp.content))