Skip to content

Commit

Permalink
Supporting WA carousel templates
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhnewatiya-plivo committed Jun 20, 2024
1 parent 137f458 commit b17745f
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Change Log

## [7.50.0](https://github.com/plivo/plivo-go/tree/v7.50.0) (2024-06-20)
**Feature - Carousel Template Support**
- Added support for WhatsApp cards in carousel templates

## [7.49.2](https://github.com/plivo/plivo-go/tree/v7.49.2) (2024-06-07)
**Bug Fix - List and Get Media object url fix**
- Fixed the media_url response value
Expand Down
162 changes: 162 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,168 @@ func main() {
}
```


#### Carousel Template Messages
Example:
```go
package main

import (
"fmt"
"github.com/plivo/plivo-go/v7"
)

func main() {
client, err := plivo.NewClient("<auth-id>", "<auth-token>", &plivo.ClientOptions{})
if err != nil {
fmt.Println("Error:", err)
return
}

// Create a WhatsApp template
template, err := plivo.CreateWhatsappTemplate(`{
"name": "sample_carousel_template",
"language": "en_US",
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "BUBBLE_TEXT_VARIABLE"
},
{
"type": "text",
"text": "BUBBLE_TEXT_VARIABLE"
}
]
},
{
"type": "carousel",
"cards": [
{
"card_index": 0,
"components": [
{
"type": "header",
"parameters": [
{
"type": "media",
"media": "https://xyz.com/sample.png"
}
]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "BUBBLE_TEXT_VARIABLE_1"
},
{
"type": "text",
"text": "CARD_BODY_VARIABLE_1"
}
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": 0,
"parameters": [
{
"type": "payload",
"payload": "QUICK_REPLY_BUTTON_PAYLOAD_1"
}
]
},
{
"type": "button",
"sub_type": "url",
"index": 1,
"parameters": [
{
"type": "text",
"text": "pricing"
}
]
}
]
},
{
"card_index": 1,
"components": [
{
"type": "header",
"parameters": [
{
"type": "media",
"media": "https://xyz.com/sample.png"
}
]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "CARD_BODY_VARIABLE_2"
},
{
"type": "text",
"text": "CARD_BODY_VARIABLE_2"
}
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": 0,
"parameters": [
{
"type": "payload",
"payload": "QUICK_REPLY_BUTTON_PAYLOAD_2"
}
]
},
{
"type": "button",
"sub_type": "url",
"index": 1,
"parameters": [
{
"type": "text",
"text": "docs"
}
]
}
]
}
]
}
]
}`)
if err != nil {
fmt.Println("Error creating template:", err)
return
}

// Send a templated message
response, err := client.Messages.Create(plivo.MessageCreateParams{
Src: "source_number",
Dst: "destination_number",
Type: "whatsapp",
Template: &template,
})
if err != nil {
fmt.Println("Error sending message:", err)
return
}

fmt.Printf("Response: %#v\n", response)
}
```

### Free Form Messages
Non-templated or Free Form WhatsApp messages can be sent as a reply to a user-initiated conversation (Service conversation) or if there is an existing ongoing conversation created previously by sending a templated WhatsApp message.

Expand Down
2 changes: 1 addition & 1 deletion baseclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/google/go-querystring/query"
)

const sdkVersion = "7.49.2"
const sdkVersion = "7.50.0"

const lookupBaseUrl = "lookup.plivo.com"

Expand Down
6 changes: 6 additions & 0 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ type Component struct {
SubType string `mapstructure:"sub_type" json:"sub_type,omitempty"`
Index string `mapstructure:"index" json:"index,omitempty"`
Parameters []Parameter `mapstructure:"parameters" json:"parameters"`
Cards []Card `mapstructure:"cards" json:"cards,omitempty"`
}

type Card struct {
CardIndex int `mapstructure:"card_index" json:"card_index,omitempty"`
Components []Component `mapstructure:"components" json:"components,omitempty"`
}

type Parameter struct {
Expand Down

0 comments on commit b17745f

Please sign in to comment.