Sender actions support
This commit is contained in:
commit
6c997fba17
13
.github/workflows/ci.yml
vendored
13
.github/workflows/ci.yml
vendored
@ -19,10 +19,17 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Lint code with golangci-lint
|
- name: Set up Go 1.17
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
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
|
only-new-issues: true
|
||||||
tests:
|
tests:
|
||||||
name: Tests
|
name: Tests
|
||||||
|
@ -32,19 +32,15 @@ linters:
|
|||||||
- gocyclo
|
- gocyclo
|
||||||
- godot
|
- godot
|
||||||
- goimports
|
- goimports
|
||||||
- golint
|
- revive
|
||||||
- gomnd
|
|
||||||
- gosec
|
- gosec
|
||||||
- ifshort
|
- ifshort
|
||||||
- interfacer
|
|
||||||
- lll
|
- lll
|
||||||
- makezero
|
- makezero
|
||||||
- maligned
|
|
||||||
- misspell
|
- misspell
|
||||||
- nestif
|
- nestif
|
||||||
- prealloc
|
- prealloc
|
||||||
- predeclared
|
- predeclared
|
||||||
- scopelint
|
|
||||||
- sqlclosecheck
|
- sqlclosecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- whitespace
|
- whitespace
|
||||||
@ -56,9 +52,11 @@ linters-settings:
|
|||||||
enable:
|
enable:
|
||||||
- assign
|
- assign
|
||||||
- atomic
|
- atomic
|
||||||
|
- atomicalign
|
||||||
- bools
|
- bools
|
||||||
- buildtag
|
- buildtag
|
||||||
- copylocks
|
- copylocks
|
||||||
|
- fieldalignment
|
||||||
- httpresponse
|
- httpresponse
|
||||||
- loopclosure
|
- loopclosure
|
||||||
- lostcancel
|
- lostcancel
|
||||||
@ -140,15 +138,13 @@ linters-settings:
|
|||||||
gocyclo:
|
gocyclo:
|
||||||
min-complexity: 25
|
min-complexity: 25
|
||||||
goimports:
|
goimports:
|
||||||
local-prefixes: github.com/retailcrm/messenger
|
local-prefixes: github.com/retailcrm/mg-transport-core
|
||||||
lll:
|
lll:
|
||||||
line-length: 120
|
line-length: 120
|
||||||
maligned:
|
|
||||||
suggest-new: true
|
|
||||||
misspell:
|
misspell:
|
||||||
locale: US
|
locale: US
|
||||||
nestif:
|
nestif:
|
||||||
min-complexity: 4
|
min-complexity: 6
|
||||||
whitespace:
|
whitespace:
|
||||||
multi-if: false
|
multi-if: false
|
||||||
multi-func: false
|
multi-func: false
|
||||||
@ -157,8 +153,8 @@ issues:
|
|||||||
exclude-rules:
|
exclude-rules:
|
||||||
- path: _test\.go
|
- path: _test\.go
|
||||||
linters:
|
linters:
|
||||||
- gomnd
|
|
||||||
- lll
|
- lll
|
||||||
|
- errorlint
|
||||||
- bodyclose
|
- bodyclose
|
||||||
- errcheck
|
- errcheck
|
||||||
- sqlclosecheck
|
- sqlclosecheck
|
||||||
@ -166,7 +162,6 @@ issues:
|
|||||||
- ineffassign
|
- ineffassign
|
||||||
- whitespace
|
- whitespace
|
||||||
- makezero
|
- makezero
|
||||||
- maligned
|
|
||||||
- ifshort
|
- ifshort
|
||||||
- errcheck
|
- errcheck
|
||||||
- funlen
|
- funlen
|
||||||
@ -174,6 +169,9 @@ issues:
|
|||||||
- gocognit
|
- gocognit
|
||||||
- gocyclo
|
- gocyclo
|
||||||
- godot
|
- godot
|
||||||
|
- unused
|
||||||
|
- path: \.go
|
||||||
|
text: "Error return value of `io.WriteString` is not checked"
|
||||||
exclude-use-default: true
|
exclude-use-default: true
|
||||||
exclude-case-sensitive: false
|
exclude-case-sensitive: false
|
||||||
max-issues-per-linter: 0
|
max-issues-per-linter: 0
|
||||||
|
17
actions.go
17
actions.go
@ -24,3 +24,20 @@ const (
|
|||||||
// status.
|
// status.
|
||||||
AccountLinkingAction
|
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"
|
||||||
|
)
|
||||||
|
@ -508,6 +508,15 @@ func (m *Messenger) EnableChatExtension(homeURL HomeURL) error {
|
|||||||
return checkFacebookError(resp.Body)
|
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.
|
// classify determines what type of message a webhook event is.
|
||||||
func (m *Messenger) classify(info MessageInfo) Action {
|
func (m *Messenger) classify(info MessageInfo) Action {
|
||||||
if info.Message != nil {
|
if info.Message != nil {
|
||||||
|
@ -352,8 +352,8 @@ func (r *Response) ListTemplate(elements *[]StructuredMessageElement, messagingT
|
|||||||
return r.DispatchMessage(&m)
|
return r.DispatchMessage(&m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SenderAction sends a info about sender action.
|
// SenderAction sends an info about sender action.
|
||||||
func (r *Response) SenderAction(action string) (QueryResponse, error) {
|
func (r *Response) SenderAction(action SenderAction) (QueryResponse, error) {
|
||||||
m := SendSenderAction{
|
m := SendSenderAction{
|
||||||
Recipient: r.to,
|
Recipient: r.to,
|
||||||
SenderAction: action,
|
SenderAction: action,
|
||||||
@ -547,6 +547,6 @@ type StructuredMessageButton struct {
|
|||||||
|
|
||||||
// SendSenderAction is the information about sender action.
|
// SendSenderAction is the information about sender action.
|
||||||
type SendSenderAction struct {
|
type SendSenderAction struct {
|
||||||
Recipient Recipient `json:"recipient"`
|
Recipient Recipient `json:"recipient"`
|
||||||
SenderAction string `json:"sender_action"`
|
SenderAction SenderAction `json:"sender_action"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user