Skip to content

Commit

Permalink
Merge pull request #411 from deepanshubaghel/main
Browse files Browse the repository at this point in the history
Telegram Bot Added
  • Loading branch information
suryanshsk authored Oct 22, 2024
2 parents a19398f + f377bba commit a61bb17
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions telegram_bot/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'''
BOT FOR TELEGRAM
'''

import random
import logging
from telegram import (ParseMode)
from telegram.ext import (Updater, CommandHandler)

logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)


def error_callback(update, context):
logger.warning('Update "%s" caused error "%s"', update, context.error)


def start(update, context):
'''
Start
'''
context.bot.send_message(update.message.chat_id,
"Welcome! to simple telegram bot", parse_mode=ParseMode.HTML)

'''
We can call other commands, without it being activated in the chat (/ help).
'''
coin(update, context)


def coin(update, context):
'''
⚪️ / ⚫️ Currency
Generate an elatory number between 1 and 2.
'''
cid = update.message.chat_id

msg = "⚫️ face " if random.randint(1, 2) == 1 else "⚪️ cross"
'''
He responds directly on the channel where he has been spoken to.
'''
update.message.reply_text(msg)


def main():
TOKEN = "1914536904:AAF4ZnqNvyg1pk-1pCPzTqhDYggAyf-1CF8"

updater = Updater(TOKEN, use_context=True)

dp = updater.dispatcher

'''
Events that will activate our bot.
'''
dp.add_handler(CommandHandler('start', start))
dp.add_handler(CommandHandler('coin', coin))

dp.add_error_handler(error_callback)

'''
The bot starts
'''
updater.start_polling()

'''
or leave listening. Keep it from stopping.
'''
updater.idle()


if __name__ == '__main__':
print('[Telegram simple bot] Start...')
main()

0 comments on commit a61bb17

Please sign in to comment.