├── Procfile ├── requirements.txt └── bot.py /Procfile: -------------------------------------------------------------------------------- 1 | worker: python bot.py -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | python-telegram-bot 2 | requests -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, 3 | RegexHandler, ConversationHandler, CallbackQueryHandler) 4 | from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ReplyKeyboardMarkup 5 | 6 | 7 | STATE1 = 1 8 | STATE2 = 2 9 | 10 | def welcome(update, context): 11 | try: 12 | username = update.message.from_user.username 13 | firstName = update.message.from_user.first_name 14 | lastName = update.message.from_user.last_name 15 | message = 'Olá, ' + firstName + '!' 16 | context.bot.send_message(chat_id=update.effective_chat.id, text=message) 17 | except Exception as e: 18 | print(str(e)) 19 | 20 | 21 | def feedback(update, context): 22 | try: 23 | message = 'Por favor, digite um feedback para o nosso tutorial:' 24 | update.message.reply_text(message, reply_markup=ReplyKeyboardMarkup([], one_time_keyboard=True)) 25 | return STATE1 26 | except Exception as e: 27 | print(str(e)) 28 | 29 | 30 | def inputFeedback(update, context): 31 | feedback = update.message.text 32 | print(feedback) 33 | if len(feedback) < 10: 34 | message = """Seu feedback foi muito curtinho... 35 | \nInforma mais pra gente, por favor?""" 36 | context.bot.send_message(chat_id=update.effective_chat.id, text=message) 37 | return STATE1 38 | else: 39 | message = "Muito obrigada pelo seu feedback!" 40 | context.bot.send_message(chat_id=update.effective_chat.id, text=message) 41 | return ConversationHandler.END 42 | 43 | 44 | def inputFeedback2(update, context): 45 | feedback = update.message.text 46 | message = "Muito obrigada pelo seu feedback!" 47 | context.bot.send_message(chat_id=update.effective_chat.id, text=message) 48 | return ConversationHandler.END 49 | 50 | 51 | # https://getemoji.com/ 52 | def askForNota(update, context): 53 | try: 54 | question = 'Qual nota você dá para o tutorial?' 55 | keyboard = InlineKeyboardMarkup( 56 | [[InlineKeyboardButton("👎 1", callback_data='1'), 57 | InlineKeyboardButton("2", callback_data='2'), 58 | InlineKeyboardButton("🤔 3", callback_data='3'), 59 | InlineKeyboardButton("4", callback_data='4'), 60 | InlineKeyboardButton("👍 5", callback_data='5')]]) 61 | update.message.reply_text(question, reply_markup=keyboard) 62 | except Exception as e: 63 | print(str(e)) 64 | 65 | 66 | def getNota(update, context): 67 | try: 68 | query = update.callback_query 69 | print(str(query.data)) 70 | message = 'Obrigada pela sua nota: ' + str(query.data) 71 | context.bot.send_message(chat_id=update.effective_chat.id, text=message) 72 | except Exception as e: 73 | print(str(e)) 74 | 75 | 76 | def cancel(update, context): 77 | return ConversationHandler.END 78 | 79 | 80 | def main(): 81 | try: 82 | # token = os.getenv('TELEGRAM_BOT_TOKEN', None) 83 | token = 'cole_aqui_o_token_de_acesso_do_seu_bot' 84 | updater = Updater(token=token, use_context=True) 85 | 86 | updater.dispatcher.add_handler(CommandHandler('start', welcome)) 87 | 88 | conversation_handler = ConversationHandler( 89 | entry_points=[CommandHandler('feedback', feedback)], 90 | states={ 91 | STATE1: [MessageHandler(Filters.text, inputFeedback)], 92 | STATE2: [MessageHandler(Filters.text, inputFeedback2)] 93 | }, 94 | fallbacks=[CommandHandler('cancel', cancel)]) 95 | updater.dispatcher.add_handler(conversation_handler) 96 | 97 | updater.dispatcher.add_handler(CommandHandler('nota', askForNota)) 98 | updater.dispatcher.add_handler(CallbackQueryHandler(getNota)) 99 | 100 | print("Updater no ar: " + str(updater)) 101 | updater.start_polling() 102 | updater.idle() 103 | except Exception as e: 104 | print(str(e)) 105 | 106 | 107 | if __name__ == "__main__": 108 | main() 109 | 110 | --------------------------------------------------------------------------------