在bot框架v4 Nodejs中发送之前拦截bot消息

时间:2019-11-04 18:14:32

标签: node.js express botframework

我需要在发送对象之前添加字段,所以我尝试了

    turnContext.onSendActivities(async (ctx, activities, nextSend) => {
        for (let activity of activities){
            activity.channelData.data='hi'
            console.log(activity)
                    }
        return await nextSend();
    })

但是它不反映我所了解的活动已经发送,并且该功能用于记录。

有什么办法可以使它工作?

1 个答案:

答案 0 :(得分:0)

只需在处理程序中包含onSendActivities()函数即可。然后,请确保先return await next(),然后再进行以下任何代码,包括处理程序的await next()。以下设置会将{ data: 'hi' }对象附加到每个活动中。

唯一的另一步是确定正确的处理程序和正确的逻辑,以便在需要时发送所需的数据。

希望有帮助!

this.onTurn(async (turnContext, next) => {

  await turnContext.onSendActivities(async (ctx, activities, next) => {
    for (let activity of activities) {
      activity.channelData = { data: 'hi' };
    }
    return await next();
  });

  await next();
});

enter image description here