From a752143df4f7889e1c723d6be88dbd107e962f15 Mon Sep 17 00:00:00 2001 From: simus Date: Fri, 30 Dec 2022 16:16:19 +0500 Subject: [PATCH] handling notification_type of the messages --- response.go | 56 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/response.go b/response.go index eb2804a..37f20ea 100644 --- a/response.go +++ b/response.go @@ -19,6 +19,7 @@ import ( // AttachmentType is attachment type. type AttachmentType string type MessagingType string +type NotificationType string type TopElementStyle string type ImageAspectRatio string @@ -50,6 +51,13 @@ const ( // NonPromotionalSubscriptionType is NON_PROMOTIONAL_SUBSCRIPTION messaging type. NonPromotionalSubscriptionType MessagingType = "NON_PROMOTIONAL_SUBSCRIPTION" + // NotificationNoPushType is NO_PUSH notification type + NotificationNoPushType NotificationType = "NO_PUSH" + // NotificationRegularType is REGULAR notification type (default) + NotificationRegularType NotificationType = "REGULAR" + // NotificationSilentPushType is SILENT_PUSH notification type + NotificationSilentPushType NotificationType = "SILENT_PUSH" + // TopElementStyle is compact. CompactTopElementStyle TopElementStyle = "compact" // TopElementStyle is large. @@ -127,16 +135,30 @@ func (r *Response) SetToken(token string) { r.token = token } -// Text sends a textual message. -func (r *Response) Text(message string, messagingType MessagingType, metadata string, tags ...string) (QueryResponse, error) { - return r.TextWithReplies(message, nil, messagingType, metadata, tags...) +func (r *Response) Text( + message string, + messagingType MessagingType, + metadata string, + notificationType NotificationType, + tags ...string, +) (QueryResponse, error) { + return r.TextWithReplies(message, nil, messagingType, metadata, notificationType, tags...) } // TextWithReplies sends a textual message with some replies // messagingType should be one of the following: "RESPONSE","UPDATE","MESSAGE_TAG","NON_PROMOTIONAL_SUBSCRIPTION" // only supply tags when messagingType == "MESSAGE_TAG" // (see https://developers.facebook.com/docs/messenger-platform/send-messages#messaging_types for more). -func (r *Response) TextWithReplies(message string, replies []QuickReply, messagingType MessagingType, metadata string, tags ...string) (QueryResponse, error) { +// notificationType should be one of the following: "NO_PUSH","REGULAR" (default),"SILENT_PUSH" +// only supply tags when messagingType == "MESSAGE_TAG" (see https://developers.facebook.com/docs/messenger-platform/send-messages#messaging_types for more) +func (r *Response) TextWithReplies( + message string, + replies []QuickReply, + messagingType MessagingType, + metadata string, + notificationType NotificationType, + tags ...string, +) (QueryResponse, error) { var tag string if len(tags) > 0 { tag = tags[0] @@ -151,13 +173,21 @@ func (r *Response) TextWithReplies(message string, replies []QuickReply, messagi QuickReplies: replies, Metadata: metadata, }, - Tag: tag, + Tag: tag, + NotificationType: notificationType, } return r.DispatchMessage(&m) } -// AttachmentWithReplies sends a attachment message with some replies. -func (r *Response) AttachmentWithReplies(attachment *StructuredMessageAttachment, replies []QuickReply, messagingType MessagingType, metadata string, tags ...string) (QueryResponse, error) { +// AttachmentWithReplies sends a attachment message with some replies +func (r *Response) AttachmentWithReplies( + attachment *StructuredMessageAttachment, + replies []QuickReply, + messagingType MessagingType, + metadata string, + notificationType NotificationType, + tags ...string, +) (QueryResponse, error) { var tag string if len(tags) > 0 { tag = tags[0] @@ -171,7 +201,8 @@ func (r *Response) AttachmentWithReplies(attachment *StructuredMessageAttachment QuickReplies: replies, Metadata: metadata, }, - Tag: tag, + Tag: tag, + NotificationType: notificationType, } return r.DispatchMessage(&m) } @@ -423,10 +454,11 @@ func (r *Response) PassThreadToInbox() error { // SendMessage is the information sent in an API request to Facebook. type SendMessage struct { - MessagingType MessagingType `json:"messaging_type"` - Recipient Recipient `json:"recipient"` - Message MessageData `json:"message"` - Tag string `json:"tag,omitempty"` + MessagingType MessagingType `json:"messaging_type"` + Recipient Recipient `json:"recipient"` + Message MessageData `json:"message"` + Tag string `json:"tag,omitempty"` + NotificationType NotificationType `json:"notification_type,omitempty"` } // MessageData is a message consisting of text or an attachment, with an additional selection of optional quick replies.