Skip to main content

Relay.Messaging

Relay.Messaging​

This represents the API interface for the Messaging Relay Service. This object is used to make requests related to managing SMS and MMS messages.

Methods​

Send​

Send a message to the destination number.

Parameters

ParameterTypeRequiredDescription
ContextstringrequiredThe context to receive inbound events.
FromstringrequiredThe phone number to place the message from. Must be a SignalWire phone number or short code that you own.
TostringrequiredThe phone number to send to.
BodystringrequiredThe content of the message. Optional if media is present.
Media[]stringrequiredArray of URLs to send in the message. Optional if body is present.
Tags[]stringoptionalArray of strings to tag the message with for searching in the UI.

Returns

SendResult

Examples

Send a message in the context office.

text := "Hello from Signalwire !"
context := "office"
from := "+1XXXXXXXXXX"
to := "+15XXXXXXXXX"

message := consumer.Client.Messaging.NewMessage(context, from, to, text)
message.OnMessageQueued = func(_ *signalwire.SendResult) {
Signalwire.Log.Info("Message Queued.\n")
}

message.OnMessageDelivered = func(_ *signalwire.SendResult) {
signalwire.Log.Info("Message Delivered.\n")
}

resultSend := consumer.Client.Messaging.SendMsg(message)
if !resultSend.GetSuccessful() {
signalwire.Log.Error("Could not send message\n")
}