Skip to content

Instantly share code, notes, and snippets.

@shivampip
Last active March 7, 2022 04:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save shivampip/d74c9a81daab7b6e4a8ea49ed12e4cf7 to your computer and use it in GitHub Desktop.
Save shivampip/d74c9a81daab7b6e4a8ea49ed12e4cf7 to your computer and use it in GitHub Desktop.
[Telegram Wikipedia Bot] #telegram #wikipedia #bot #python
from telegram.ext import Updater
from telegram.ext import MessageHandler, Filters
import wikipedia as wiki
# put your toen here
BOT_TOKEN= "641238067:AAEB___d1oM4llx6********************"
updater= Updater(BOT_TOKEN) #Bot Token is given by BotFather on Telegram while creating bot.
def get_wiki(word):
try:
return wiki.summary(word)
except:
return "Not Found"
def textpro(bot, update):
msg= update.message.text.lower()
senderName= update.message.from_user.first_name
chatid= update.message.chat.id
print("{}: {}".format(senderName, msg))
if(msg.startswith('wiki')):
bot.send_message(chat_id= chatid,text= get_wiki(msg[5:]))
print("Bot: Wikipedia summery of {}".format(msg[5:]))
else:
bot.send_message(chat_id= chatid, text= "{}, Invalid command".format(senderName))
print("Bot: Invalid command")
updater.dispatcher.add_handler(MessageHandler(Filters.text, textpro))
updater.start_polling()
print("Bot Server Started")
updater.idle()
#DONE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment