From b0a193bf6dd96b40346e93bab8258d1d4173c9f0 Mon Sep 17 00:00:00 2001 From: Saurabh Newatiya <107537111+saurabhnewatiya-plivo@users.noreply.github.com> Date: Tue, 7 May 2024 15:22:29 +0530 Subject: [PATCH] Adding support for interactive whatsapp messages (#203) * Adding support for interactive whatsapp messages --- CHANGELOG.md | 4 ++++ baseclient.go | 2 +- messages.go | 57 +++++++++++++++++++++++++++++++++++++++++++++------ utils.go | 16 +++++++++++++-- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fce6ec9..6b6d76e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/baseclient.go b/baseclient.go index 897d65f..8111ea3 100644 --- a/baseclient.go +++ b/baseclient.go @@ -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" diff --git a/messages.go b/messages.go index 71a4fe7..b473f27 100644 --- a/messages.go +++ b/messages.go @@ -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 { @@ -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 { diff --git a/utils.go b/utils.go index 8bea28d..441610d 100644 --- a/utils.go +++ b/utils.go @@ -173,6 +173,18 @@ 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) @@ -180,10 +192,10 @@ func CreateWhatsappTemplate(templateData string) (template Template, err error) return } err = validateWhatsappTemplate(template) - if err !=nil{ + if err != nil { return } - return + return } func validateWhatsappTemplate(template Template) (err error) {