From 6c659359175e7b3386daad022389b16f6ea56125 Mon Sep 17 00:00:00 2001 From: Shubham Date: Thu, 4 Apr 2024 17:35:02 +0530 Subject: [PATCH] chore: added messaging bulk example (#243) * chore: added messaging bulk example * chore: added messaging bulk example * chore: added messaging bulk example * chore: corrected message --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 202859df6..d53257109 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ and [twilio-oai](https://github.com/twilio/twilio-oai). If you find an issue wit please go ahead and open an issue or a PR against the relevant repositories. ## 🚀 Feature Update -Twilio Go Helper Library's version 1.20.0 adds support for the application/json content type in the request body. +Twilio Go Helper Library's version 1.20.0 adds support for the application/json content type in the request body. See example [here](#messaging-bulk). Behind the scenes Go Helper is now auto-generated via OpenAPI with this release. This enables us to rapidly add new features and enhance consistency across versions and languages. @@ -301,6 +301,48 @@ func main() { } ``` +### Send Bulk Message + +Try sending a message to multiple recipients with JSON request body support. + +```go +package main + +import ( + "encoding/json" + "fmt" + + "github.com/twilio/twilio-go" + previewMessaging "github.com/twilio/twilio-go/rest/preview_messaging/v1" +) + +func main() { + accountSid := "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + authToken := "f2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + + client := twilio.NewRestClientWithParams(twilio.ClientParams{ + Username: accountSid, + Password: authToken, + }) + + // create multiple recipients + msg1 := previewMessaging.MessagingV1Message{To: "+XXXXXXXXXX"} + msg2 := previewMessaging.MessagingV1Message{To: "+XXXXXXXXXX"} + + // create message request object + req := &previewMessaging.CreateMessagesRequest{Messages: []previewMessaging.MessagingV1Message{msg1, msg2}, Body: "Hello from Go!", From: "+XXXXXXXXXX"} + params := &previewMessaging.CreateMessagesParams{CreateMessagesRequest: req} + + resp, err := client.PreviewMessagingV1.CreateMessages(params) + if err != nil { + fmt.Println("Error sending SMS message: " + err.Error()) + } else { + response, _ := json.Marshal(*resp) + fmt.Println("Response: " + string(response)) + } +} +``` + ### Iterate through records This library also offers paging functionality. Collections such as calls and messages have `ListXxx` and `StreamXxx`