Broadcast
Trigger broadcast notifications to list of subscribers in single call
Payload Schema
package main
import (
"context"
"log"
suprsend "github.com/suprsend/suprsend-go"
)
func main() {
// Initialize SDK
opts := []suprsend.ClientOption{
// suprsend.WithDebug(true),
}
suprClient, err := suprsend.NewClient("__api_key__", "__api_secret__", opts...)
if err != nil {
log.Println(err)
}
ctx := context.Background()
// ================= broadcast to a list
broadcastIns := &suprsend.SubscriberListBroadcast{
Body: map[string]interface{}{
"list_id": "users-with-prepaid-vouchers-1",
"template": "template slug",
"notification_category": "category",
// broadcast channels.
// if empty: broadcast will be tried on all available channels
// if present: broadcast will be tried on passed channels only
"channels": []string{"email"},
"delay": "1m", // check docs for delay format
// "trigger_at": "", // check below for trigger_at format
"data": map[string]interface{}{
"first_name": "User",
"spend_amount": "$10",
"nested_key_example": map[string]interface{}{
"nested_key1": "some_value_1",
"nested_key2": map[string]interface{}{
"nested_key3": "some_value_3",
},
},
},
},
IdempotencyKey: "",
TenantId: "",
}
res, err := suprClient.SubscriberLists.Broadcast(ctx, broadcastIns)
if err != nil {
log.Fatalln(err)
}
log.Println(res)
}
Parameter | Format | Description |
---|---|---|
list_id | string | list of users that you want to send broadcast messages. |
template | string | It is the template slug which can be found in Templates tab in SuprSend dashboard. |
notification_category | system / transactional / promotional | You can understand more about them in the Notification Category. |
channels (Optional) | string[] | User channels on which the broadcast messages to be sent. If not provided, it will trigger notifications on all available channels in user profile. Available channels: androidpush / iospush / inbox / email / whatsapp / sms Example:["sms", "inbox"] |
delay (Optional) | XXdXXhXXmXXs or Number (in seconds) | Broadcast will be halted for the time mentioned in delay, and become active once the delay period is over. Example: 1d2h3m4s / 60 |
trigger_at (Optional) | date string in ISO 8601 | Trigger broadcast on a specific date-time. Example: "2021-08-27T20:14:51.643Z" |
data (Optional) | object | variable data defined in templates |
Add file attachment (for email)
To add one or more attachments to a notification (viz. Email), call add_attachment()
on broadcast instance for each attachment file. Ensure that attachment url is valid and public, otherwise error will be raised. Since broadcast instance size can't be > 100 KB, local file paths can't be passed in event attachment.
// If need to add attachment
err = broadcastIns.AddAttachment("https://attachment-url", &suprsend.AttachmentOption{IgnoreIfError: true})
if err != nil {
log.Fatalln(err)
}
A single broadcast instance size (including attachment) must not exceed 100KB (100 x 1024 bytes).
Updated 4 months ago