Use @Format

Use formats

Quick response

Show quick answers like this:

@Event('start')
start() {
    @Format('quickReplies', ['yes', 'no'])
    > Continue ?
    Prompt()
    > Ok !
}

Here's how to display a carousel:

@Event('start')
start() {
    @Format('carousel', [
        {
            title: 'TITLE',
            subtitle: 'SUBTITLE',
            image: 'URL_IMAGE',
            buttons: [
                {
                    url: 'URL',
                    title: 'TITLE BUTTON'
                }
            ]
        }
    ])
    > Continue ?
}

Display an image

@Event('start')
start() {
    @Format('image', 'http://url.com/image.png')
    > Nice picture !
}

Send text with buttons

@Event('start')
start() {
    @Format('buttons', [
        {
            title: 'An url',
            url: 'https://google.fr'
        },
        {
            type: 'postback',
            title: 'Postback'
        }
    ])
    > Buttons
}

Webview

  1. Create an webviews folder at the root of the project

  2. Put an HTML file (eg webviews/map.html)

@Event('start')
start() {
    @Format('webview', {
        url: '/webview/map.html', // required
        button: 'View map', // for other platforms,
        fbHeight: 'full', // compact, tall or full (only for Messenger)
        height: 600 // in pixels, only for chatbox
    })
    > Ok, here is the webview
}

Share button

On Facebook Messenger, NewBot ChatBox and Twitter, we can share content with the following code

@Event('start')
start() {
    @Format('buttons', [
        {
           type: 'share'
        }
    ])
    > Buttons
}

On Twitter

On Twitter, let's add the tweet property:

@Event('start')
start() {
    @Format('buttons', [
        {
           type: 'share',
           tweet: {
               text: 'Partagez-moi',
               url: 'https://newbot.io'
               via: '@me',
               hashtags: ['one', 'two']
           }
       }
    ])
    > Share
}
  • tweet.text (required): Text in the tweet

  • tweet.url (optional): Url to share

  • tweet.via (optional): User Profile to Share

  • tweet.hashtags (optional): Embed Hashtags

Show a video

@Event('start')
start() {
    @Format('video', 'http://url.com/video.mp4')
    > Nice video !
}

Send a contact

@Event('start')
start() {
    @Format('contact', '0123456789', 'Sam R')
    > Here is my friend !
}

Last updated