本文介绍了如何处理用户离开对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些使用OnMember GibraltarAsync方法的示例,但没有示例显示如何处理用户离开会话.我尝试重写OnMembersRemovedAsync,但似乎并未调用它(至少在使用bot框架仿真器时).

We have welcome examples using OnMembersAddedAsync method but no examples showing how to handle user leaving conversation. I tried to override OnMembersRemovedAsync but it does not seem to be invoked (at least when I use bot framework emulator).

我需要在用户离开/离开对话时进行一些清理.一个例子或任何技巧将不胜感激.

I need to do some cleanup at the event of user leaving/left conversation.An example or any tips would be appreciated.

更新:我正在使用C#和Bot框架v4

Update: I'm using C# and Bot framework v4

推荐答案

这将是特定于通道的,因为它依赖于提供在用户离开对话时发送更新的功能的通道.任何其他渠道,您都需要研究.

This is going to be channel specific as it is dependent on the channel providing a feature that sends an update when the user leaves a conversation. Any other channels, you will need to research.

对于Facebook,我无法找到涵盖此类操作的范围.这些是可用范围,您可以在此处:

For Facebook, I was unable to find a scope that covers such an action. These are the available scopes which you can reference more closely here:

  • 消息
  • message_deliveries
  • message_echoes
  • message_reads
  • messaging_account_linking
  • messaging_checkout_updates(测试版)
  • messaging_game_plays
  • messaging_handovers
  • messaging_optins
  • messaging_payments(beta)
  • messaging_policy_enforcement
  • messaging_postbacks
  • messaging_pre_checkouts(测试版)
  • messaging_referrals
  • 待机
  • messages
  • message_deliveries
  • message_echoes
  • message_reads
  • messaging_account_linking
  • messaging_checkout_updates (beta)
  • messaging_game_plays
  • messaging_handovers
  • messaging_optins
  • messaging_payments(beta)
  • messaging_policy_enforcement
  • messaging_postbacks
  • messaging_pre_checkouts (beta)
  • messaging_referrals
  • standby

Web Chat作为一项功能,也不包括此功能.但是,由于这是一个网页,因此可以利用onbeforeunload()窗口函数来调度事件.事件侦听器将利用Web Chat的存储将消息或事件分发给机器人.为了清楚起见,我通过SEND_MESSAGESEND_EVENT发送不同类型的数据.

Web Chat, as a feature, also does not include this. However, given this is a web page, you can utilize the onbeforeunload() window function to dispatch an event. The event listener will make use of Web Chat's store to dispatch either a message or event to the bot. For the sake of clarity, I'm sending different types of data via SEND_MESSAGE and SEND_EVENT.

const store = window.WebChat.createStore( {}, ( { dispatch } ) => next => async action => {
  return next( action );
};

window.addEventListener( 'sendEventActivity', ( { data } ) => {
  store.dispatch({
    type: 'WEB_CHAT/SEND_MESSAGE',
    payload: {
      text: data
    }
  } )
  ,
  store.dispatch( {
    type: 'WEB_CHAT/SEND_EVENT',
    payload: {
      name: 'user_event',
      value: {
        name: 'end_conversation',
        value: 'user ended conversation'
      },
      text: 'The user has left the conversation.'
    }
  } )
} );

window.onbeforeunload = function() {
  const eventSendActivity = new Event( 'sendEventActivity' );
  eventSendActivity.data = 'User left conversation';
  window.dispatchEvent( eventSendActivity );
}
{ type: 'message',
  id: '4uPdpZhlTFfBMziBE7EmEI-f|0000004',
  timestamp: 2020-01-10T18:21:26.767Z,
  serviceUrl: 'https://directline.botframework.com/',
  channelId: 'directline',
  from: { id: 'dl_123', name: 'johndoe', role: 'user' },
  conversation: { id: '4uPdpZhlTFfBMziBE7EmEI-f' },
  recipient: { id: 'botberg@QaeuoeEamLg', name: 'Dungeon Runner' },
  textFormat: 'plain',
  locale: 'en-US',
  text: 'User left conversation',
  channelData:
  { clientActivityID: '15786804807910gegwkp2kai',
    clientTimestamp: '2020-01-10T18:21:20.792Z' }
}

{ type: 'event',
  id: '4uPdpZhlTFfBMziBE7EmEI-f|0000005',
  timestamp: 2020-01-10T18:21:26.780Z,
  serviceUrl: 'https://directline.botframework.com/',
  channelId: 'directline',
  from: { id: 'dl_123', name: 'johndoe', role: 'user' },
  conversation: { id: '4uPdpZhlTFfBMziBE7EmEI-f' },
  recipient: { id: 'botberg@QaeuoeEamLg', name: 'Dungeon Runner' },
  locale: 'en-US',
  channelData:
  { clientActivityID: '1578680480821h7kgfm9cyz',
    clientTimestamp: '2020-01-10T18:21:20.821Z' },
  value:
  { name: 'end_conversation', value: 'user ended conversation' },
  name: 'user_event'
}

希望有帮助!

这篇关于如何处理用户离开对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 10:33