从后端更新Dialogflow“转移呼叫”字段(Node.js)

时间:2019-10-03 19:58:00

标签: dialogflow

我尝试使用Node.js为给定的意图在“响应”选项卡(“电话”->“添加响应”按钮)下的“转移呼叫”字段中更新电话号码,但是我不能。 新更新删除了带有旧电话号码的旧“转接呼叫”字段(我是在控制台中手动创建的,用于测试) 请帮助

这是示例代码:

const dialogflow = require('dialogflow')
const intentsClient = new dialogflow.IntentsClient({ keyFilename: 'key.json' })

const fulfillmentMessages = [ { platform: 'TELEPHONY',
telephonySynthesizeSpeech: { text: 'Hello World' } },
{ platform: 'TELEPHONY',
telephonyTransferCall: { phoneNumber: '+12132954242' } },
{ text: { text: [ '' ] } } ]

const intent = {
name: 'projects/example/agent/intents/2ef3e0b6-6cd7-4d5b-a8ca-ce11111125e019',
displayName: 'Test',
fulfillmentMessages: fulfillmentMessages
}

const updateIntentRequest = { intent: intent }

intentsClient.updateIntent(updateIntentRequest).then((data) =>{ console.log(data)}, (e) => { 
console.log(e) })

1 个答案:

答案 0 :(得分:0)

可以找到详细的回复here,但这是正确的代码示例(已测试并且可以正常工作)

const dialogflow = require('dialogflow');
const intentsClient = new dialogflow.v2beta1.IntentsClient({ keyFilename: 'key.json' }) //Note that dialogflow will be using v2beta1 api

const message_to_set = [
  { 
      platform: 10,
      telephonySynthesizeSpeech: {
             text : 'Hello World'
         },
         telephonyTransferCall: {
             phoneNumber: '+12132954242'
      }
  }
]

const intent = {
   name: 'projects/example/agent/intents/2ef3e0b6-6cd7-4d5b-a8ca-ce11111125e019',
   displayName: 'Forward',
   messages: message_to_set //Note parameter was switched from fulfillmentMessages to messages
}

const updateIntentRequest = { intent: intent }

intentsClient.updateIntent(updateIntentRequest).then((data) =>{ console.log(data)}, (e) => { console.log(e) })