拦截用户消息修改,bot框架

intercept user message to modify it , bot framework

我用的是直连bot框架,想拦截用户的消息再发到服务器修改

这个想法是,如果用户输入一些 phone 号码、信用卡等,用星号修改消息的那部分,并且不会将带有该数据的消息传送到服务器. 我试图配置一些事件或 activity 但我做不到。

我已经尝试使用 javascript,为输入框和按钮创建一个附加事件侦听器,但是当该事件启动时,无法再修改消息

有什么想法吗?

conect.activity$
                    .filter(function (activity) {   
                      return activity.type === 'endOfConversation';
                    })
                    .subscribe(function (activity) {
                        console.log('RemoveLocalStorage endOfConversation');
                     RemoveLocalStorage("paramCon");
                    });

                      BotChat.App({
                        botConnection : conect,
                        speechOptions: speechOptions,
                        user: user,
                        bot: bot,
                        typing:false,
                        locale: (params.locale !== undefined) ? params.locale : "es-es",
                        resize: 'detect'
                      },window.parent.frames["chatBot"].document.getElementById('bot'));
                     //window.frames[0].document.getElementById('bot')
                      //document.getElementById("bot")

window.parent.frames["chatBot"].document.getElementsByClassName("wc-send")[0].addEventListener("click", disableSensitiveData);
    window.parent.frames["chatBot"].document.getElementsByClassName("wc-textbox")[0].addEventListener("keyup", disableSensitiveData);

您可以创建一个自定义中间件来在用户点击发送时拦截和修改消息的文本属性。我在下面的 Webchat V3 和 V4 中创建了将整个消息转换为星号的示例。

WebChat V4

// We are adding a new middleware to customize the behavior of WEB_CHAT/SEND_MESSAGE.
const store = window.WebChat.createStore(
  {},
  ({ dispatch }) => next => action => {
      if (action.type === 'WEB_CHAT/SEND_MESSAGE') {
        // Edit text when user sends message
        action.payload.text = action.payload.text.split('').map(_ => '*').join('')
      }
      return next(action);
  }
);

window.WebChat.renderWebChat({
  directLine: window.WebChat.createDirectLine({ token }),
  store
}, document.getElementById('webchat'));

查看 WebChat Repository 以获取有关 v4 的更多示例和信息。

WebChat V3

我们将修改机器人处理发布活动的方式,以拦截和修改来自用户的消息。

var dl = new BotChat.DirectLine({ secret: '<SECRET>' });

BotChat.App({
  botConnection: Object.assign({}, dl, {
    postActivity: activity => {
      // Edit text when user sends message
      activity.text = activity.text.split('').map(_ => '*').join('');
      return dl.postActivity(activity);
    }
  }),
  bot: 'bot',
  user: 'user',
  resize: 'detect',
}, document.getElementById('bot'));

希望对您有所帮助!