Skip to content

Commit

Permalink
Adding support for interactive whatsapp messages (#203)
Browse files Browse the repository at this point in the history
* Adding support for interactive whatsapp messages
  • Loading branch information
saurabhnewatiya-plivo authored May 7, 2024
1 parent bd9691b commit b0a193b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [7.48.0](https://github.com/plivo/plivo-go/tree/v7.48.0) (2024-05-07)
**Feature - Adding support for interactive whatsapp messages**
- Added new param 'interactive' to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support interactive 'whatsapp' messages

## [7.47.0](https://github.com/plivo/plivo-go/tree/v7.47.0) (2024-05-02)
**Feature - Added SubAccount and GeoMatch for Create Masking Session API of Number Masking.**
- Added sub_account and geo_match support in MaskingSession APIs
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.47.0"
const sdkVersion = "7.48.0"

const lookupBaseUrl = "lookup.plivo.com"

Expand Down
57 changes: 51 additions & 6 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ type MessageCreateParams struct {
MediaUrls []string `json:"media_urls,omitempty" url:"media_urls,omitempty"`
MediaIds []string `json:"media_ids,omitempty" url:"media_ids,omitempty"`
// Either one of src and powerpackuuid should be given
PowerpackUUID string `json:"powerpack_uuid,omitempty" url:"powerpack_uuid,omitempty"`
MessageExpiry int `json:"message_expiry,omitempty" url:"message_expiry,omitempty"`
Template *Template `json:"template,omitempty" url:"template,omitempty"`
DLTEntityID string `json:"dlt_entity_id,omitempty" url:"dlt_entity_id,omitempty"`
DLTTemplateID string `json:"dlt_template_id,omitempty" url:"dlt_template_id,omitempty"`
DLTTemplateCategory string `json:"dlt_template_category,omitempty" url:"dlt_template_category,omitempty"`
PowerpackUUID string `json:"powerpack_uuid,omitempty" url:"powerpack_uuid,omitempty"`
MessageExpiry int `json:"message_expiry,omitempty" url:"message_expiry,omitempty"`
Template *Template `json:"template,omitempty" url:"template,omitempty"`
Interactive *Interactive `json:"interactive,omitempty" url:"interactive,omitempty"`
DLTEntityID string `json:"dlt_entity_id,omitempty" url:"dlt_entity_id,omitempty"`
DLTTemplateID string `json:"dlt_template_id,omitempty" url:"dlt_template_id,omitempty"`
DLTTemplateCategory string `json:"dlt_template_category,omitempty" url:"dlt_template_category,omitempty"`
}

type Message struct {
Expand Down Expand Up @@ -151,6 +152,50 @@ type DateTime struct {
FallbackValue string `mapstructure:"fallback_value" json:"fallback_value" validate:"required"`
}

type Interactive struct {
Type string `mapstructure:"type" json:"type,omitempty"`
Header *Header `mapstructure:"header" json:"header,omitempty"`
Body *Body `mapstructure:"body" json:"body,omitempty"`
Footer *Footer `mapstructure:"footer" json:"footer,omitempty"`
Action *Action `mapstructure:"action" json:"action,omitempty"`
}

type Header struct {
Type string `mapstructure:"type" json:"type,omitempty"`
Text *string `mapstructure:"text" json:"text,omitempty"`
Media *string `mapstructure:"media" json:"media,omitempty"`
}

type Body struct {
Text string `mapstructure:"text" json:"text,omitempty"`
}

type Footer struct {
Text string `mapstructure:"text" json:"text,omitempty"`
}

type Action struct {
Button []*Buttons `mapstructure:"buttons" json:"buttons,omitempty"`
Section []*Section `mapstructure:"sections" json:"sections,omitempty"`
}

type Buttons struct {
ID string `mapstructure:"id" json:"id,omitempty"`
Title string `mapstructure:"title" json:"title,omitempty"`
CTAURL string `mapstructure:"cta_url" json:"cta_url,omitempty"`
}

type Section struct {
Title string `mapstructure:"title" json:"title,omitempty"`
Row []*Row `mapstructure:"rows" json:"rows,omitempty"`
}

type Row struct {
ID string `mapstructure:"id" json:"id,omitempty"`
Title string `mapstructure:"title" json:"title,omitempty"`
Description string `mapstructure:"description" json:"description,omitempty"`
}

func (service *MessageService) List(params MessageListParams) (response *MessageList, err error) {
req, err := service.client.NewRequest("GET", params, "Message")
if err != nil {
Expand Down
16 changes: 14 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,29 @@ func ValidateSignatureV3(uri, nonce, method, signature, authToken string, params
multipleSignatures := strings.Split(signature, ",")
return Find(ComputeSignatureV3(authToken, uri, method, nonce, parameters), multipleSignatures)
}
func CreateWhatsappInteractive(interactiveData string) (interactive Interactive, err error) {
err = json.Unmarshal([]byte(interactiveData), &interactive)
if err != nil {
return
}
validate := validator.New()
err = validate.Struct(interactive)
if err != nil {
return
}
return
}

func CreateWhatsappTemplate(templateData string) (template Template, err error) {
err = json.Unmarshal([]byte(templateData), &template)
if err != nil {
return
}
err = validateWhatsappTemplate(template)
if err !=nil{
if err != nil {
return
}
return
return
}

func validateWhatsappTemplate(template Template) (err error) {
Expand Down

0 comments on commit b0a193b

Please sign in to comment.