This bot manages an anonymous inbox for your students, so they can do anonymised suggestions about the course of your teaching, and what can you do to improve it. It also supports identifiable suggestions, and the type of suggestion is decided by the student at the moment of sending the message.
The functionality of the bot is pretty simple. Using the /start
command triggers the welcome message of the bot. It welcomes the
students and tells them how to perform new suggestions.
The main function of the bot is built around the /suggest command.
Using this command, the student can send a new message. After using
the command, the bot asks you about the nature the suggestion
(anonymous or identifiable), showing a button keyboard. After pressing
one of the buttons, the bot asks for the message to be sent. When the
message has been sent, the bot thanks the student for the suggestion,
and sends the message to the teacher, indicating the name and alias
of the student if it has decided to send an identifiable suggestion.
The bot has been developed using Python 3.8. It should work
independently of the Python version, as long as it is Python 3. The
requirements for the project are specified in
requirements.txt. Basically, the libraries
needed are
- Flask==1.1.2
- gunicorn==20.0.4
- python-telegram-bot==13.2
The current state of the bot is prepared to run in Google Cloud Run out-of-the-box. However, there are a few steps you have to perform in order to make it running. To begin with, you should clone this repository in your machine:
git clone https://github.com/fluque1995/anonymous_inbox_bot.gitIn order to create a new bot, you have to talk to the BotFather. You can start a conversation with him here. Creating a new bot using the BotFather is pretty straightforward, you can find more information in this link: https://core.telegram.org/bots#6-botfather
After creating you bot, BotFather should give you the API_TOKEN of
your bot. This token is a huge alphanumerical code that identifies
your bot with Telegram. Store this key in a safe place, and be careful
not to give it to anybody, since they can take control of your bot
using it. The API_TOKEN is something similar to this:
1234567890:aaaaaaaaaaaaaaaaaaaaaa_aaaaaaaaaaaIn order to get your contact information, specifically your chat ID,
you have to talk to @userinfobot. This
number is the identifier or your account, so again be careful not
to show it publicly, or your account can be easily spammed. From
now on, we will refer to this number as TEACHER_CHAT_ID, since
it is the name we will give to the variable in our code.
After getting this two descriptors, TOKEN_ID and TEACHER_CHAT_ID,
we are ready to deploy the bot in Google Cloud Run.
Disclaimer: The next steps are strongly inspired by this tutorial: https://nullonerror.org/2021/01/08/hosting-telegram-bots-on-google-cloud-run/ . This is the resource I first followed to deploy my instance of the bot, and it is a really valuable resource. I will show the specific steps I took, since I had never worked with Google Cloud before this project. Because of that, this tutorial can be a bit basic for experienced users. In that case, I recommend you to follow the previous link. Thanks to the original author!
The first thing you have to do is getting a Google Cloud Run account. In order to get one, simply go to https://console.cloud.google.com . It should be simple if you already have a google account.
Afterwards, we need to create a project for our bot. Projects are a
way to keep our Google Cloud organized. In order to launch a service
in Google Cloud, it has to be associated to a previously existing
project. It is easy to create a new project. In your Google Console
(https://console.cloud.google.com), at the top right corner, there is
a menu called CREATE RESOURCE, where you can create a new project. You can
follow this tutorial if you are uncertain:
https://cloud.google.com/resource-manager/docs/creating-managing-projects
When creating your project, you have to specify a project name and the
project ID. Project ID is automatically generated by Google Cloud,
using the name of the project and a 6-digit number. For example, if we
use telegram-bot as the name of the project, our project ID will be
something like telegram-bot-123456.
Note: It is possible you will have to set up a payment method in order to make the project fully operational. Don't worry about that, since the number of free requests you can do monthly to the API is huge. If you don't plan to use your bot for a whole university or campus, you will not be billed. For the moment, the number of free petitions per month is 2 million. You can check it in https://cloud.google.com/run/pricing
After the project have been created, we are finally ready to deploy our bot!. We will need the Google Cloud CLI. You can check the installation process in https://cloud.google.com/sdk/docs/install .
After installing gcloud, navigate to the repository folder in your
computer (remember, we cloned this repo at the beginning of the
tutorial). After being in the repository folder, we have to login into
Google Cloud from our terminal:
gcloud auth loginIt will redirect us to a Google login page, where we will have to specify our account. After we are logged in, we will have to set our region:
gcloud config set run/region europe-west1And finally, we have to deploy our bot! The command for deploy is:
gcloud beta run deploy anonymous-box --source . \
--set-env-vars TOKEN=<YOUR_API_TOKEN>,TEACHER_CHAT_ID=<YOUR_CHAT_ID> \
--platform managed --allow-unauthenticated --project <YOUR_PROJECT_ID>After the command has finished, you will receive a public URL of your run,
and you will need to set up the bot webHook using cURL:
curl "https://api.telegram.org/bot<YOUR_API_TOKEN>/setWebhook?url=https://your-bot-name-uuid-uc.a.run.app"And we are finished! If you encounter any problem when deploying your bot, feel free to contact me, or leaving an issue in the repo :)