简体   繁体   English

当到达对话流程中的步骤时,自动从聊天机器人视图移动到离子移动应用程序页面

[英]Shifting from chatbot view to ionic mobile app page automatically when reaching a step in dialogue flow

I am using MS chatbot-framework V3 and embedding it in my ionic 3 mobile app via Direct line . 我正在使用MS chatbot-framework V3并通过Direct line将其嵌入到我的离子3移动应用程序中。

What I am aiming to is when reaching the end of conversation, the chatbot is terminated and shifting to another page in the mobile app with passing some values from chatbot to that page. 我的目标是,当谈话结束时,聊天机器人终止并转移到移动应用程序中的另一个页面,并将一些值从chatbot传递到该页面。

When you reach the end of your conversation, you can send an event activity to your DirectLine Client with channel data from the conversation, and once the client receives the event, you can transition to the next view in your app with the channel data. 当您到达对话结束时,您可以使用对话中的频道数据向DirectLine客户端发送活动活动,一旦客户收到活动,您就可以使用频道数据转换到应用中的下一个视图。 See the code snippets below. 请参阅下面的代码段。

Sending Transition Event 发送过渡事件

In the bot, we are going to send back channel events to DirectLine with the data we have gathered in the chat. 在机器人中,我们将使用我们在聊天中收集的数据将频道事件发送回DirectLine。 Basically, you just need to send an activity with the type property set to 'event' and the name attribute set to some string value - we are going to use 'transition' in this case. 基本上,您只需要发送一个活动,其type属性设置为'event',name属性设置为某个字符串值 - 在这种情况下我们将使用'transition'。 The conversation data is going to be encapsulated in the activity's channel data. 会话数据将封装在活动的频道数据中。

// End of conversation 

var reply = turnContext.Activity.CreateReply();

reply.Name = "transition";
reply.Type = "event";
reply.ChannelData = JObject.FromObject( new {
    user = new {
        name = "TJ",
        location = "Seattle"
    }
});

await turnContext.SendActivityAsync(reply, cancellationToken: cancellationToken);

Listen for Transition Event 听取过渡事件

On the client side, we are going to filter the incoming activities to listen for our 'transition' event from the bot. 在客户端,我们将过滤传入的活动,以便从机器人中侦听我们的“过渡”事件。 When it's received, you can transition to the next view and pass along the channel data which contains the conversation data. 收到后,您可以转换到下一个视图并传递包含会话数据的频道数据。

import { DirectLine } from 'botframework-directlinejs';

var directLine = new DirectLine({
    secret: "<DIRECTLINE_SECRET"
});

directLine.activity$
  .filter(activity => activity.type === 'event' && activity.name === 'transition')
  .subscribe( activity => { /* Initiate transition to next view with activity.channelData */ });

Hope this helps! 希望这可以帮助!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM