简体   繁体   English

MS BOT 框架(自适应卡):如何从直线发送值(Stepcontext.Value)

[英]MS BOT Framework (adaptive cards): How to send value (Stepcontext.Value) from directline

I have deployed a Bot in Azure, the Bot displays a welcome message OnMemberAdd.我在 Azure 中部署了一个 Bot,Bot 显示欢迎消息 OnMemberAdd。 Its adaptive card so the entered value are sent to stepcontext.value.它的自适应卡因此输入的值被发送到 stepcontext.value。 I have integrated it with multiple channels, for directline, I would like to bypass the welcome card and pass the message directly to stepcontext.value so the second prompt is displayed instead of first.我已经将它与多个渠道集成,对于直达线,我想绕过欢迎卡并将消息直接传递给 stepcontext.value 以便显示第二个提示而不是第一个提示。 I have tried the below but it does not work, please help.我已经尝试了以下方法,但它不起作用,请帮助。

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <title>Web Chat: Send welcome event</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <style>
      html,
      body {
        height: 100%;
      }
      body {
        margin: 0;
      }

      #webchat {
        height: 100%;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div id="webchat"></div>
    <script>
      (async function() {
        // In this demo, we are using Direct Line token from MockBot.
        // Your client code must provide either a secret or a token to talk to your bot.
        // Tokens are more secure. To learn about the differences between secrets and tokens
        // and to understand the risks associated with using secrets, visit https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication?view=azure-bot-service-4.0

        const { token } = { token};

        // We are using a customized store to add hooks to connect event
        const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
 if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
   dispatch({
     type: 'WEB_CHAT/SEND_EVENT',
     payload: { 
                name: 'userInfo',
       value: { fname:'user', lname:'test', pnumber:'0678775453'} 
                }
   });
 }

 return next(action);
        });

        const styleOptions = {
 botAvatarImage:
   '',
 botAvatarInitials: 'Chatbot',
 userAvatarImage: '',
 userAvatarInitials: 'User',
 showNub: true,
 bubbleFromUserNubOffset: 'bottom',
 bubbleFromUserNubSize: 10,
 bubbleFromUserBorderColor: '#0077CC',
 bubbleNubOffset: 'top',
 bubbleNubSize: 0,
 bubbleBorderColor: '#009900',
 sendBoxButtonColor: '#009900',
 hideUploadButton: true,
 hideSendBox : true
        };
        window.WebChat.renderWebChat(
 {
   directLine: window.WebChat.createDirectLine({ token }),
   store,
            styleOptions
 },
 document.getElementById('webchat')
        );

        document.querySelector('#webchat > *').focus();
      })().catch(err => console.error(err));
    </script>
  </body>
</html>

I have tried to send the data via postman and it works well but when I do it using above code it does not work.我试图通过 postman 发送数据,它运行良好,但是当我使用上面的代码执行它时它不起作用。

Postman body Postman体

{
    "type": "message",
    "from": {
        "id": "user1"
    },
    "value": 
    {
        "fname":"user",
        "lname":"test",
        "pnumber":"0678787543"
    }
}

You're so close: You have two options:你是如此接近:你有两个选择:

  1. Change to WEB_CHAT/SEND_EVENT and include the name property:更改为WEB_CHAT/SEND_EVENT并包含name属性:
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
          if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
            dispatch({
              type: 'WEB_CHAT/SEND_EVENT',
              payload: {
                name: 'userInfo',
                value: { fname:'user', lname:'test', pnumber:'0678775453'}
              }
            });
          }

          return next(action);
        });
  1. Use WEB_CHAT/SEND_MESSAGE , include the text property, and change to channelData :使用WEB_CHAT/SEND_MESSAGE ,包括text属性,并更改为channelData
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
          if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
            dispatch({
              type: 'WEB_CHAT/SEND_MESSAGE',
              payload: {
                text: 'userInfo',
                channelData: { fname:'user', lname:'test', pnumber:'0678775453'}
              }
            });
          }

          return next(action);
        });

=== ===

Update更新

I can see it coming through just fine using your code.我可以看到它使用您的代码很好。 Put a breakpoint in onTurn / OnTurnAsync and you'll see that when a user connects you get:onTurn / OnTurnAsync中放置一个断点,您会看到当用户连接时,您会得到:

  1. conversationUpdate for the bot机器人的对话更新
  2. conversationUpdate for the user用户的对话更新
  3. WebChat's Event with the user data you want:带有您想要的用户数据的 WebChat 事件:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Axios 直接向机器人框架发送帖子 - 错误 - send a post to bot framework directline with Axios - ERROR 如何以编程方式清除聊天窗口中输入字段(发送框)的内容 | MS Bot 框架 | 直线机器人 - How to programmatically clear the content of the input field (sendbox) in the chat window | MS Bot framework | Directline bot 如何:使用WebSocket的MS Bot直线消息传递 - How to: MS Bot directline messaging using a websocket 使用Microsoft Bot Framework动态创建具有不同内容的自适应卡 - Dynamically create adaptive cards with different content using Microsoft Bot Framework 如何在 C# 中使用 Microsoft Bot Framework SDK V4 开发的 ChatBot 中添加条件 w.r.t 自适应卡片? - How to add conditions w.r.t Adaptive cards in ChatBot developed using Microsoft Bot Framework SDK V4 in C#? 如何在不每次在 Microsoft Bot Framework Direct Line JS Client (REACTJS) 中创建直线对象的情况下从服务器获得响应 - How can I get response from the server without creating directline object everytime in Microsoft Bot Framework Direct Line JS Client (REACTJS) 如何将Microsoft Bot中的值发送到Javascript? - How do I send a value from a Microsoft Bot to Javascript? 如何从Microsoft Bot Framework发送SMS(使用Twilio通道)? - How to send SMS (using Twilio channel) from Microsoft Bot Framework? 从网络聊天窗口触发事件或消息到机器人(MS机器人框架) - Trigger event or message from webchat window to bot(MS bot framework) 如何通过directline botconnector发送用户信息 - How to send user information through directline botconnector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM