def show_products(payload, event): selected_id = payload.split('|')[1] print("------------CATEGORY_ID: ", selected_id) navigation = [ QuickReply("Back to Categories", payload="SHOW_CATEGORIES"), QuickReply("View Cart", payload="CHECK_CART") ] templates = template_products(selected_id) template_dict = defaultdict(list) count = 0 dict_count = 0 # FIXME: add comments here for template in templates: template_dict[dict_count].append(template) count += 1 if count == 10: dict_count += 1 count = 0 for temp_dict in template_dict.values(): pprint(temp_dict) page.send(event.sender_id, Template.Generic(temp_dict, True)) page.send(event.sender_id, "or explore categories", quick_replies=navigation)
def handle_due_date(sender_id, message_text): """Takes in the number of weeks a user has to do their new project.""" from lib.utilities import update_project_due_date if message_text: try: weeks = int(message_text.strip()) except: page.send( sender_id, "I'm sorry I didn't catch that.\nHow many weeks do you want to do this project?", ) else: project_id = crafter[sender_id].get('project_id') project = update_project_due_date(project_id=project_id, weeks=weeks) note_no = [ QuickReply(title="Note", payload="NOTE"), QuickReply(title="No Notes", payload="NO_NOTES") ] page.send( sender_id, "Got it. Anything else you want me to know about this project", quick_replies=note_no) crafter[sender_id]['due_date'] = weeks else: page.send( sender_id, 'Please add the number of weeks until you would like to work on this project' )
def click_persistent_menu_cart(payload, event): print("Selected Cart") response = template_cart_items(event.sender_id) cart_template = response[0] isNull = response[1] page.typing_on(event.sender_id) time.sleep(.8) page.typing_off(event.sender_id) if isNull: quick_replies = [ QuickReply(title="π Buy something", payload="MENU_CATEGORY") ] page.send(event.sender_id, "Your cart is empty. π ", quick_replies=quick_replies) else: page.send(event.sender_id, cart_template) quick_replies = [ QuickReply(title="βοΈ Continue Shopping", payload="MENU_CATEGORY"), QuickReply(title="π§Ύ Checkout", payload="CHECKOUT") ] page.send( event.sender_id, "You can continue shoppping or check out if your are done for today!", quick_replies=quick_replies)
def on_enter_music(self, event): print("I'm entering music") sender_id = event['sender']['id'] quick_replies = [QuickReply(title="η·ζζ", payload="PICK_man"), QuickReply(title="ε₯³ζζ", payload="PICK_woman")] page.send(sender_id, "ι£δ½ ζ³θ½η·ζζηζιζ―ε₯³ζζηε’~",quick_replies=quick_replies,metadata="DEVELOPER_DEFINED_METADATA")
def send_hoteles_cercanos(recipient): print('------------------------------HOTELES----CERCANOS-----------------------------------------------') page.send(recipient, "Claro que sΓ, serΓ‘ un placer hospedarte.") page.send(recipient, "Compartir ubicacion?", quick_replies=[QuickReply(title="compartir", payload="compartir"), QuickReply(title="en otro momento", payload="en otro momento")], metadata="DEVELOPER_DEFINED_METADATA")
def on_enter_sleeping(self, event): print("I'm entering sleeping") sender_id = event['sender']['id'] quick_replies = [QuickReply(title="8ε°ζ", payload="PICK_8"), QuickReply(title="12ε°ζ", payload="PICK_12"), QuickReply(title="24ε°ζ", payload="PICK_24")] page.send(sender_id, "ι£δ½ ζ³θ¦η‘ε€δΉ ε’><",quick_replies=quick_replies,metadata="DEVELOPER_DEFINED_METADATA")
def on_enter_eatting(self, event): print("I'm entering eatting") sender_id = event['sender']['id'] quick_replies = [QuickReply(title="ει£²ζ", payload="PICK_DRINK"), QuickReply(title="εζ£ι€", payload="PICK_MEAL"), QuickReply(title="ειΆι£/ηι»", payload="PICK_DESSERT")] page.send(sender_id, "δ½ ε°εͺδΈι ζ―θΌζθθΆ£ε’~",quick_replies=quick_replies,metadata="DEVELOPER_DEFINED_METADATA")
def on_enter_playing(self, event): print("I'm entering playing") sender_id = event['sender']['id'] quick_replies = [QuickReply(title="θ½ι³ζ¨", payload="PICK_MUSIC"), QuickReply(title="η©ιζ²", payload="PICK_GAME"), QuickReply(title="ιε", payload="PICK_EXERCISE")] page.send(sender_id, "δ½ ε°εͺδΈι ζ―θΌζθθΆ£ε’~",quick_replies=quick_replies,metadata="DEVELOPER_DEFINED_METADATA")
def handle_allActions(sender, action, ai_reply): if action == 'action.getNews': smart_object = qr.get_news_quick_reply() page.send(recipient_id=sender, message='Choose any one of these sources:', quick_replies=smart_object) elif action == 'smalltalk.greetings.hello': quickreply_mini = [ QuickReply(title='news', payload='news_hello'), QuickReply(title='weather', payload='weather') ] message_ai = ai_reply['result']['fulfillment']['speech'] page.send( recipient_id=sender, message=message_ai + '! Click on the button below, or you can simply text What is the news? For info on weather tap on weather', quick_replies=quickreply_mini) elif action == 'action.getWeather': if 'cityName' in ai_reply['result']['parameters']: city = ai_reply['result']['parameters']['cityName'] page.send(recipient_id=sender, message=w.get_weather(city)) else: reply = ai_reply['result']['fulfillment']['speech'] if reply is None or reply == "": reply = "Okay" page.send(recipient_id=sender, message=reply)
def webhook_handler(): body = request.json event = body['entry'][0]['messaging'][0] global Records sender_id = event['sender']['id'] if sender_id in Records: machine.state = Records[sender_id] else: machine.state = "init" print('\nFSM STATE: ' + machine.state) print('REQUEST BODY: ') print(body) # only deal text messages if event['message'].get('text'): machine.advance(event) Records[sender_id] = machine.state # initial state if machine.state == "init": quick_replies = [ QuickReply(title="ζ°εΉ΄εΏ«ζ¨", payload="PICK_YEAR"), QuickReply(title="δΌιε¨ζ¨", payload="PICK_PLAY"), QuickReply(title="ι²ι£", payload="PICK_EAT"), QuickReply(title="η‘θ¦Ί", payload="PICK_SLEEP"), QuickReply(title="θ倩", payload="PICK_TALK") ] page.send(sender_id, "ε¨~\nδ½ ηΎε¨ζ³θ¦εδ»ιΊΌε’?", quick_replies=quick_replies, metadata="DEVELOPER_DEFINED_METADATA") return 'OK'
def purchase_item(recipient): page.send(recipient, "What item would you like to purchase?", quick_replies=[ QuickReply(title=("Sneakers π"), payload="BUY_SNEAKERS"), QuickReply(title=("Jeans π"), payload="BUY_JEANS"), ], metadata="DEVELOPER_DEFINED_METADATA")
def start_again(recipient): page.send(recipient, "Would you like to view more items? π", quick_replies=[ QuickReply(title=("Cancel"), payload="CANCEL"), QuickReply(title=("View More"), payload="VIEW_MORE") ], metadata="DEVELOPER_DEFINED_METADATA")
def start_callback(payload, event): sender_id = event.sender_id quick_replies = [ QuickReply(title="Yeah !", payload="PICK_SYNC"), QuickReply(title="Nah ", payload="PICK_DSYNC") ] page.send(sender_id, "Would you like to sync this conversation ?\n you can subscribe etc. ",quick_replies=quick_replies,metadata="DEVELOPER_DEFINED_METADATA") print("Let's start!")
def bot_ask_participation(recipient, question): page.send(recipient, question, quick_replies=[ QuickReply(title="OK", payload="PICK_OK"), QuickReply(title="No thanks", payload="PICK_NO") ], metadata="DEVELOPER_DEFINED_METADATA")
def hello(recipient): page.send(recipient, "Hi! π") page.send(recipient, "What would you like to buy?", quick_replies=[ QuickReply(title=("Sneakers π"), payload="BUY_SNEAKERS"), QuickReply(title=("Jeans π"), payload="BUY_JEANS"), ], metadata="DEVELOPER_DEFINED_METADATA")
def view_more(recipient, event): user_profile = page.get_user_profile(event.sender_id) # return dict print(user_profile) page.send(recipient, quick_replies=[ QuickReply(title=("Sneakers π"), payload="BUY_SNEAKERS"), QuickReply(title=("Jeans π"), payload="BUY_JEANS"), ], metadata="DEVELOPER_DEFINED_METADATA")
def accept_order(payload, event): navigation = [ QuickReply("Cash On Delivery", payload="CASH_ON_DELIVERY"), QuickReply("Online Payment", payload="PAYMENT_ONLINE") ] page.send(event.sender_id, "Select payment method", quick_replies=navigation)
def initiate_feedback(): for p in models.select_participants(): page.send(p.fb_id, "We would appreciate your feedback!", quick_replies=[ QuickReply(title="Okay", payload="PICK_OK"), QuickReply(title="I'm busy", payload="PICK_NO") ], metadata="DEVELOPER_DEFINED_METADATA")
def send_quick_reply_program(recipient): page.send(recipient, "Here are some suggestion, if you wanna choose", quick_replies=[ QuickReply(title="BSCS", payload="bscs"), QuickReply(title="BSIT", payload="bsit"), QuickReply(title="BSSE", payload="bsse"), QuickReply(title="MSCS", payload="mscs") ], metadata="DEVELOPER_DEFINED_METADATA")
def send_quick_reply(recipient): page.send(recipient, "Here are some suggestion, if you wanna choose", quick_replies=[ QuickReply(title="CS Department", payload="Dep_info"), QuickReply(title="CS HOD", payload="head_info"), QuickReply(title="CS Faculty", payload="faculty_info"), QuickReply(title="CS Programs", payload="program_info") ], metadata="DEVELOPER_DEFINED_METADATA")
def last_messege(recipient): page.send(recipient, "Would you like to continue?", quick_replies=[ QuickReply(title=("Book another room"), payload="BOOK_ANOTHER_ROOM"), QuickReply(title=("Cancel"), payload="CANCEL"), QuickReply(title=("Start Again"), payload="START_AGAIN") ], metadata="DEVELOPER_DEFINED_METADATA")
def start_callback(payload, event): sender_id = event.sender_id quick_replies = [ QuickReply(title="quiz", payload="GAME"), QuickReply(title="explore", payload="D_SEARCH"), QuickReply(title="ask question", payload="Q_SEARCH") ] page.send(sender_id, "What would you like to do now?", quick_replies=quick_replies)
def start_callback(payload, event): sender_id = event.sender_id quick_replies = [ QuickReply(title="Yeah !", payload="PICK_CONF"), QuickReply(title="Nah ", payload="PICK_NCONF") ] page.send(sender_id, "Would you like to configure your ssh ", quick_replies=quick_replies, metadata="DEVELOPER_DEFINED_METADATA") print("Let's start!")
def send_quick_reply(recipient): """ shortcuts are supported page.send(recipient, "What's your favorite movie genre?", quick_replies=[{'title': 'Action', 'payload': 'PICK_ACTION'}, {'title': 'Comedy', 'payload': 'PICK_COMEDY'}, ], metadata="DEVELOPER_DEFINED_METADATA") """ page.send(recipient, "What's your favorite movie genre?", quick_replies=[QuickReply(title="Action", payload="PICK_ACTION"), QuickReply(title="Comedy", payload="PICK_COMEDY")], metadata="DEVELOPER_DEFINED_METADATA")
def quiz(event, previous=None): "start or continue a quiz" sender_id = event.sender_id message = event.message_text # Send a gif page.typing_on(sender_id) # the first question is special if previous is None: # a brand new quiz page.send( sender_id, _("Welcome to a brand new quiz! If you get seven in a row, you get a prize" )) previous = [] # a list to keep previous quiz id's else: if len(previous) == 7: app.logger.debug('we have made 7 in a row, send a prize') send_prize(event, previous) return None # ask a question try: quiz = random.choice(quizes) # get a random quiz while quiz.qid in previous: quiz = random.choice( quizes) # we've had this ques before, get a new onone except IndexError: # no quizes in list, yikes page.send( sender_id, _("We have no available quizes for you, pls try again later 8)")) return previous.append(quiz.qid) # remember what we've seen| buttons = [] for text in quiz.incorrectanswers: buttons.append( QuickReply(title=text, payload=encode_payload('ANSWER', { 'previous': previous, 'correct': False }))) # TODO: quick_replies is limited to 11, prune incorrect answers if too many buttons.append( QuickReply(title=quiz.correct, payload=encode_payload('ANSWER', { 'previous': previous, 'correct': True })), ) random.shuffle(buttons) # hide correct answer app.logger.debug("sending quiz: %s", quiz) page.send(sender_id, quiz.question, quick_replies=buttons) page.typing_off(sender_id)
def select_to_cart(payload, event): selected_product_id = payload.split('|')[1] print("______CART_SELECTED_ID", selected_product_id) navigation = [ QuickReply("1", payload="QUANTITY|1|" + str(selected_product_id)), QuickReply("2", payload="QUANTITY|2|" + str(selected_product_id)), QuickReply("3", payload="QUANTITY|3|" + str(selected_product_id)), QuickReply("4", payload="QUANTITY|4|" + str(selected_product_id)), QuickReply("5", payload="QUANTITY|5|" + str(selected_product_id)), ] page.send(event.sender_id, "Select quantity: ", quick_replies=navigation)
def get_news_quick_reply(): return [ QuickReply(title='bloomberg', payload='bloomberg'), QuickReply(title='cnn', payload='cnn'), QuickReply(title='business-insider', payload='business-insider'), QuickReply(title='bbc-news', payload='bbc-news'), QuickReply(title='cnbc', payload='cnbc'), QuickReply(title='hacker-news', payload='hacker-news'), QuickReply(title='techcrunch', payload='techcrunch'), QuickReply(title='talksport', payload='talksport'), QuickReply(title='google-news', payload='google-news'), QuickReply(title='the-times-of-india', payload='the-times-of-india') ]
def remove_from_cart(payload, event): cart = Cart.get_cart(event.sender_id) product_id = payload.split('|')[1] print("========> PRODUCT_ID: ", product_id) cart.remove_product(product_id) navigation = [ QuickReply("explore categories", payload="SHOW_CATEGORIES"), QuickReply("check cart", payload="CHECK_CART"), ] page.send(event.sender_id, "product removed", quick_replies=navigation)
def book_another(recipient): text = "Noted! " page.send(recipient, text, metadata="DEVELOPER_DEFINED_METADATA") page.send( recipient, "Would you like to book another room or would you like to continue? Γ°ΕΈβ’β", quick_replies=[ QuickReply(title=("Book another room"), payload="BOOK_ANOTHER_ROOM"), QuickReply(title=("Cancel"), payload="CANCEL"), QuickReply(title=("Continue with booking"), payload="RESERVATION") ], metadata="DEVELOPER_DEFINED_METADATA")
def send_welcome_message(recipient, event): user_profile = page.get_user_profile(event.sender_id) # return dict print(user_profile) text1 = "Hello " + user_profile['first_name'] + "!" text2 = "Welcome to your personal Shopping Example Bot. We have the following items for sale. Please choose one. π" page.send(recipient, text1, metadata="DEVELOPER_DEFINED_METADATA") page.send(recipient, text2, quick_replies=[ QuickReply(title=("Sneakers π"), payload="BUY_SNEAKERS"), QuickReply(title=("Jeans π"), payload="BUY_JEANS"), ], metadata="DEVELOPER_DEFINED_METADATA")