Send messages

Send SMS and WhatsApp messages, follow them, and cancel ones that haven't gone.

client.Messages sends messages, each to its own person, and reads them back. For the fields of a message, see Send messages.

Send one message

msg, err := client.Messages.SendOne(ctx, goomzo.MessageInput{
	To:      "+255712345678",
	Channel: goomzo.SMS,
	Content: &goomzo.Content{Text: "Amina, order #1042 is ready."},
})

SendOne returns the message, its Status sending, or scheduled with a SendAt.

Send up to 100

msgs, err := client.Messages.Send(ctx, []goomzo.MessageInput{
	{To: "+255712345678", Channel: goomzo.SMS, Content: &goomzo.Content{Text: "Amina, order #1042 is ready."}},
	{CustomerID: "cus_4hq2v9n1c8x0t6pk", Channel: goomzo.WhatsApp, Content: &goomzo.Content{Text: "Juma, order #1043 is ready."}},
})

They're queued all or none. If one isn't valid, none is sent, and the error names it, such as messages[1].to.

Send to many people

A broadcast sends one message to segments, numbers or every customer:

_, err := client.Broadcasts.Create(ctx, goomzo.BroadcastInput{
	Name:     "Black Friday",
	Channel:  goomzo.SMS,
	Content:  &goomzo.Content{Text: "Hi {{name|there}}, 20% off everything today."},
	Audience: goomzo.AudienceInput{Segments: []goomzo.SegmentRef{{Name: "VIP"}}},
})

See Broadcasts.

Read messages

msg, err := client.Messages.Get(ctx, "msg_7c1x9v2b4n6m8q0w")

for msg, err := range client.Messages.List(ctx, goomzo.MessageListParams{Status: goomzo.MessageFailed}) {
	if err != nil {
		return err
	}
	fmt.Println(msg.To.Phone, *msg.Error)
}

Other methods

MethodDoes
Messages.Cancel(ctx, id)Cancels a message that hasn't gone.
Messages.Senders(ctx)Lists the SMS sender IDs you can send from.
Messages.Media(ctx, receivedID)Gets a file a customer sent on WhatsApp.
Broadcasts.Get(ctx, id)Gets a broadcast, with how its messages are doing.
Broadcasts.List(ctx, params)Lists broadcasts.
Broadcasts.Cancel(ctx, id)Cancels a broadcast that hasn't gone.

Note: Follow a message's status with webhooks, not by asking again and again.

Next steps

Last updated