-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from deepanshubaghel/main
Telegram Bot Added
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |