Skip to content

Commit 8d2ab13

Browse files
committed
feat: add location request message support
Signed-off-by: sarthakjdev <jsarthak448@gmail.com>
1 parent 22347b3 commit 8d2ab13

File tree

5 files changed

+271
-20
lines changed

5 files changed

+271
-20
lines changed

docs/api-reference/manager.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ type ProductItem struct {
14501450
Brand string `json:"brand,omitempty"`
14511451
CapabilityToReviewStatus []KeyValue `json:"capability_to_review_status,omitempty"`
14521452
Category string `json:"category,omitempty"`
1453-
CategorySpecificFields string `json:"category_specific_fields,omitempty"`
1453+
CategorySpecificFields interface{} `json:"category_specific_fields,omitempty"`
14541454
Color string `json:"color,omitempty"`
14551455
CommerceInsights string `json:"commerce_insights,omitempty"`
14561456
Condition string `json:"condition,omitempty"`

docs/api-reference/pkg/components.mdx

Lines changed: 185 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,12 @@ type InteractiveMessageType string
660660

661661
```go
662662
const (
663-
InteractiveMessageTypeButton InteractiveMessageType = "button"
664-
InteractiveMessageTypeProduct InteractiveMessageType = "product"
665-
InteractiveMessageTypeProductList InteractiveMessageType = "product_list"
666-
InteractiveMessageTypeList InteractiveMessageType = "list"
667-
InteractiveMessageTypeCatalog InteractiveMessageType = "catalog_message"
663+
InteractiveMessageTypeButton InteractiveMessageType = "button"
664+
InteractiveMessageTypeProduct InteractiveMessageType = "product"
665+
InteractiveMessageTypeProductList InteractiveMessageType = "product_list"
666+
InteractiveMessageTypeList InteractiveMessageType = "list"
667+
InteractiveMessageTypeCatalog InteractiveMessageType = "catalog_message"
668+
InteractiveMessageTypeLocationRequest InteractiveMessageType = "location_request_message"
668669
)
669670
```
670671

@@ -691,6 +692,29 @@ type ListMessageBody struct {
691692
}
692693
```
693694

695+
<a name="ListMessageFooter"></a>
696+
## type ListMessageFooter
697+
698+
ListMessageFooter represents the footer of the list message.
699+
700+
```go
701+
type ListMessageFooter struct {
702+
Text string `json:"text" validate:"required"` // Text of the footer.
703+
}
704+
```
705+
706+
<a name="ListMessageHeader"></a>
707+
## type ListMessageHeader
708+
709+
710+
711+
```go
712+
type ListMessageHeader struct {
713+
Type string `json:"type" validate:"required"` // Type of the header.
714+
Text string `json:"text" validate:"required"` // Text of the header.
715+
}
716+
```
717+
694718
<a name="ListMessageParams"></a>
695719
## type ListMessageParams
696720

@@ -804,6 +828,80 @@ type LocationMessageApiPayload struct {
804828
}
805829
```
806830

831+
<a name="LocationRequestMessage"></a>
832+
## type LocationRequestMessage
833+
834+
835+
836+
```go
837+
type LocationRequestMessage struct {
838+
Type InteractiveMessageType `json:"type" validate:"required"` // Type of the message.
839+
Action locationMessageAction `json:"action" validate:"required"` // Action of the message.
840+
Body LocationRequestMessageBody `json:"body,omitempty"` // Body of the message.
841+
}
842+
```
843+
844+
<a name="NewLocationRequestMessage"></a>
845+
### func NewLocationRequestMessage
846+
847+
```go
848+
func NewLocationRequestMessage(params LocationRequestMessageParams) (*LocationRequestMessage, error)
849+
```
850+
851+
852+
853+
<a name="LocationRequestMessage.SetBodyText"></a>
854+
### func \(\*LocationRequestMessage\) SetBodyText
855+
856+
```go
857+
func (m *LocationRequestMessage) SetBodyText(bodyText string)
858+
```
859+
860+
SetBodyText sets the body text of the list message.
861+
862+
<a name="LocationRequestMessage.ToJson"></a>
863+
### func \(\*LocationRequestMessage\) ToJson
864+
865+
```go
866+
func (m *LocationRequestMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
867+
```
868+
869+
ToJson converts the list message to JSON.
870+
871+
<a name="LocationRequestMessageApiPayload"></a>
872+
## type LocationRequestMessageApiPayload
873+
874+
875+
876+
```go
877+
type LocationRequestMessageApiPayload struct {
878+
BaseMessagePayload
879+
Interactive LocationRequestMessage `json:"interactive" validate:"required"` // Interactive message.
880+
}
881+
```
882+
883+
<a name="LocationRequestMessageBody"></a>
884+
## type LocationRequestMessageBody
885+
886+
887+
888+
```go
889+
type LocationRequestMessageBody struct {
890+
Text string `json:"text" validate:"required"` // Text of the body.
891+
}
892+
```
893+
894+
<a name="LocationRequestMessageParams"></a>
895+
## type LocationRequestMessageParams
896+
897+
898+
899+
```go
900+
type LocationRequestMessageParams struct {
901+
BodyText string `json:"-" validate:"required"` // Text of the body.
902+
}
903+
```
904+
807905
<a name="MessageType"></a>
808906
## type MessageType
809907

@@ -840,7 +938,7 @@ Order represents an order in the system.
840938
type Order struct {
841939
CatalogID string `json:"catalog_id"` // CatalogID is the ID of the catalog associated with the order.
842940
ProductItems []ProductItem `json:"product_items"` // ProductItems is a list of product items in the order.
843-
Text string `json:"text"` // Text is an additional text associated with the order.
941+
Text *string `json:"text"` // Text is an additional text associated with the order.
844942
}
845943
```
846944

@@ -892,10 +990,10 @@ ProductItem represents a product item in an order.
892990

893991
```go
894992
type ProductItem struct {
895-
Currency string `json:"currency"` // Currency is the currency of the product item.
896-
ItemPrice string `json:"item_price"` // ItemPrice is the price of the product item.
897-
ProductRetailerID string `json:"product_retailer_id"` // ProductRetailerID is the ID of the retailer associated with the product item.
898-
Quantity string `json:"quantity"` // Quantity is the quantity of the product item.
993+
Currency string `json:"currency"` // Currency is the currency of the product item.
994+
ItemPrice float64 `json:"item_price"` // ItemPrice is the price of the product item.
995+
ProductRetailerID string `json:"product_retailer_id"` // ProductRetailerID is the ID of the retailer associated with the product item.
996+
Quantity int `json:"quantity"` // Quantity is the quantity of the product item.
899997
}
900998
```
901999

@@ -1258,9 +1356,11 @@ QuickReplyButtonMessage represents a quick reply button message.
12581356

12591357
```go
12601358
type QuickReplyButtonMessage struct {
1261-
Type InteractiveMessageType `json:"type" validate:"required"` // Type of the quick reply button message.
1262-
Body QuickReplyButtonMessageBody `json:"body" validate:"required"` // Body of the quick reply button message.
1263-
Action QuickReplyButtonMessageAction `json:"action" validate:"required"` // Action of the quick reply button message.
1359+
Type InteractiveMessageType `json:"type" validate:"required"` // Type of the quick reply button message.
1360+
Body QuickReplyButtonMessageBody `json:"body" validate:"required"` // Body of the quick reply button message.
1361+
Action QuickReplyButtonMessageAction `json:"action" validate:"required"` // Action of the quick reply button message.
1362+
Footer *QuickReplyButtonMessageFooter `json:"footer,omitempty"` // Footer of the quick reply button message.
1363+
Header *QuickReplyButtonMessageHeader `json:"header,omitempty"` // Header of the quick reply button message.
12641364
}
12651365
```
12661366

@@ -1282,6 +1382,24 @@ func (m *QuickReplyButtonMessage) AddButton(id, title string) error
12821382

12831383

12841384

1385+
<a name="QuickReplyButtonMessage.SetFooter"></a>
1386+
### func \(\*QuickReplyButtonMessage\) SetFooter
1387+
1388+
```go
1389+
func (m *QuickReplyButtonMessage) SetFooter(text string)
1390+
```
1391+
1392+
1393+
1394+
<a name="QuickReplyButtonMessage.SetHeader"></a>
1395+
### func \(\*QuickReplyButtonMessage\) SetHeader
1396+
1397+
```go
1398+
func (m *QuickReplyButtonMessage) SetHeader(text string)
1399+
```
1400+
1401+
1402+
12851403
<a name="QuickReplyButtonMessage.ToJson"></a>
12861404
### func \(\*QuickReplyButtonMessage\) ToJson
12871405

@@ -1325,6 +1443,29 @@ type QuickReplyButtonMessageBody struct {
13251443
}
13261444
```
13271445

1446+
<a name="QuickReplyButtonMessageFooter"></a>
1447+
## type QuickReplyButtonMessageFooter
1448+
1449+
QuickReplyButtonMessageFooter represents the footer of a quick reply button message.
1450+
1451+
```go
1452+
type QuickReplyButtonMessageFooter struct {
1453+
Text string `json:"text" validate:"required"` // Text of the quick reply button message footer.
1454+
}
1455+
```
1456+
1457+
<a name="QuickReplyButtonMessageHeader"></a>
1458+
## type QuickReplyButtonMessageHeader
1459+
1460+
1461+
1462+
```go
1463+
type QuickReplyButtonMessageHeader struct {
1464+
Type string `json:"type" validate:"required"` // Type of the quick reply button message header.
1465+
Text string `json:"text" validate:"required"` // Text of the quick reply button message header.
1466+
}
1467+
```
1468+
13281469
<a name="ReactionMessage"></a>
13291470
## type ReactionMessage
13301471

@@ -2023,6 +2164,8 @@ type listMessage struct {
20232164
Type InteractiveMessageType `json:"type" validate:"required"` // Type of the message.
20242165
Action listMessageAction `json:"action" validate:"required"` // Action of the message.
20252166
Body ListMessageBody `json:"body,omitempty"` // Body of the message.
2167+
Footer *ListMessageFooter `json:"footer,omitempty"` // Footer of the message.
2168+
Header *ListMessageHeader `json:"header,omitempty"` // Header of the message.
20262169
}
20272170
```
20282171

@@ -2053,6 +2196,24 @@ func (m *listMessage) SetBodyText(section *ListSection)
20532196

20542197
SetBodyText sets the body text of the list message.
20552198

2199+
<a name="listMessage.SetFooterText"></a>
2200+
### func \(\*listMessage\) SetFooterText
2201+
2202+
```go
2203+
func (m *listMessage) SetFooterText(footerText string)
2204+
```
2205+
2206+
2207+
2208+
<a name="listMessage.SetHeaderText"></a>
2209+
### func \(\*listMessage\) SetHeaderText
2210+
2211+
```go
2212+
func (m *listMessage) SetHeaderText(headerText string)
2213+
```
2214+
2215+
2216+
20562217
<a name="listMessage.ToJson"></a>
20572218
### func \(\*listMessage\) ToJson
20582219

@@ -2123,6 +2284,17 @@ func (row *listSectionRow) SetTitle(title string)
21232284

21242285
SetTitle sets the title of the list section row.
21252286

2287+
<a name="locationMessageAction"></a>
2288+
## type locationMessageAction
2289+
2290+
2291+
2292+
```go
2293+
type locationMessageAction struct {
2294+
Name string `json:"name" validate:"required"` // Name of the action.
2295+
}
2296+
```
2297+
21262298
<a name="productMessageAction"></a>
21272299
## type productMessageAction
21282300

manager/catalog_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type ProductItem struct {
8383
Brand string `json:"brand,omitempty"`
8484
CapabilityToReviewStatus []KeyValue `json:"capability_to_review_status,omitempty"`
8585
Category string `json:"category,omitempty"`
86-
CategorySpecificFields string `json:"category_specific_fields,omitempty"`
86+
CategorySpecificFields interface{} `json:"category_specific_fields,omitempty"`
8787
Color string `json:"color,omitempty"`
8888
CommerceInsights string `json:"commerce_insights,omitempty"`
8989
Condition string `json:"condition,omitempty"`

pkg/components/interactive_message.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package components
33
type InteractiveMessageType string
44

55
const (
6-
InteractiveMessageTypeButton InteractiveMessageType = "button"
7-
InteractiveMessageTypeProduct InteractiveMessageType = "product"
8-
InteractiveMessageTypeProductList InteractiveMessageType = "product_list"
9-
InteractiveMessageTypeList InteractiveMessageType = "list"
10-
InteractiveMessageTypeCatalog InteractiveMessageType = "catalog_message"
6+
InteractiveMessageTypeButton InteractiveMessageType = "button"
7+
InteractiveMessageTypeProduct InteractiveMessageType = "product"
8+
InteractiveMessageTypeProductList InteractiveMessageType = "product_list"
9+
InteractiveMessageTypeList InteractiveMessageType = "list"
10+
InteractiveMessageTypeCatalog InteractiveMessageType = "catalog_message"
11+
InteractiveMessageTypeLocationRequest InteractiveMessageType = "location_request_message"
1112
)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package components
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"github.com/wapikit/wapi.go/internal"
8+
)
9+
10+
type locationMessageAction struct {
11+
Name string `json:"name" validate:"required"` // Name of the action.
12+
}
13+
14+
type LocationRequestMessageBody struct {
15+
Text string `json:"text" validate:"required"` // Text of the body.
16+
}
17+
type LocationRequestMessage struct {
18+
Type InteractiveMessageType `json:"type" validate:"required"` // Type of the message.
19+
Action locationMessageAction `json:"action" validate:"required"` // Action of the message.
20+
Body LocationRequestMessageBody `json:"body,omitempty"` // Body of the message.
21+
}
22+
23+
type LocationRequestMessageParams struct {
24+
BodyText string `json:"-" validate:"required"` // Text of the body.
25+
}
26+
27+
func NewLocationRequestMessage(params LocationRequestMessageParams) (*LocationRequestMessage, error) {
28+
if err := internal.GetValidator().Struct(params); err != nil {
29+
return nil, fmt.Errorf("error validating configs: %v", err)
30+
}
31+
32+
return &LocationRequestMessage{
33+
Type: InteractiveMessageTypeLocationRequest,
34+
Body: LocationRequestMessageBody{
35+
Text: params.BodyText,
36+
},
37+
Action: locationMessageAction{
38+
Name: "send_location",
39+
},
40+
}, nil
41+
}
42+
43+
type LocationRequestMessageApiPayload struct {
44+
BaseMessagePayload
45+
Interactive LocationRequestMessage `json:"interactive" validate:"required"` // Interactive message.
46+
}
47+
48+
// SetBodyText sets the body text of the list message.
49+
func (m *LocationRequestMessage) SetBodyText(bodyText string) {
50+
m.Body.Text = bodyText
51+
52+
}
53+
54+
// ToJson converts the list message to JSON.
55+
func (m *LocationRequestMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error) {
56+
if err := internal.GetValidator().Struct(configs); err != nil {
57+
return nil, fmt.Errorf("error validating configs: %v", err)
58+
}
59+
60+
jsonData := LocationRequestMessageApiPayload{
61+
BaseMessagePayload: NewBaseMessagePayload(configs.SendToPhoneNumber, MessageTypeInteractive),
62+
Interactive: *m,
63+
}
64+
65+
if configs.ReplyToMessageId != "" {
66+
jsonData.Context = &Context{
67+
MessageId: configs.ReplyToMessageId,
68+
}
69+
}
70+
71+
jsonToReturn, err := json.Marshal(jsonData)
72+
73+
if err != nil {
74+
return nil, fmt.Errorf("error marshalling json: %v", err)
75+
}
76+
77+
return jsonToReturn, nil
78+
}

0 commit comments

Comments
 (0)