How to get external api data using inline editor in dialogflow

3.8k Views Asked by At

I've got a Dialogflow agent for which I'm using the Inline Editor (powered by Cloud Functions for Firebase). When I try to get external api data by using request-promise-native I keep getting Ignoring exception from a finished function in my firebase console.

function video(agent) {
    agent.add(`You are now being handled by the productivity intent`);
    const url = "https://reqres.in/api/users?page=2";
    return request.get(url)
        .then(jsonBody => {
            var body = JSON.parse(jsonBody);
            agent.add(body.data[0].first_name)
            return Promise.resolve(agent);
        });
}
2

There are 2 best solutions below

4
On BEST ANSWER

Your code looks correct. The exception in this case might be that you're not using a paid account, so network access outside Google is blocked. You can probably see the exact exception by adding a catch block:

function video(agent) {
    agent.add(`You are now being handled by the productivity intent`);
    const url = "https://reqres.in/api/users?page=2";
    return request.get(url)
        .then(jsonBody => {
            var body = JSON.parse(jsonBody);
            agent.add(body.data[0].first_name)
            return Promise.resolve(agent);
        })
        .catch(err => {
            console.error('Problem making network call', err);
            agent.add('Unable to get result');
            return Promise.resolve(agent);
        });
}

(If you do this, you may want to update your question with the exact error from the logs.)

4
On

Inline Editor uses Firebase. If you do not have a paid account with Firebase, you will not be able to access external APIs.