首页 > 解决方案 > 如何使用钩子向消息的 channelData 添加值

问题描述

我正在使用Customization Plain UI 示例,需要将自定义数据添加到 channelData。使用此示例时,实现此目的的最佳方法是什么?

标签: botframeworkweb-chat

解决方案


您可以将存储中间件添加到自定义纯 UI示例,该示例通过将自定义存储作为道具传递给Composer组件来添加自定义通道数据。有关更多详细信息,请查看Piggyback Data Web Chat Sample。

export default () => {
  ...

  const store = useMemo(() => createStore({}, () => next => action => {
    if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
      action = simpleUpdateIn(
        action,
        ['payload', 'activity', 'channelData', 'email'],
        () => 'johndoe@example.com'
      );
    }
     return next(action);
  }), []);

  ...

  return (
    <React.Fragment>

      ...

      {!!directLine && (
        <Components.Composer directLine={directLine} store={store}>
          <PlainWebChat />
        </Components.Composer>
      )}
    </React.Fragment>
  );
};

推荐阅读