Telegram Bot: Basic Strategy BlackJack

Telegram Bot: Basic Strategy BlackJack

Aakash Shah

Read the telegram bots introduction here: https://core.telegram.org/bots


Set up a GitHub repository and clone it in your local environment. I will soon add a template repository which has everything setup on my GitHub.


I am using VSCode on my local environment, I added the cloned repository to my workspace.


Started coding by making a virtual environment. (Good habits must not die)

python3 -m venv env
source ./env/bin/activate


I will add a freeze requirements to start with the telegram bot library.

pip install --upgrade pip
pip3 install --upgrade pip
pip install python-telegram-bot --upgrade
pip install configparser
pip freeze > requirements.txt


Here is readthedocs link for python-telegram-bot.


Follow instruction here to start a new bot using BotFather -


Adding a config file for secrets

I made a config.ini to add the telegram token provided by the BotFather and added the file to .gitignore.


Filename: config.ini

[DEFAULT]
BOT_TOKEN = 12345678:yxaibsdnlqkjsfnkandMnB3wzv7Z4nvnK4z

12345678: Your user id.

yxaibsdnlqkjsfnkandMnB3wzv7Z4nvnK4z: It is the actual token.


Clone ehchobot2 as a template

Start by cloning the example echobot2 with the telegram.ext. It is easy to learn code with examples with definite output.


Start Coding!


One of the issues i dealt with is how to capture user data in an Inline Keyboard

Also for using an inline keyboard and being compatible with multiple routes was tricky.

I had to decided upon the states of the game, patterns to function mapping, and allowing multiple routes.


Pandas!

I am going to enter the basic strategy to the csv files and then have pandas return the combination



Report Page