From 5bdc2eb8047bae2c023b9940390d05e265c7e081 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 29 Jul 2022 15:40:30 +0300 Subject: [PATCH 1/2] Sender actions support --- actions.go | 17 +++++++++++++++++ messenger.go | 9 +++++++++ response.go | 8 ++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/actions.go b/actions.go index f478203..bc50220 100644 --- a/actions.go +++ b/actions.go @@ -24,3 +24,20 @@ const ( // status. AccountLinkingAction ) + +// SenderAction is used to send a specific action (event) to the Facebook. +// The result of sending said action is supposed to give more interactivity to the bot. +type SenderAction string + +const ( + // MarkSeen marks message as seen. + MarkSeen SenderAction = "MARK_SEEN" + // TypingOn turns on "Bot is typing..." indicator. + TypingOn SenderAction = "TYPING_ON" + // TypingOff turns off typing indicator. + TypingOff SenderAction = "TYPING_OFF" + // React to the message. + React SenderAction = "REACT" + // Unreact to the message (remove reaction). + Unreact SenderAction = "UNREACT" +) diff --git a/messenger.go b/messenger.go index 7e574df..de7b267 100644 --- a/messenger.go +++ b/messenger.go @@ -508,6 +508,15 @@ func (m *Messenger) EnableChatExtension(homeURL HomeURL) error { return checkFacebookError(resp.Body) } +func (m *Messenger) SenderAction(to Recipient, action SenderAction) (QueryResponse, error) { + response := &Response{ + token: m.token, + to: to, + sendAPIVersion: m.sendAPIVersion, + } + return response.SenderAction(action) +} + // classify determines what type of message a webhook event is. func (m *Messenger) classify(info MessageInfo) Action { if info.Message != nil { diff --git a/response.go b/response.go index d2db26c..252353a 100644 --- a/response.go +++ b/response.go @@ -352,8 +352,8 @@ func (r *Response) ListTemplate(elements *[]StructuredMessageElement, messagingT return r.DispatchMessage(&m) } -// SenderAction sends a info about sender action. -func (r *Response) SenderAction(action string) (QueryResponse, error) { +// SenderAction sends an info about sender action. +func (r *Response) SenderAction(action SenderAction) (QueryResponse, error) { m := SendSenderAction{ Recipient: r.to, SenderAction: action, @@ -547,6 +547,6 @@ type StructuredMessageButton struct { // SendSenderAction is the information about sender action. type SendSenderAction struct { - Recipient Recipient `json:"recipient"` - SenderAction string `json:"sender_action"` + Recipient Recipient `json:"recipient"` + SenderAction SenderAction `json:"sender_action"` } From 2af7845f3b7cd439426bdcf1e47fbe2044b3edf3 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 29 Jul 2022 15:44:46 +0300 Subject: [PATCH 2/2] update linter --- .github/workflows/ci.yml | 13 ++++++++++--- .golangci.yml | 20 +++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9799a8c..28a189b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,10 +19,17 @@ jobs: steps: - name: Check out code into the Go module directory uses: actions/checkout@v2 - - name: Lint code with golangci-lint - uses: golangci/golangci-lint-action@v2 + - name: Set up Go 1.17 + uses: actions/setup-go@v2 with: - version: v1.36 + # TODO: Should migrate to 1.18 later + go-version: '1.17' + - name: Get dependencies + run: go mod tidy + - name: Lint code with golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.42.1 only-new-issues: true tests: name: Tests diff --git a/.golangci.yml b/.golangci.yml index 9397fd4..8a3aa63 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,19 +32,15 @@ linters: - gocyclo - godot - goimports - - golint - - gomnd + - revive - gosec - ifshort - - interfacer - lll - makezero - - maligned - misspell - nestif - prealloc - predeclared - - scopelint - sqlclosecheck - unconvert - whitespace @@ -56,9 +52,11 @@ linters-settings: enable: - assign - atomic + - atomicalign - bools - buildtag - copylocks + - fieldalignment - httpresponse - loopclosure - lostcancel @@ -140,15 +138,13 @@ linters-settings: gocyclo: min-complexity: 25 goimports: - local-prefixes: github.com/retailcrm/messenger + local-prefixes: github.com/retailcrm/mg-transport-core lll: line-length: 120 - maligned: - suggest-new: true misspell: locale: US nestif: - min-complexity: 4 + min-complexity: 6 whitespace: multi-if: false multi-func: false @@ -157,8 +153,8 @@ issues: exclude-rules: - path: _test\.go linters: - - gomnd - lll + - errorlint - bodyclose - errcheck - sqlclosecheck @@ -166,7 +162,6 @@ issues: - ineffassign - whitespace - makezero - - maligned - ifshort - errcheck - funlen @@ -174,6 +169,9 @@ issues: - gocognit - gocyclo - godot + - unused + - path: \.go + text: "Error return value of `io.WriteString` is not checked" exclude-use-default: true exclude-case-sensitive: false max-issues-per-linter: 0