Documentation

Do you use documentation to use NewBot Framework

Make a request

Previously

Let's add the function in the skill:

import code from './main.converse'
import request from 'newbot/functions/request'

export default {
    code,
    functions: {
        request
    }
}

In the ConverseScript, Let's Perform a Query

@Event('start') 
start() {
    request('https://jsonplaceholder.typicode.com/photos?_limit=10')
    > {:response.data[0].title }
}

Using the function request, you can make a request. The answer is stored in the magic variable :response

Notice the properties retrieved in the query response still do not match the carousel format, we can transform the response to match the format.

Use the functions property in the skill:

import code from './main.converse'
import request from 'newbot/functions/request'

export default {
    code,
    functions: {
        request,
        mapPhotos(photos) {
            return photos.map(photo => ({
                title: photo.title,
                image: photo.thumbnailUrl,
                buttons: [
                    {
                        url: photo.url,
                        title: 'View'
                    }
                ]
            }))
        }
    }
}

In main.converse, we can use our function to transform the received data

@Event('start') 
start() {
    Request('https://jsonplaceholder.typicode.com/photos?_limit=10')
    @Format('carousel', mapPhotos(:response))
    > Your photos !
}
© 2019 NewBot