Exemple #1
0
    def init_bot(self):
        self.add_whitelisted_domains('https://facebook.com/')
        greeting = GreetingText(text='Welcome to the fbmessenger bot demo.')
        self.set_messenger_profile(greeting.to_dict())

        get_started = GetStartedButton(payload='start')
        self.set_messenger_profile(get_started.to_dict())

        menu_item_1 = PersistentMenuItem(
            item_type='postback',
            title='Help',
            payload='help',
        )
        menu_item_2 = PersistentMenuItem(
            item_type='web_url',
            title='Messenger Docs',
            url='https://developers.facebook.com/docs/messenger-platform',
        )
        persistent_menu = PersistentMenu(menu_items=[
            menu_item_1,
            menu_item_2
        ])

        res = self.set_messenger_profile(persistent_menu.to_dict())
        app.logger.debug('Response: {}'.format(res))
Exemple #2
0
    def init_bot(self):
        """Handles greeting procedure and persistent menu"""

        greet_txt = responses["greet"]
        greeting_text = GreetingText(greet_txt)
        get_started = GetStartedButton(payload='WELCOME')

        menu_item = PersistentMenuItem(item_type='postback',
                                       title='Restart recipe search',
                                       payload='RESTART')
        menu = PersistentMenu(menu_items=[menu_item])

        messenger_profile = MessengerProfile(persistent_menus=[menu],
                                             get_started=get_started,
                                             greetings=[greeting_text])
        res = self.set_messenger_profile(messenger_profile.to_dict())
        app.logger.info('Response: {}'.format(res))
Exemple #3
0
    def init_bot(self):
        self.add_whitelisted_domains('https://facebook.com/')

        #get started button
        get_started = GetStartedButton(payload='start')
        messenger_profile = MessengerProfile(get_started=get_started)
        res = self.set_messenger_profile(messenger_profile.to_dict())
        app.logger.debug('Response: {}'.format(res))

        #persistent menu entries

        menu_item_1 = PersistentMenuItem(
            item_type='postback',
            title='Get Started',
            payload='start'
        )

        menu_item_2 = PersistentMenuItem(
            item_type='postback',
            title='Help',
            payload='help',
        )

        menu_item_3 = PersistentMenuItem(
            item_type='postback',
            title='Example',
            payload='example',
        )
     
        
        # menu_item_4 = PersistentMenuItem(
        #     item_type='web_url',
        #     title='Messenger Docs',
        #     url='https://developers.facebook.com/docs/messenger-platform',
        # )

        persistent_menu = PersistentMenu(menu_items=[
            menu_item_1,
            menu_item_2,
            menu_item_3
        ])

        messenger_profile = MessengerProfile(persistent_menus=[persistent_menu])
        res = self.set_messenger_profile(messenger_profile.to_dict())
        app.logger.debug('Response: {}'.format(res))
Exemple #4
0
def helloMenu():
    '''
        You cannot have more than 3 `menu_items` in top level
        Valid `item_type`: 'nested' | 'web_url' | 'postback'
        `nested_items`(an array of not more than 5 PersistentMenuItem) must be supplied for 
            `nested` type menu_items 
        `url` must be supplied for `web_url` type menu items
        `payload` must be supplied for `postback` type `menu_items`
        `messenger_extensions` (TRUE | FALSE) & `webview_height_ratio` (COMPACT | TALL | FULL) is 
            only valid for item type `web_url`
        len(title) <= 30
        example_item = PersistentMenuItem(item_type, title, nested_items=None, url=None, payload=None, 
            fallback_url=None, messenger_extensions=None, webview_share_button=None, webview_height_ratio=None)
    '''
    menu_item_1 = PersistentMenuItem(item_type='postback',
                                     title='Stop',
                                     payload='stop_asking')

    #en_menu = PersistentMenu(menu_items=[menu_item_1, menu_item_2], locale='en_US', composer_input_disabled=None)
    menu = PersistentMenu(menu_items=[menu_item_1])
    postRequest(messenger_profile_url,
                MessengerProfile(persistent_menus=[menu]).to_dict())
Exemple #5
0
    def _convert_to_persistent_menu(
            custom_json: Dict[Text, Any]) -> PersistentMenu:
        """Convert json custom message for persitent Menu into a PersistentMenu object support 
                by fbmessenger api ."""

        pers_menu_item_0 = []
        pers_menu_item_1 = []
        nested_menu_item_depth_0 = []
        nested_menu_item_depth_1 = []
        for json_message in custom_json:
            if 'payload' in json_message.keys():
                payload_depth_0 = json_message['payload']

            if 'title' in json_message.keys():
                title_depth_0 = json_message['title']
            else:
                raise ValueError(
                    "You must specify a title for your menu items.")

            if 'type' in json_message.keys():
                type_depth_0 = json_message['type']

                if type_depth_0 == 'nested' and ('nested_items'
                                                 in json_message.keys()):

                    for json_item_depth_1 in json_message['nested_items']:
                        if 'payload' in json_item_depth_1.keys():
                            payload_depth_1 = json_item_depth_1['payload']

                        if 'title' in json_item_depth_1.keys():
                            title_depth_1 = json_item_depth_1['title']

                        if 'type' in json_item_depth_1.keys():
                            type_depth_1 = json_item_depth_1['type']
                            if type_depth_1 == 'nested' and (
                                    'nested_items'
                                    in json_item_depth_1.keys()):
                                for json_item_depth_2 in json_item_depth_1[
                                        'nested_items']:
                                    if 'payload' in json_item_depth_2.keys():
                                        payload = json_item_depth_2['payload']

                                    if 'title' in json_item_depth_2.keys():
                                        title = json_item_depth_2['title']

                                    if 'type' in json_item_depth_2.keys():
                                        type_depth_2 = json_item_depth_2[
                                            'type']
                                        if type_depth_2 == 'nested':
                                            raise ValueError(
                                                "You must have at most two nested menus!"
                                            )
                                    nested_menu_item_depth_1.append(
                                        PersistentMenuItem(
                                            title=title,
                                            item_type=type_depth_2,
                                            payload=payload))
                                PersistentMenuItem(
                                    title=title_depth_1,
                                    item_type=type_depth_1,
                                    nested_items=nested_menu_item_depth_1)

                            else:
                                nested_menu_item_depth_0.append(
                                    PersistentMenuItem(
                                        title=title_depth_1,
                                        item_type=type_depth_1,
                                        payload=payload_depth_1))
                    pers_menu_item_1.append(
                        PersistentMenuItem(
                            item_type=type_depth_0,
                            title=title_depth_0,
                            nested_items=nested_menu_item_depth_0))

                else:
                    pers_menu_item_0.append(
                        PersistentMenuItem(item_type=type_depth_0,
                                           title=title_depth_0,
                                           payload=payload_depth_0))
            else:
                raise ValueError("You must specify a type for your menu items")
        pers_menu_item_0.extend(pers_menu_item_1)

        return PersistentMenu(menu_items=pers_menu_item_0)
Exemple #6
0
    open(os.path.abspath(os.path.join(os.getcwd(), "src/texts.json")), "r"))

msngr = Messenger()
greeting_text = GreetingText(texts["greetings"])

schedule_order_now_menu_item = PersistentMenuItem(item_type="postback",
                                                  title="Schedule Order Now",
                                                  payload=State.SCHEDULE_ORDER)
login_item = PersistentMenuItem(item_type="postback",
                                title="Login",
                                payload=State.LOGIN)
register_item = PersistentMenuItem(item_type="postback",
                                   title="Register",
                                   payload=State.REGISTER)

menu = PersistentMenu(
    menu_items=[schedule_order_now_menu_item, login_item, register_item])

messenger_profile = MessengerProfile(
    persistent_menus=[menu],
    greetings=[greeting_text],
    get_started=GetStartedButton(payload=State.HI),
)
msngr.set_messenger_profile(messenger_profile.to_dict())

print("msngr profile set")


def handle_message(json_response):
    print(json_response)
    msngr.handle(json_response)