Created
January 12, 2020 08:22
-
-
Save kaikiat/e6bd00d1864e2eb6675a348d6ff05cd9 to your computer and use it in GitHub Desktop.
Telegram Bot inline keyboard to prompt user for the time for their apppointment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sendInlineMessageForBookingTime(chat_id): | |
text_message='Please choose a time slot...' | |
current_time=datetime.datetime.now() | |
current_hour=str(current_time)[11:13] | |
# ----------- Chunk of if statement to determine which inline keyboard to reply user ---------------- | |
if int(current_hour) < 8: | |
keyboard={'keyboard':[ | |
[{'text':'08:00'}],[{'text':'10:00'}], | |
[{'text':'12:00'}],[{'text':'14:00'}], | |
[{'text':'16:00'}],[{'text':'18:00'}], | |
]} | |
elif 8<=int(current_hour)<10: | |
keyboard={'keyboard':[ | |
[{'text':'10:00'}], | |
[{'text':'12:00'}],[{'text':'14:00'}], | |
[{'text':'16:00'}],[{'text':'18:00'}], | |
]} | |
elif 10<=int(current_hour)<12: | |
keyboard={'keyboard':[ | |
[{'text':'12:00'}],[{'text':'14:00'}], | |
[{'text':'16:00'}],[{'text':'18:00'}], | |
]} | |
elif 12<=int(current_hour)<14: | |
keyboard={'keyboard':[ | |
[{'text':'14:00'}], | |
[{'text':'16:00'}],[{'text':'18:00'}], | |
]} | |
elif 14<=int(current_hour)<16: | |
keyboard={'keyboard':[ | |
[{'text':'16:00'}],[{'text':'18:00'}], | |
]} | |
elif 16<=int(current_hour)<18: | |
keyboard={'keyboard':[ | |
[{'text':'18:00'}], | |
]} | |
else: | |
return sendMessage(chat_id,'Please try again tmr') | |
#---------------------------------------------------------------------------------------------------- | |
key=json.JSONEncoder().encode(keyboard) | |
url='https://api.telegram.org/bot'+str(api_key)+'/sendmessage?chat_id='+str(chat_id)+'&text='+str(text_message)+'&reply_markup='+key | |
response = requests.get(url) | |
return response | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment