我们正在使用Microsoft NodeJS开发一个机器人。在这种情况下,我们的要求是,一旦输入了Utterance,就需要对我们服务器之一进行API调用,并且需要在Bot中显示从服务器接收到的数据。 我正在获取数据并能够在控制台中查看结果。但是我无法在Bot中打印该回复。
下面是我的bot.js代码片段:
/**
*
* Use onTurn to handle an incoming activity, received from a user,
process it, and reply as needed
*
* @param {TurnContext} on turn context object.
*/
async onTurn(turnContext) {
// Handle message activity type. User's responses via text or speech
or card interactions flow back to the bot as Message activity.
// Message activities may contain text, speech, interactive cards, and
binary or unknown attachments.
// see https://aka.ms/about-bot-activity-message to learn more about
the message and other activity types
if (turnContext.activity.type === ActivityTypes.Message) {
// read from state.
let count = await this.countProperty.get(turnContext);
count = count === undefined ? 1 : ++count;
const callingSynapse = async function() {
var dataObject = somethinng;
requestify.post('IPAddress', dataObject).then(async
function(response) {
let result =
JSON.parse(response.body).result.result.botMessage;
console.log(result); /*This line showing the Exact output
I need.*/
await turnContext.sendActivity(`${result} `);
});
}
await turnContext.sendActivity(`You said:
${turnContext.activity.text } `);
callingSynapse();
// increment and set turn counter.
await this.countProperty.set(turnContext, count);
} else {
// Generic handler for all other activity types.
await turnContext.sendActivity(`[${ turnContext.activity.type }
event detected]`);
}
// Save state changes
await this.conversationState.saveChanges(turnContext);
}
行await turnContext.sendActivity(
$ {result} );
无法将结果显示给Bot。
即使我写了行await turnContext.sendActivity(
,您说过:requestify块中的$ {turnContext.activity.text} );
,也无法显示。
有人可以帮我解决这个问题吗?
谢谢。