How to handle user leaving conversation

自作多情 提交于 2020-02-26 03:59:08

问题


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.

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


回答1:


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.

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:

  • 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, 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'
}

Hope of help!



来源:https://stackoverflow.com/questions/59472204/how-to-handle-user-leaving-conversation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!