Javascript API.ai如何在同一答案中为webhook中的speech和displaytext字段添加不同的实现

Javascript API.ai如何在同一答案中为webhook中的speech和displaytext字段添加不同的实现,javascript,json,dialogflow-es,Javascript,Json,Dialogflow Es,我试图从一个webhook发回一个响应,内容格式化为可读,内容格式化为口语。屏幕上要读取的文本将在displaytext字段中,而要说出的文本将在speech字段中。使用中的weather webhook示例,我尝试向resolve方法添加第二个对象: resolve(speech_output, displayText_output); 但用于发送响应时,不使用displayText_输出: callWeatherApi(city, date).then((speech_output, di

我试图从一个webhook发回一个响应,内容格式化为可读,内容格式化为口语。屏幕上要读取的文本将在displaytext字段中,而要说出的文本将在speech字段中。使用中的weather webhook示例,我尝试向resolve方法添加第二个对象:

resolve(speech_output, displayText_output);
但用于发送响应时,不使用displayText_输出:

callWeatherApi(city, date).then((speech_output, displayText_output) => {
            // Return the results of the weather API to API.AI
            res.setHeader('Content-Type', 'application/json');
            res.send(JSON.stringify({'speech': speech_output, 'displayText': displayText_output}));
响应的JSON对象中不包括displayText。我认为Promise.resolve只需要处理一个参数,一个参数返回错误,比如Promise(resolve,reject)。但是,当两个字段都使用speech_输出值时,JSON响应中会包含displayText

我想知道是否有一种方法可以实现这两个字段,在同一个答案中发送不同的信息


谢谢

最简单的方法是为变量
output
创建一个新的Javascript对象,以包含
displayText
speech
属性。例如:

output = { 'displayText': 'YOUR DISPLAY TEXT STRING HERE',
           'speech': 'YOUR SPEECH STRING HERE' };
resolve(output);
然后在
然后
块中:

callWeatherApi(city, date).then((output) => {
            // Return the results of the weather API to API.AI
            res.setHeader('Content-Type', 'application/json');
            res.send(JSON.stringify(output));

谢谢,伙计,它工作得很好。非常感谢。