0

We are using Twilio's javascript SDK to create a programmable chat. I am hooking up to the messageAdded event to play an audio alert. But the messageAdded event gets triggered, both for an inbound message (which is what I want), and for an outbound message as well.

The handler accepts an argument, that represents a message

  1. How can I identify the sender from the message? The closest I find is, message.author which has a value of 'system' for inbound.

  2. What is the difference between messageAdded and messageUpdated event?

Amudh
  • 40
  • 6
  • Are you sure that's not a notification for a user joining / leaving the channel? Those may be system messages. Or maybe however you've configured chat, instead of using the SDK to send a message as a user you are triggering the API to send the message as the system? I don't know if that's even possible. Either way, my messages have an appropriate author on them. – Jake T. May 01 '18 at 20:28
  • By default, I see the value is 'system' for message.author, and yes, we are using the API to trigger the message, because the target user responds to our chat messages, with SMS. – Amudh May 02 '18 at 01:05
  • Can you check that the `message.author` is not equal to the current user? Even if the `message.author` is system in the case of an incoming SMS message, it's not going to be the logged in user that you want to alert. – philnash May 10 '18 at 06:43
  • Yes, I ended up doing something like that. I am playing the audio alert, only if the `message.author` is system which is the case, for all inbound messages. When I, as a logged in user, send a message, the `message.author` is set correctly to my id, and the alert does not play. – Amudh May 11 '18 at 00:56

0 Answers0