Skip to content

Commit

Permalink
chore: added messaging bulk example (#243)
Browse files Browse the repository at this point in the history
* chore: added messaging bulk example

* chore: added messaging bulk example

* chore: added messaging bulk example

* chore: corrected message
  • Loading branch information
tiwarishubham635 authored Apr 4, 2024
1 parent ddc0f26 commit 6c65935
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -301,6 +301,48 @@ func main() {
}
```

### Send Bulk Message <a id="messaging-bulk"></a>

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`
Expand Down

0 comments on commit 6c65935

Please sign in to comment.