显示对用户Google助手的api响应

时间:2019-02-12 12:22:40

标签: dialogflow actions-on-google

我正在创建一个Google Action,它向我的服务器请求一些信息,并向用户显示响应,但是该响应不起作用。

操作和链接帐户运行正常,我使用的是付费帐户,所以我可以得到Api响应,但只能向用户显示

我做到了:

app.intent('Get Sign In', (conv, params, signin) => {
    console.log('signIn');
    if (signin.status === 'OK') {
        console.log('userId', conv.user.raw.userId);
        console.log('params-debug', params);
        conv.add(`accessToken: ${conv.user.raw.accessToken} - Buscando Nickname`);//works

        const bearer = 'Bearer ' + conv.user.raw.accessToken;
        const options = {
            method: 'GET',
            url: '{URL}',
            headers: {
              'Authorization': bearer,
            },
            json: true,
        };

        request.post(options, (err, httpResponse, body) => {
            console.log(`received response`);
            if (err) {
                console.log(`deu erro`);//works
                console.log(err);//works - here i can see the api response correctly
                conv.ask(`error: ${err}`);//DOESN'T WORK
                return;
            } else {
                console.log(`deu certo`);//works
                console.log(body);//works
                conv.ask(`Got your nickname`);//DOESN'T WORK
                conv.ask(`nickname: ${body.nickname}`);//DOESN'T WORK
            }
        });
    } else {
        console.log(`not signed in: ${signin.status}`);
        console.log(`not signed in: ${signin}`);
        conv.ask(`I won't be able to save your data, but what do you want to do next?`);
    }
});

我也尝试了Promises,但结果相同,我在DialogFlow上使用内联编辑器。

是否可以将结果显示给用户?我在做什么错了?

0 个答案:

没有答案