Utiliser plus d'événements avec le Client SDK

Product deprecation notice

Effective April 30th, 2026, Vonage In-App Messaging will no longer be available. Access for new users will be closed, and the service will be discontinued for all existing users.

If you have any questions regarding this product’s discontinuation, please contact your account manager or our support team.

Dans ce guide, nous aborderons l'ajout d'autres événements de conversation ; nous traiterons de plusieurs types d'événements, ceux qui proviennent de la conversation et ceux que nous envoyons à la conversation.

Concepts

Ce guide vous présentera les concepts suivants.

  • Événements de conversation - member:left et text: les événements qui se déclenchent dans une conversation lorsque quelqu'un effectue une action
  • Actions de conversation - les actions qui déclenchent des événements sur une conversation
  • Histoire de la conversation - un events objet qui stocke tous les événements textuels se produisant dans une conversation

NOTE: A step-by-step tutorial to build a chat application is available here.

The getEvents method retrieves all the events that occurred in the context of the conversation. It returns a subset or "page" of events with each invocation - the number of events it returns is based on the page_size parameter (the default is 10 results, the maximum is 100).

Note: See the documentation for helper methods you can use to work with this paginated data.

conversation
  .getEvents({ page_size: 20 })
  .then((events_page) => {
    events_page.items.forEach((value, key) => {
      if (conversation.members.get(value.from)) {
        const date = new Date(Date.parse(value.timestamp))
        
        switch (value.type) {

          case 'member:joined':
            console.log(`${conversation.members.get(value.from).user.name} @ ${date}: joined the conversation`);
            break;
          case 'member:left':
            console.log(`${conversation.members.get(value.from).user.name} @ ${date}: left the conversation`);
            break;
          case 'member:invited':
            console.log(`${conversation.members.get(value.from).user.name} @ ${date}: invited to the conversation`);
            break;

          case 'text:seen':
            console.log(`${conversation.members.get(value.from).user.name} saw text at @ ${date} : ${value.body.text}`))
            break;
          case 'text:delivered':
            console.log(`Text from ${conversation.members.get(value.from).user.name} delivered at @ ${date} : ${value.body.text}`))
            break;
          case 'text':
            console.log(`${conversation.members.get(value.from).user.name} @ ${date}: ${value.body.text}`);
            break;

          case 'text:typing:on':
            console.log(`${conversation.members.get(value.from).user.name} starting typing @ ${date}`);
            break;
          case 'text:typing:off':
            console.log(`${conversation.members.get(value.from).user.name} stopped typing @ ${date}`);
            break;

          default:
            console.log(`${conversation.members.get(value.from).user.name} @ ${date}: unknown event`);
        }
      }
    })

  })
  .catch(this.errorLogger)

Référence