Echo Dot (3rd Gen) - Smart speaker with Alexa - Charcoal

Use your voice to play a song, artist, or genre through Amazon Music, Apple Music, Spotify, Pandora, and others. With compatible Echo devices in different rooms, you can fill your whole home with music.

Buy Now

Wireless Rechargeable Battery Powered WiFi Camera.

Wireless Rechargeable Battery Powered WiFi Camera is home security camera system lets you listen in and talk back through the built in speaker and microphone that work directly through your iPhone or Android Mic.

Buy Now

Build a Telegram Bot Scheduler with Python

0
75


Image from:https://www.bounteous.com/insights/2014/08/07/understanding-bot-and-spider-filtering-google-analytics/

In this post , I will cover how I code a Telegram Bot capable of scheduling appointments with the use of google-calendar-api. The objective of this project is to create a bot to help someone schedule his appointments based on his availability as well as the current time.

It will also be great if you have a basic understanding on Python , HTTP requests as well as a brief understanding on google-calendar-api.

Let’s start by going to Telegram and search for Bot Father. Bot Father is a bot which helps you to create and manage a bot.

Interface of Bot Father

Type

After that enter the name and username of the bot . Your bot is created and an API key will be generated. Now let’s verify the bot and send a message to it.

Type /start followed by test..

Bot Father provides several options to customise the bot such as

But for now we will keep the project simple and just stick to creating a new bot.

Now create a python file called main.py and write the following code.

This will return a json data which contains data/messages that was send to the bot.(if there are no messages send to this bot previously , result will be an empty list).

Now go to google calendar via https://developers.google.com/calendar/quickstart/python and click on enable Google Calendar API .

Click on Enable the Google Calendar API

Next download the credential.json and store it in the same directory as your python file . And also run this code in terminal/command prompt to install the relevant modules.

Next copy the quickstart.py and rename it as scheduler.py . Save this python file in the same directory as main.py. Hence, this is how the file hierarchy will look like.

After that,you will have to modify the code in scheduler.py to a function that creates an event on google calendar and returns a boolean. True if successfully scheduled and False if unable to schedule.

https://gist.github.com/kaikiat/06370d17dbb14d6717c0e0dda3ae3dd9

Now let’s create a function that will prompt user for the service that they want i.e Hair Cut,Trim,Dyeing etc.

https://gist.github.com/kaikiat/632805982d505247eb9ee9706d1645e5

This is how it will look on Telegram. An inline-keyboard will be automatically displayed to prompt user for their choice.

Only when a valid option is received, the next step will then be triggered which is to ask user for the time they prefer.

https://gist.github.com/kaikiat/e6bd00d1864e2eb6675a348d6ff05cd9

In this code there is a chunk of if statements which modifies the reply according to the current time. For instance , if the current time is 07:15a.m , time slots ranging from 08:00 to 18:00 will be displayed on the inline keyboard.

Only 16:00 and 18:00 will be displayed since the time is 15:59

Next ,we will have to create a function to prompt for the user email as well as verify it using regular expressions.

https://gist.github.com/kaikiat/8642b8ffdf264cfdaa945500cc23ef47

This is how it should look on Telegram. And now we have to verify that the event is created on Google Calendar.

Go to google-calendar and verify that the event is scheduled. You can customize the duration of the event , description of the event as well as the attendees for the event on scheduler.py

your google calendar

Click the link below for the code for this project. If there are any issues with the code, please contact automationfeed@gmail.com.



Read More

LEAVE A REPLY

Please enter your comment!
Please enter your name here