window.WebChat.render WebChat 可以使用哪个参数来提供自定义 URL 参数?使用 Azure Bot Frameworks Nodejs

Which parameter we can use for window.WebChat.render WebChat so that provide custom URL parameters? using Azure Bot Frameworks Nodejs

将自定义参数从网络聊天控件传递到机器人框架 哪个与 bot URL 有关,我们想要 fetch/render? 即更详细的例子 场景:

window.WebChat.renderWebChat({
        directLine: window.WebChat.createDirectLine({
            token: token,
            ....
            ...
            customUrl : "mybot.net?q1=abc&&q2=xyz
        }),
        styleSet: styleSet,
        store: store
    }, document.getElementById('webchat'));
    document.querySelector('#webchat > *').focus();

是否可以将不同的 url 参数与令牌一起传递,即让机器人根据参数呈现特定功能,即 q2=xyz 体育相关问题卡。

不,创建 Direct Line 对象时无法发送特定参数。 Direct Line 参数是该服务专有的 - 无法检索您发送的任何自定义值。

但是,在网络聊天客户端/用户和机器人之间发送数据的公认方法是使用网络聊天 storedispatch() 功能。 store 广播各种 actions,例如 DIRECT_LINE/CONNECT_FULFILLEDDIRECT_LINE/INCOMING_ACTIVITY(以及其他),允许您在触发时执行功能。

在您的情况下(不知道全部细节),您可能希望在网络聊天加载后将值作为事件发送。代码看起来像这样:

<script>
  (async function () {
    const store = window.WebChat.createStore( {}, ( { dispatch } ) => next => async action => {
      if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
        console.log('Event dispatched');
        dispatch( {
          type: 'WEB_CHAT/SEND_EVENT',
          payload: {
            name: 'CUSTOM_PARAMETERS',
            value: { q1: 'abc', q2: 'xyz' }
          }
        } )
      }

      return next(action);
    });

    [...]

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

在您的机器人中,您将利用 onEvent() activity 处理程序来捕获已调度的事件:

this.onEvent = async (context, next) => {
  console.log('Event activity detected');

  const { activity } = context;

  if (activity && activity.name === 'CUSTOM_PARAMETERS') {
    await context.sendActivity('Custom parameters received!');
  }

  await next();
};

如果您的机器人后端在 C# 上,您将在 OnEventActivityAsync 方法上收到自定义参数

protected override async Task OnEventActivityAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken)
{
     if(turnContext.Activity.Name == "CUSTOM_PARAMETERS")
       {
          await turnContext.SendActivityAsync($" Your custom parameters are: {turnContext.Activity.Value}", cancellationToken: cancellationToken);
       }
}

有多种 samples 您可以参考详细说明如何实现不同的功能,包括如何在网络聊天中发送、接收和处理特定数据点。

希望得到帮助!