I have the basic code for sending a photo and i seem to understand the concept of choosing a random one. My question is where in this code should i put the random choice code?
import sys
import time
import os
import telepot
from telepot.loop import MessageLoop
from telepot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton
import random
def on_chat_message(msg):
global chat_id
content_type, chat_type, chat_id = telepot.glance(msg)
#creating buttons
if content_type == 'text':
if msg['text'] == '/start':
bot.sendMessage(chat_id, 'Welcome to randomImgBot\nOn each click i will display you a random image of your choice\n Created by JonSnow 2021',reply_markup = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="PGP",callback_data='a')]]))
def on_callback_query(msg):
global chat_id
query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
print('Callback Query:', query_id, from_id, query_data)
if query_data == 'a':
bot.sendPhoto(chat_id, photo=open('lolly.png'))
bot = telepot.Bot('')
MessageLoop(bot, {'chat': on_chat_message,
'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')
while 1:
time.sleep(10)