1

I'm trying to make a menu bot. All is working but I can't put a GIF for decoration before the keyboard and message.

I used some variations of .inputmedia and .document from here.

I know nothing and have zero python knowledge. I can only understand on the fly from reading on the internet. I really can't understand how to phrase it.

from telegram.ext import Updater
from telegram.ext import CommandHandler, CallbackQueryHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
import emoji
def start(bot, update):
  update.message.reply_text(main_menu_message(),
                            reply_markup=main_menu_keyboard())

def main_menu(bot, update):
  query = update.callback_query
  bot.edit_message_text(chat_id=query.message.chat_id,
                        message_id=query.message.message_id,
                        text=main_menu_message(),
                        reply_markup=main_menu_keyboard())

def first_menu(bot, update):
  query = update.callback_query
  bot.edit_message_text(chat_id=query.message.chat_id,
                        message_id=query.message.message_id,
                        text=first_menu_message(),
                        reply_markup=first_menu_keyboard())

pretty much all i need is an example how to phrase a inputgif command with some text and a markup keyboard. Thanks!

Amir Shabani
  • 3,857
  • 6
  • 30
  • 67
david kha
  • 31
  • 1
  • 3

2 Answers2

0

You mean something like this?

enter image description here

If yes, read on! If no, tell me in the comments.

  • We're gonna use the send_animation method from telegram.Bot class.

    Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).

  • We'll need to know the file_id of the GIF that we wish to send! Important: We need to get the file_id in the same chat with the bot!

Here's how we can send a GIF with a caption and an inline keyboard (you can see the full code on my GitHub: wehavetogoback.py)

keyboard = [
    [
        InlineKeyboardButton('yes ', callback_data='yes'),
        InlineKeyboardButton('no ', callback_data='no')
    ]
]

bot.send_animation(
    chat_id=update.message.chat.id,
    animation='file_id',
    caption='go back??',
    reply_markup=InlineKeyboardMarkup(keyboard)
)
Amir Shabani
  • 3,857
  • 6
  • 30
  • 67
0

use these methods:

  • update.message.send_animation()
  • bot.send_animation()
  • bot.edit_message_media()

For example:

def start(bot, update):
    gif_link='https://media.giphy.com/media/yFQ0ywscgobJK/giphy.gif'
    update.message.reply_animation(
        animation=gif_link,
        caption=main_menu_message(),
        reply_markup=main_menu_keyboard(),
        parse_mode=ParseMode.MARKDOWN
    )

upd: @amir-a-shabani thank you for edition and thanks to @david-kha for using code examples)

dzNET
  • 930
  • 1
  • 9
  • 14