Broadcast messages
Update time: 2024/03/07 11:13:59
The SDK can receive broadcast messages. Broadcast messages are suitable for business scenarios where all users are notified, such as sending internal announcements within an organization to all employees.
How it works
The broadcast message is sent by the server API (msg.broadcastMsg.action
), and the SDK receives the broadcast message and sends it to the upper layer of the app. All users of the app can receive a broadcast message. The MessageService
interface provides methods to monitor sending broadcast messages.
Broadcast messages can be stored as offline messages. If a broadcast message is sent for offline messages, the message has a validity period (7 days by default. You can specify a custom duration). If a user logs in with a different device, or uninstalls and reinstalls the app on the same device, the user can receive broadcast messages within the validity period.
Prerequisites
- You must activate broadcast messages separately. Before building related features, make sure you have contact the sales manager and activated the service. You can contact the sales manager using the Whatsapp on the CommsEasewebsite.
- SDK is initialized.
- You have created IM accounts.
Limits
- The SDK cannot send broadcast messages. You can send broadcast messages by calling the server API (
msg.broadcastMsg.action
). The API can be called up to 10 times per minute, and up to 1000 times in a day. If the number of calls exceeds the limit, a 416 error code will be returned. - To increase the limit, contact the sales manager over the Whatsapp on the CommsEase website. - Users who are not logged in to IM server, for example, users who only join a chat room in independent mode, cannot receive broadcast messages.
- The latest 100 offline broadcast messages can be stored;
- Broadcast messages cannot be delivered using the push service, or as roaming messages, and in sessions. The SDK cannot store broadcast messages in message history.
- Broadcast messages cannot be stored on the client.
Workflow
-
The recipient registers the
onBroadcastMessage
event stream to track broadcast messagesNIMBroadcastMessage
from the server.NIMBroadcastMessage
representation
Attribute Type Description id
int Broadcast messages ID fromAccount
String Account that sends a broadcast message time
int Timestamp of a broadcast message. content
String Content of a broadcast message - Example
dart
NimCore.instance.messageService.onBroadcastMessage.listen((event) { print('Test_Observer onBroadcastMessage ${event.toString()}'); });
-
A sender calls
msg.broadcastMsg.action
to send a broadcast message. -
The
Stream
event stream triggers the callback, and the recipient receives the broadcast message returned by this callback.
API reference
API |
Description |
---|---|
onBroadcastMessage |
Register or unregister the observer for receiving broadcast messages. |
msg.broadcastMsg.action |
Send a broadcast message using the corresponding server API. |