Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =========================================
- main.py
- =========================================
- from telegram import Update, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineKeyboardButton, InlineKeyboardMarkup
- from telegram.ext import (Application, CommandHandler, CallbackQueryHandler, MessageHandler, filters, ConversationHandler, CallbackContext, PrefixHandler)
- import random, logging, datetime, requests, pytz, os, scrapy, platform
- import re, json, pytz
- import socket as socket
- from survey import main_survey
- #LOG
- logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
- #
- def main():
- app = Application.builder().token(os.environ['TGTOKEN']).build()
- logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
- app.add_handler(PrefixHandler('?', 'ask', main_survey))
- app.run_polling()
- if __name__ == "__main__":
- main()
- =========================================
- survey.py
- =========================================
- from telegram import Update, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineKeyboardButton, InlineKeyboardMarkup
- from telegram.ext import (CommandHandler, CallbackQueryHandler, MessageHandler, filters, ConversationHandler, CallbackContext, PrefixHandler)
- STATE1, STATE2, STATE3 = range(3)
- async def state1(update, context):
- buttons = [[
- InlineKeyboardButton("Google", callback_data="google"),
- InlineKeyboardButton("Bing", callback_data="bing"),
- InlineKeyboardButton("Yahoo!", callback_data="yahoo")
- ]
- ]
- ReplyKeyboardMarkup = InlineKeyboardMarkup(buttons)
- await update.message.reply_text("Stage 1. What's your favourite search engine?", reply_markup= ReplyKeyboardMarkup)
- return STATE2
- async def state2(update, context):
- buttons = [[
- InlineKeyboardButton("Gmail", callback_data="gmail"),
- InlineKeyboardButton("Outlook", callback_data="outlook"),
- InlineKeyboardButton("Yahoo!", callback_data="yahoomail")]
- ]
- ReplyKeyboardMarkup = InlineKeyboardMarkup(buttons)
- await update.message.reply_text("Stage 2. What's your favourite e-mail provider?", reply_markup= ReplyKeyboardMarkup)
- return STATE3
- async def state3(update, context):
- await update.message.reply_text("Thank you for your answers!")
- return ConversationHandler.END
- async def main_survey(update, context):
- print("OK")
- survey_handler = ConversationHandler(
- entry_points=[CallbackQueryHandler(state1)],
- states={
- STATE1: [CallbackQueryHandler(state1)],
- STATE2: [CallbackQueryHandler(state2)],
- STATE3: [CallbackQueryHandler(state3)]
- },
- fallbacks=[],
- per_message=True
- )
- print(survey_handler)
- return survey_handler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement