【问题标题】:How to pick up channel data using C#如何使用 C# 获取频道数据
【发布时间】:2021-10-19 00:33:00
【问题描述】:

我正在通过通道数据从网络聊天客户端向 Bot 发送数据,方式如下:

const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
  if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
   // The channelData submitted here is very similar to HTTP cookies and vulnerable to forgery attack.
   // Make sure you use signature to protect it and verify the signature on the bot side.
   // To minimize unexpected behaviors, we recommend to treat the "action" object as if it is immutable.
   // We use simple-update-in package to update "action" with partial deep cloning.
   action = window.simpleUpdateIn(
     action,
     ['payload', 'activity', 'channelData', 'myCustomProperty'],
     () => 'Custom value'
   );
 }

 return next(action);
}); 

https://github.com/microsoft/BotFramework-WebChat/blob/master/samples/04.api/b.piggy-back-on-outgoing-activities/index.html

如何使用 C# 在服务器端访问这些数据?

【问题讨论】:

    标签: c# botframework chatbot


    【解决方案1】:

    您可以在上下文对象下的 channelData 下访问它,下面的完整路径

    dialogContext.Context.Activity.ChannelData

    【讨论】:

      【解决方案2】:

      我来自巴西,我找到了类似问题的解决方案。 我最终的 java 脚本存储对象:

      var cliente = {'xxx': 'xx', 'xx':'xx'} 
            const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
               if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
                 dispatch({
                   type: 'WEB_CHAT/SEND_EVENT',
                   payload: {
                     name: 'webchat/join',
                     value: cliente
                   }
                 });
               }
               return next(action);
             });
      

      还有我的 C# 代码:

      public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
              {
                  await base.OnTurnAsync(turnContext, cancellationToken);
                  if (turnContext.Activity.Name == "webchat/join")
                  {
                      await turnContext.SendActivityAsync(turnContext.Activity.Value?.ToString());
                  }
                  // Save any state changes that might have occurred during the turn.
                  await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
                  await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
              }
      

      【讨论】:

        猜你喜欢
        • 2022-07-16
        • 1970-01-01
        • 2014-05-21
        • 2021-07-11
        • 2016-09-08
        • 2019-12-14
        • 2012-10-05
        • 2014-08-05
        • 2017-07-25
        相关资源
        最近更新 更多