Proactive Messaging
In Sending Messages, you were shown how to respond to an event when it happens. However, there are times when you want to send a message to the user without them sending a message first. This is called proactive messaging. You can do this by using the send
method in the app
instance. This approach is useful for sending notifications or reminders to the user.
The main thing to note is that you need to have the conversationId
of the chat or channel that you want to send the message to. It's a good idea to store this value somewhere from an activity handler so that you can use it for proactive messaging later.
Then, when you want to send a proactive message, you can retrieve the conversationId
from storage and use it to send the message.
In this example, you see how to get the conversation id using one of the activity handlers. This is a good place to store the conversation id, but you can also do this in other places like when the user installs the app or when they sign in. The important thing is that you have the conversation id stored somewhere so you can use it later.