ringcentral / ringcentral-chatbot-js

RingCentral Chatbot Framework for JavaScript
MIT License
10 stars 7 forks source link

Need support PersonsAdded event #17

Closed zxdong262 closed 5 years ago

zxdong262 commented 5 years ago
{ type: 'PostAdded',
  message:
   { uuid: '5208092479506162115',
     event: '/restapi/v1.0/glip/posts',
     timestamp: '2019-03-21T01:51:26.682Z',
     subscriptionId: '8f322d09-8af7-48ec-9f8f-2f8bdc9f8aa5',
     ownerId: '257744004',
     body:
      { id: '2923945988',
        groupId: '287195142',
        type: 'PersonsAdded',
        text: null

in bot webhook:

  let text = message.body.text
 // maybe should remove this or set a another event handler
  if (!text) {
    return // not a text message
  }
zxdong262 commented 5 years ago

Not a problem, can be handled!

tylerlong commented 5 years ago

PersonsAdded event is a special case of PostAdded event.

You can take advantages of the catch-all event here: https://github.com/ringcentral/ringcentral-chatbot-js/blob/master/src/apps/bot.js#L44

await handle({ type: body.eventType, message })

And write some code like this:

if(event.type === 'PostAdded' && event.message.body.type === 'PersonsAdded') {
  // ...
}