Skip to content

Instantly share code, notes, and snippets.

@Aniketh01
Created May 6, 2020 15:53
Show Gist options
  • Save Aniketh01/31138ddfd28dfdcef64479b309ccb6b6 to your computer and use it in GitHub Desktop.
Save Aniketh01/31138ddfd28dfdcef64479b309ccb6b6 to your computer and use it in GitHub Desktop.
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, ConversationHandler
class Telegram_Bot(object):
def tg_authenticate(self):
updater = Updater(token=tg_token, use_context=True)
return updater
def display_tweet(self, context):
print('starting display parameter')
for i in range(1, 100):
context.bot.send_message(job.context, text=str(i))
def start(self, update, context):
print('starting bot')
chat_id = update.message.chat_id
if 'job' in context.chat_data:
old_job = context.chat_data['job']
old_job.schedule_removal()
new_job = context.job_queue.run_once(self.display_tweet, 2, context=chat_id)
print("new job %s", new_job)
context.chat_data['job'] = new_job
update.message.reply_text('successfully started!')
def stop(self, update, context):
if 'job' not in context.chat_data:
update.message.reply_text('You have not activated the bot yet!')
return
job = context.chat_data['job']
job.schedule_removal()
del context.chat_data['job']
update.message.reply_text('Nawab Telegram bot has been stopped successfully!')
def main():
bot = tg_bot.Telegram_Bot(api, dirpath)
updater = bot.nawab_tg_authenticate()
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', bot.start, pass_job_queue=True, pass_chat_data=True))
dp.add_handler(CommandHandler("stop", bot.stop, pass_chat_data=True))
dp.add_handler(CommandHandler('help',bot.help))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment