访问令牌未定义

时间:2019-03-27 06:26:45

标签: dialogflow chatbot google-assistant-sdk

我是Google动作和对话框流程的新手。在这里,我想向Google Assistant发送通知。但是我得到

TypeError:无法读取未定义的属性'access_token'

 const { google } = require('googleapis');
 const key = require('./myapp.json');

let jwtClient = new google.auth.JWT(
 key.client_email, null, key.private_key,
 ['https://www.googleapis.com/auth/actions.fulfillment.conversation'],
 null
 );

jwtClient.authorize((err, tokens) => {
let notif = {
    userNotification: {
        title: "message",
    },
    target: {
        userId: 'xxxyyyzzzz',
        intent: 'intent_name',
        locale: 'en-US'
    },
};

request.post('https://actions.googleapis.com/v2/conversations:send', {
    'auth': {
        'bearer': tokens.access_token,
    },
    'json': true,
    'body': { 'customPushMessage': notif },
}, (err, httpResponse, body) => {
    console.log(body);
    console.log(httpResponse.statusCode + ': ' + httpResponse.statusMessage);
  });
});

0 个答案:

没有答案