This bot shares Yo-Mama jokes, inspired by this tutorial.
- Python 3.0
- Ensure pip is installed (
pip --version
) - Install virtual environment:
pip install virtualenv
- Telegram messenger (or web version at web.telegram.org)
git clone https://github.com/hrushikesh009/TelegramBot.git
pip install -r requirements.txt
Utilized MySQL Database in this tutorial. Modify settings in Telegram_Bot.settings
:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'Your Database Name',
'HOST': 'localhost',
'USER': 'Database Username',
'PASSWORD': 'Database Password',
'PORT': 'Database Port'
}
}
Refer to this link for PostgreSQL setup.
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
For HTTPS URL during development, use ngrok:
ngrok http 8000
Add the URLs to ALLOWED_HOSTS in Telegram_Bot.settings
.
Talk to BotFather on Telegram (/newbot
command) to create a bot and get a token. Copy and paste the token in FunBot/views.py
.
Run the following command or use services like Postman:
curl -F “url=<ngrok_url>/chat/c817304a3d163ebd58b44dd446eba29572300724098cdbca1a/“ https://api.telegram.org/bot<bot_token>/setWebhook
Initiate a conversation and receive responses from the bot.
Visit <ngrok_url>/chat/home/
to view user interactions and data captured in the database.