def reply_text(bot, update): intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for articles in articles: bot.send_message(chat_id=update.message.chat_id, text=article) else: bot.send_message(chat_id=update.message.chat_id, text=reply) def echo_sticker(bot, update): bot.send_sticker(chat_id=update.message.chat_id, sticker=update.message.sticker.file_id) def error(bot, update): logger.error("Update '%s' caused error '%s'", update, update.error) # def message_handler(update, context: CallbackContext): # update.message.reply_text(text) bot = Bot(TOKEN) try: bot.set_webhook("https://48c9acd55480.ngrok.io/" + TOKEN) except Exception as e: print(e) dp = Dispatcher(bot, None) dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", _help)) dp.add_handler(CommandHandler("news", news)) dp.add_handler(MessageHandler(Filters.text, reply_text)) dp.add_handler(MessageHandler(Filters.sticker, echo_sticker)) dp.add_error_handler(error) if __name__ == "__main__": app.run(port=8443)
def reply_text(bot, update): intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(update: Update, context: CallbackContext): intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: context.bot.send_message(chat_id=update.message.chat_id, text=article['link']) else: context.bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(update: Update, context: CallbackContext): """callback function for text message handler""" intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: update.message.reply_text(article['link']) else: update.message.reply_text(reply)
def reply_text(bot, update): """callback function for text message handler""" intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(update: Update, context: CallbackContext): intent, reply = get_reply( update.to_dict()['message']['text'], update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: update.message.reply_text(article['link']) else: update.message.reply_text(reply)
def reply_text(bot, update): # callback function for text message handler intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": # reply_text = "Ok! I will show you news with {}".format(reply) articles = fetch_news(reply) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(bot, update): intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": reply_text = "Okay!Here's the news" articles = fetch_news(reply) for article in articles: update.message.reply_text(article['link']) else: update.message.reply_text(reply)
def reply_text(bot, update): """callback function for text message handler""" intent, reply = get_reply(update.message.text, update.message.chat_id) print("Reply : ",reply,"\nIntent :",intent) if reply == "": bot.send_message(chat_id=update.message.chat_id, text="Its beyond my reach.!") if intent == "topic": articles = fetch_news(reply) ## print(articles) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(bot, update): intent, reply = get_reply(update.message.text, update.message.chat_id) #the get_reply function uses the chat_id as the session_id for multiple interactions with different users #also to prevent the bot to send the required text of one user to another #we are also receiving the intent from the return statement in the utils module if intent == "get_news": articles = fetch_news(reply) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) # reply_text = "Ok! I will show you the news with {}".format(reply) # bot.send_message(chat_id=update.message.chat_id, text=reply_text) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(bot, update): intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) elif intent == "Corona": Total, Active, Death, Recoverd = get_cases() cases = " 🇮🇳 India: Total \n Confirmed: {} \n Active: {} \n Deaths: {} \n Recovered: {}".format( Total, Active, Death, Recoverd) city = reply.get('geo-state') if city is not '': City_name, Total_city, Active_city, Death_city, Recoverd_city = get_cases_by_city( city) cases_by_city = " In {} Total \n Confirmed: {} \n Active: {} \n Deaths: {} \n Recovered: {}".format( City_name, Total_city, Active_city, Death_city, Recoverd_city) final = cases + "\n\n" + cases_by_city bot.send_message(chat_id=update.message.chat_id, text=final) else: bot.send_message(chat_id=update.message.chat_id, text=cases) else: bot.send_message(chat_id=update.message.chat_id, text=reply)