def __call__(self): msg = ("You may look at another player’s card " + "or two of the center cards.") payload = player_payload(self, 'choose') b1 = Button(title="Player's Card", type='postback', payload=payload) b2 = Button(title="Two Center Cards", type='postback', payload=payload) bot.send_button_message(self.id, msg, [b1, b2])
def support(user_id, urgent=False): """ Handles every attempt to open support dialogue. Do not open if not urgent and not in working time """ time.sleep(1) if not urgent: # User trying to contact support in non working time if not 17 <= datetime.datetime.today().hour < 22 or datetime.datetime.today().isoweekday() in [6, 7]: buttons = [Button(title='Срочно', type='postback', payload='urgent')] fb_bot.send_button_message(user_id, messages.non_working, buttons) return open_dialogue("fb_id", user_id) buttons = [Button(title='Настройка', type='postback', payload='install'), Button(title='Другое', type='postback', payload='sup_other')] # Ask user to choose problem type msg = messages.type_support sub = get_info("sub", "fb_id", user_id) if sub != '-' and int(get_info("verified", "fb_id", user_id)): msg += f"\U000026A1 Ваша подписка: {sub}" fb_bot.send_button_message(user_id, msg, buttons)
def first_message(self): init = Button(title='Start New Game', type='postback', payload='init') join = Button(title='Join Existing Game', type='postback', payload='join') buttons = [init, join] bot.send_button_message(self.caller_id, "Choose Action", buttons)
def deck_prompt(self): make = Button(title='Make Deck', type='postback', payload=self.room) default = Button(title='Use Default Deck', type='postback', payload=self.room) buttons = [make, default] bot.send_button_message(self.admin, "Choose Action", buttons)
def send_menu(recipient_id): branches_button = Button(title='Branches', type='postback', payload='branches') hours_button = Button(title='Store Hours & Contact Info', type='postback', payload='schedule') prices_button = Button(title='Price Check', type='postback', payload='prices') buttons = [branches_button, hours_button, prices_button] text = 'Hi! how may I help you?' result = bot.send_button_message(recipient_id, text, buttons) return 'success'
def sendbt(recipient_id): buttons = [] button = Button(title='Doctor', type='text') buttons.append(button) button = Button(title='Patient', type='text') buttons.append(button) text = 'Select your role ' bot.send_button_message(recipient_id, text, buttons)
def test_button_message(recipient_id): buttons = [] button = Button(title='Arsenal', type='web_url', url='http://arsenal.com') buttons.append(button) button = Button(title='Other', type='postback', payload='other') buttons.append(button) text = 'Select any of them please' bot.send_button_message(recipient_id, text, buttons)
def send_initial_buttons(id, reply=False): """ Send message with starting buttons """ time.sleep(1) buttons = [Button(title='\U0001F4B4Оплата', type='postback', payload='pay'), Button(title='\U00002753Поддержка', type='postback', payload='sup'), Button(title='Другое', type='postback', payload='other')] text = messages.push_buttons if reply else messages.buttons_menu fb_bot.send_button_message(recipient_id=id, text=text, buttons=buttons)
def sendMainMenu(user_id): buttons = [] button = Button(title='Entertainment', type='postback', payload='Entertainment') buttons.append(button) button = Button(title='Offers right now', type='postback', payload='$$$') buttons.append(button) text = 'Below are the available menus.\n' text += 'Please select an option:' bot.send_button_message(user_id, text, buttons)
def sendEntertainmentMenu(user_id): buttons = [] button = Button(title='Meme', type='postback', payload='Meme') buttons.append(button) button = Button(title='Roast', type='postback', payload='Roast') buttons.append(button) button = Button(title='Compliment', type='postback', payload='Compliment') buttons.append(button) text = 'Welcome to the entertainment menu!\n' text += 'Please select an option:' bot.send_button_message(user_id, text, buttons)
def test_button_message(): buttons = [] button = Button(title='Arsenal', type='web_url', url='http://arsenal.com') buttons.append(button) button = Button(title='Other', type='postback', payload='other') buttons.append(button) text = 'Select' result = bot.send_button_message(recipient_id, text, buttons) assert type(result) is dict assert result.get('message_id') is not None assert result.get('recipient_id') is not None
def other(recipient_id): Text = "নিজের স্কিল ডেভেলপ করার উপায়" buttons = [] button1 = Button(title='পড়াশোনার মনোযোগ বৃদ্ধির উপায়া', type='postback', payload='study') button2 = Button(title="লক্ষ্যে অবিচল থাকব যেভাবে", type='postback', payload='attention') buttons.append(button1) buttons.append(button2) bot.send_button_message(recipient_id, Text, buttons)
def get_buttons(): buttons = [] button = Button(title='Want To Buy', type='web_url', url='http://crm.agrostar.in/#/products') buttons.append(button) button = Button(title='Want to Know More', type='postback', payload='other') buttons.append(button) text = 'Select Option' return text, buttons
def sendOfferMenu(user_id): buttons = [] button = Button(title='Happy hours', type='postback', payload='Happy hours') buttons.append(button) button = Button(title='Nova 2 for 1 offers', type='postback', payload='Nova 2 for 1 offers') buttons.append(button) text = 'Below are offers happening RIGHT NOW!\n' text += 'Please select an option:' bot.send_button_message(user_id, text, buttons)
def kheladhula(recipient_id): text = "আপডেট পেতে যেকোনো একটি সিলেক্ট কর" buttons = [] button1 = Button(title='IPL', type='postback', payload='ipl2020') button2 = Button(title='Cricket World Cup 2019', type="web_url", url="https://www.cricketworldcup.com/") button3 = Button(title="FIFA World Cup 2022", type='web_url', url='https://www.fifa.com/worldcup/') buttons.append(button1) buttons.append(button2) buttons.append(button3) bot.send_button_message(recipient_id, text, buttons)
def slide_message(recipient_id, content, access_token): buttons = [] elements = [] element = {'title': '', 'image_url': '', 'subtitle': '', 'buttons': []} cont = 0 for data in content: buttons = [] for btn in data['buttons']: if btn['typeButton'] == 'web_url': button = Button(title=btn['titleButton'], type='web_url', url=btn['urlButton']) elif btn['typeButton'] == 'postback': button = Button(title=btn['titleButton'], type='postback', payload=btn['payloadButton']) buttons.append(button) cont = cont + 1 if cont > 2: break element = { 'title': data['title'], 'image_url': data['image_url'], 'subtitle': data['subtitle'], 'buttons': buttons } elements.append(element) payload = { "recipient": { "id": recipient_id }, "message": { "attachment": { "type": "template", "payload": { "template_type": "generic", "elements": elements } } }, 'notification_type': 'REGULAR' } result = send_message(payload, access_token) assert type(result) is dict assert result.get('message_id') is not None assert result.get('recipient_id') is not None
def buttons_response(bot, sender, message): buttons = [] for button in message.buttons: if button.kind == 'postback': item = Button(title=button.name, type=button.kind, payload=button.name.lower()) buttons.append(item) if button.kind == 'web_url': item = Button(title=button.name, type=button.kind, url=button.url) buttons.append(item) text = message.response bot.send_button_message(sender, text, buttons)
def send_option_message(self, recipient_id, response, options): buttons = [] for element in options: button = Button(title=element, type='postback', payload='other') buttons.append(button) self.bot.send_button_message(recipient_id, response, buttons) return "success"
def generate_message(text, recipient_id): data = get_data() books = data['books'] names = data['names'] if text in names: index = names.index(text) try: change_color(index+1, index+2, 2, 3, G=1) return "Ok" except: return "Error" elif text in books: count = books.count(text) if count > 1: return "يوجد اكثر من نسخه. ما هو اسم المستعير؟" index = books.index(text) try: change_color(index+1, index+2, 2, 3, G=1) return "Ok" except: return "Error" else: words = names+books matches = difflib.get_close_matches(text, words) if matches<1: return "غير موجود" buttons = [Button(type='postback', title=match, payload=match) for match in matches] res = bot.send_button_message(recipient_id, "did you mean:", buttons)
def button_message(recipient_id, content, options, access_token): buttons = [] cont = 0 for opc in options: button = Button(title=opc, type='postback', payload=opc) buttons.append(button) cont = cont + 1 if cont > 2: break payload = { 'message': { 'attachment': { 'type': 'template', 'payload': { 'template_type': 'button', 'text': content, 'buttons': buttons } } }, 'recipient': { 'id': recipient_id }, 'notification_type': 'REGULAR' } result = send_message(payload, access_token) assert type(result) is dict assert result.get('message_id') is not None assert result.get('recipient_id') is not None
def send_buttons(self, inbuttons, action_description): buttons = [] for inbtn in inbuttons: button = Button(title=inbtn[0], type=inbtn[1], payload='other') buttons.append(button) bot.send_button_message(self._id, action_description, buttons) return "success"
def postback_button(button_title="How can i register?", button_payload="Sample questions"): button = Button(title=button_title, type='postback', payload=button_payload) return button '''button = Button(title='More questions', type='postback', payload='questions')
def pick_center_card(payload_str, title, subtitle): buttons = [] for x in range(3): button_title = "Card {:d}".format(x + 1) buttons.append( Button(title=button_title, type='postback', payload=payload_str)) element = Element(title=title, image_url=urls.center_img, subtitle=subtitle, buttons=buttons) return [element]
def player_carousel(player, action, do_nothing=False): elements = [] players = player.game_state.players if do_nothing: nothing_button = Button(title="Do Nothing", type='postback', payload=player_payload(player, action)) for k in players: if k != player.player_no: #player_no as k will be passed payload formatted in a dictionary #with key 0 payload = player_payload(player, action, str(k)) button = Button(title="Pick", type='postback', payload=payload) if do_nothing: buttons = [button, nothing_button] else: buttons = [button] elements.append( Element(title=players[k].first_name, image_url=players[k].profile_pic, buttons=buttons)) return elements
def initialize_payment_interface(user_id, amount): buttons = [] button = Button( type='web_url', url= 'http://www.students.ic.unicamp.br/~ra158044/visa_checkout.html?value=' + str(amount), title='Payment', webview_height_ratio='tall', webview_share_button='hide') buttons.append(button) text = 'Please click here to complete' result = bot.send_button_message(recipient_id, text, buttons)
def first_msg(recipient_id): text = " হ্যালো ব্রাদার, ছোটখাটো এই বটের দুনিয়ায় আমাকে স্বাগতম! তুমি আমাকে রোবট ভাই বলে ডাকতে পারো!!" buttons = [] button1 = Button(title='খবরাখবর', type='postback', payload='news') button2 = Button(title='খেলাধুলা', type='postback', payload='sports') #button3 = Button(title="ক্ষুধা লাগছে", type='web_url',url='https://www.foodpanda.com.bd/?gclid=Cj0KCQjw2or8BRCNARIsAC_ppyaxlUnuvIHnJUn3cJ026az3ujpRLrEaCq5o1Yv7Zopsc3riG1laJvwaAv9cEALw_wcB') button4 = Button(title='অন্যান্য', type='postback', payload='others') buttons.append(button1) buttons.append(button2) #buttons.append(button3) buttons.append(button4) bot.send_button_message(recipient_id, text, buttons) rext = "Shortcuts" buttons2 = [] button3 = Button(title="FOODPANDA", type='web_url', url='https://www.foodpanda.com.bd/') button5 = Button(title='UBER', type='web_url', url='https://www.uber.com/bd/en/') buttons2.append(button3) buttons2.append(button5) bot.send_button_message(recipient_id, rext, buttons2)
def send_templates(recipient_id): templates = [] for temp in TEMPLATES: templates.append( Element(title="Vorlage", image_url=asset_url(temp + "_preview.png"), subtitle="Vorlage", buttons=[ Button({ "type": "postback", "title": "Vorlage wählen", "payload": temp }) ])) bot.send_generic_message(recipient_id, templates)
def menu(db: Database, option: Option): options = get_suboptions(db, option) quick_replies = [] buttons = [Button( title=option.title, type='postback', payload=GoToOption(option_id=option.id,).to_json() ) for option in options] messages = [] for _, section in itertools.groupby(buttons, _grouper(buttons, 3)): message = { 'attachment': { 'type': 'template', 'payload': { 'template_type': 'button', 'text': option.title, 'buttons': list(section) } }, } if quick_replies: message['quick_replies'] = quick_replies messages.append(message) return messages
def close_dialogue(type_id, id, pay=False, silent=False, notify_admin_group=True): """ Change client state in DB to CLOSED and update pinned message with new info Optionally send client closing message """ time.sleep(1) user_state = get_info('state', type_id, id) # Return if client not found in DB if not user_state: return # Point that dialogue is already closed and return to prevent multiple closing messages for client if user_state in ["CLOSED", "ONE MESSAGE"]: bot.send_message(config.group_id, "Диалог уже закрыт") return update_clients([type_id, id], ["state", "CLOSED"], ["rate", "0"], ["review_time", "0"], ["received", "NO"]) if notify_admin_group: bot.send_message(config.group_id, f"Диалог закрыт\n{id}") update_pinned_top() if pay: update_clients([type_id, id], ["verified", 1]) # Do not send any message to client if silent or pay: return if type_id == "tg_id": # Ask client to rate support buttons = types.InlineKeyboardMarkup() buttons.add( types.InlineKeyboardButton(text="\U0001F92C 1", callback_data="1")) buttons.add( types.InlineKeyboardButton(text="\U00002639 2", callback_data="2")) buttons.add( types.InlineKeyboardButton(text="\U0001F610 3", callback_data="3")) buttons.add( types.InlineKeyboardButton(text="\U0001F642 4", callback_data="4")) buttons.add( types.InlineKeyboardButton(text="\U0001F600 5", callback_data="5")) bot.send_message(id, messages.close, reply_markup=buttons) elif type_id == "vk_id": keyboard = VkKeyboard(inline=True) keyboard.add_button("\U0001F92C 1") keyboard.add_line() keyboard.add_button("\U00002639 2") keyboard.add_line() keyboard.add_button("\U0001F610 3") keyboard.add_line() keyboard.add_button("\U0001F642 4") keyboard.add_line() keyboard.add_button("\U0001F600 5") vk_send_message(id, messages.close, keyboard=keyboard.get_keyboard()) elif type_id == "fb_id": buttons = [ Button(title='\U0001F92C Плохо', type='postback', payload='2'), Button(title='\U0001F610 Нормально', type='postback', payload='4'), Button(title='\U0001F600 Отлично', type='postback', payload='5') ] fb_bot.send_button_message(recipient_id=id, text=messages.close, buttons=buttons)
def webhook(): data = request.get_json() log(data) print(data) if data['object'] == 'page': for entry in data['entry']: for messaging_event in entry['messaging']: sender_id = messaging_event['sender']['id'] recipient_id = messaging_event['recipient']['id'] global last_message if messaging_event.get('message'): if 'is_echo' not in messaging_event['message']: if 'text' in messaging_event['message']: messaging_text = messaging_event['message']['text'] if messaging_text != last_message: last_message = messaging_text print("last_message:" + last_message) entity = None # print(messaging_text) response = None try: entity = wit_response(messaging_text) print(entity) except Exception: pass if entity == "price_crypto": for phrase in crypto_name: if phrase in messaging_text.lower(): element = load_crypto(phrase) bot.send_generic_message( sender_id, element) image_url = stock_show() gif(sender_id, image_url) else: pass # image_url = 'https://media.giphy.com/media/rl0FOxdz7CcxO/giphy.gif' # continue elif entity == 'welcome_greets': print("welcome") image_url = news_complete() print("Done") response = 'Hello I am your Share Market & Crypto-Currency Bot \n\nHow can i help You? \n\n'\ + "Here are a Command Before we get Started \n\nupdate=>updates the database always do this before you get started\n\n"\ + "then just feel free to ask me anything 😄 " bot.send_text_message(sender_id, response) gif(sender_id, image_url) elif entity == 'stock_update': image_url = news_complete() # print(image_url) print("Done") buttons = [] button = Button(title='Stocks', type='postback', payload='stocks') buttons.append(button) button = Button(title='Crypto-Currency', type='postback', payload='crypto-currency') buttons.append(button) text = 'Select One To Update ' result = bot.send_button_message( sender_id, text, buttons) gif(sender_id, image_url) elif entity == "stock_price": state = None print("Done") element, state = stock(messaging_text) # if bool(element) != False: bot.send_generic_message( sender_id, element) print(state) if state is True: image_url = happy() print(image_url) gif(sender_id, image_url) else: image_url = sad() gif(sender_id, image_url) print(image_url) # else: # image_url = nope() # gif(sender_id, image_url) # continue gif(sender_id, image_url) # image_url = 'https://media.giphy.com/media/rl0FOxdz7CcxO/giphy.gif' elif entity == "stock_news": print("Done") element = news() if bool(element) != False: bot.send_generic_message( sender_id, element) else: image_url = nope() gif(sender_id, image_url) continue # image_url = 'https://media.giphy.com/media/rl0FOxdz7CcxO/giphy.gif' image_url = news_complete() gif(sender_id, image_url) elif entity == "stock_financial": element = load_financial(messaging_text) bot.send_generic_message( sender_id, element) # else: # image_url = nope() # gif(sender_id, image_url) # continue image_url = stock_show() gif(sender_id, image_url) else: # pass messaging_text = 'no text' elif messaging_event.get('postback'): if 'title' in messaging_event['postback']: messaging_text = messaging_event['postback']['title'] print(messaging_text) if messaging_text != last_message: last_message = messaging_text if 'Stocks' in messaging_text: print(messaging_text) image_url = updating() gif(sender_id, image_url) bot.send_text_message(sender_id, "Starting") stock_read() bot.send_text_message(sender_id, "Completetd =====>20%") market_newss() bot.send_text_message(sender_id, "Completetd =====>60%") financial_data() bot.send_text_message(sender_id, "Completetd =====>100%") elif 'Crypto-Currency' in messaging_text: image_url = complete() print(image_url) crypto_load() print("Done") gif(sender_id, image_url) response = "Done" bot.send_text_message(sender_id, response) # messaging_text = messaging_text.lower() # response = None # entity, value = wit_response(messaging_text) # print(entity, value) # if entity == "newstype:newstype": # response = "Ok. I will send you {} news".format(str(value)) # elif entity == "location:location": # response = "ok so you live in {0}. I will send you top headlines from {0}".format(str(value)) # elif response == None: # response = "sorry i didnt get you" # response = stock(messaging_text) # buttons = [] # button = Button(title='Arsenal', type='web_url', url='http://arsenal.com') # buttons.append(button) # button = Button(title='Other', type='postback', payload='other') # buttons.append(button) # text = 'Select One To Update ' # buttons = [] # button = Button(title='Stocks', type='postback', payload='stocks') # buttons.append(button) # button = Button(title='Crypto-Currency', type='postback', payload='crypto-currency') # buttons.append(button) # text = 'Select One To Update ' # result = bot.send_button_message(sender_id, text, buttons) # # image_url = 'https://lh4.googleusercontent.com/-dZ2LhrpNpxs/AAAAAAAAAAI/AAAAAAAA1os/qrf-VeTVJrg/s0-c-k-no-ns/photo.jpg' # # elements = [] # '''element = Element(title=title, image_url="https://images.moneycontrol.com/images/common/header/logo.png?v=0.2&impolicy=mchigh", subtitle=subtitle, # item_url="https://www.moneycontrol.com/india/stockpricequote/banks-private-sector/hdfcbank/HDF01" ) # elements.append(element)''' # # element = Element(title=title, subtitle=subtitle, webview="tall") # elements.append(element) # # result = bot.send_generic_message(sender_id, elements) # buttons = [] # button = Button(title='Arsenal', type='web_url', url='http://arsenal.com') # buttons.append(button) # button = Button(title='Other', type='postback', payload='other') # buttons.append(button) # text = 'Select' # result = bot.send_button_message(sender_id, text, buttons) # print("DONE") # bot.send_text_message(sender_id, elements) # # response = { # # 'attachment': { # # 'type': 'image', # # 'payload': { # # 'url': 'http://facebook.com/image.jpg' # # } # # } # # } # # image_url = 'https://lh4.googleusercontent.com/-dZ2LhrpNpxs/AAAAAAAAAAI/AAAAAAAA1os/qrf-VeTVJrg/s0-c-k-no-ns/photo.jpg' # # result = bot.send_image_url(recipient_id, image_url) # # user_profile = bot.get_user_info(recipient_id) # image_url = 'https://media.giphy.com/media/rl0FOxdz7CcxO/giphy.gif' # result = bot.send_image_url(recipient_id, image_url) # image_url = 'https://media.giphy.com/media/1fgI4bZpCo9S57r4Vd/giphy.gif' # bot.send_image_url(recipient_id, image_url) return "ok", 200