1
0
Fork 0
mirror of synced 2025-04-08 11:32:06 +00:00

Compare commits

..

No commits in common. "master" and "v1.2.7" have entirely different histories.

8 changed files with 36 additions and 148 deletions

View file

@ -19,17 +19,10 @@ jobs:
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
# 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
uses: golangci/golangci-lint-action@v2
with:
version: v1.50.1
version: v1.36
only-new-issues: true
tests:
name: Tests

View file

@ -6,33 +6,20 @@ output:
format: colored-line-number
sort-results: true
# Linters below do not support go1.18 yet because of generics.
# See https://github.com/golangci/golangci-lint/issues/2649
# - bodyclose
# - sqlclosecheck
linters:
disable-all: true
enable:
- paralleltest
- tparallel
- asciicheck
- asasalint
- varnamelen
- reassign
- nilnil
- nilerr
- nakedret
- goprintffuncname
- typecheck
- errchkjson
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- unused
- unparam
- varcheck
- bodyclose
- dogsled
- dupl
- errorlint
@ -45,15 +32,20 @@ linters:
- gocyclo
- godot
- goimports
- revive
- golint
- gomnd
- gosec
- ifshort
- interfacer
- lll
- makezero
- maligned
- misspell
- nestif
- prealloc
- predeclared
- exportloopref
- scopelint
- sqlclosecheck
- unconvert
- whitespace
@ -64,11 +56,9 @@ linters-settings:
enable:
- assign
- atomic
- atomicalign
- bools
- buildtag
- copylocks
- fieldalignment
- httpresponse
- loopclosure
- lostcancel
@ -80,6 +70,7 @@ linters-settings:
- unmarshal
- unreachable
- unsafeptr
- unused
settings:
printf:
funcs:
@ -138,13 +129,11 @@ linters-settings:
threshold: 200
errorlint:
errorf: true
asserts: false
comparison: false
exhaustive:
check-generated: false
default-signifies-exhaustive: false
funlen:
lines: 90
lines: 60
statements: 40
gocognit:
min-complexity: 25
@ -154,6 +143,8 @@ linters-settings:
local-prefixes: github.com/retailcrm/messenger
lll:
line-length: 120
maligned:
suggest-new: true
misspell:
locale: US
nestif:
@ -161,36 +152,28 @@ linters-settings:
whitespace:
multi-if: false
multi-func: false
varnamelen:
max-distance: 10
ignore-map-index-ok: true
ignore-type-assert-ok: true
ignore-chan-recv-ok: true
ignore-decls:
- t *testing.T
- e error
- i int
issues:
exclude-rules:
- path: _test\.go
linters:
- gomnd
- lll
- bodyclose
- errcheck
- sqlclosecheck
- misspell
- ineffassign
- whitespace
- makezero
- maligned
- ifshort
- errcheck
- funlen
- goconst
- gocognit
- gocyclo
- godot
- unused
- errchkjson
- varnamelen
- 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
@ -202,4 +185,4 @@ severity:
case-sensitive: false
service:
golangci-lint-version: 1.50.x
golangci-lint-version: 1.36.x

View file

@ -24,20 +24,3 @@ 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"
)

7
go.mod
View file

@ -1,11 +1,8 @@
module github.com/retailcrm/messenger
require (
github.com/stretchr/testify v1.2.2
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
)

View file

@ -66,8 +66,6 @@ type Read struct {
RawWatermark int64 `json:"watermark"`
// Seq is the sequence the message was sent in.
Seq int `json:"seq"`
// Mid is the ID of the message.
Mid string `json:"mid"`
}
// IGMessageRead represents data with the read message ID. Present in the Instagram webhook.
@ -81,7 +79,7 @@ type IGMessageReaction struct {
// Mid is a message ID.
Mid string `json:"mid"`
// Action can be {react|unreact}
Action ReactionAction `json:"action"`
Action string `json:"action"`
// Reaction is a reaction name. Optional.
Reaction string `json:"reaction,omitempty"`
// Emoji is optional.
@ -94,10 +92,8 @@ type IGMessageProduct struct {
ID string `json:"id,omitempty"`
}
// IGMessageReferral represents Instagram message referral with ad data and product ID.
// IGMessageReferral represents Instagram message referral with product ID.
type IGMessageReferral struct {
// Ad data
Referral
// Product data.
Product IGMessageProduct `json:"product,omitempty"`
}

View file

@ -508,29 +508,6 @@ 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)
}
func (m *Messenger) InstagramReaction(
to Recipient,
mid string,
action ReactionAction,
reaction ...string,
) (QueryResponse, error) {
response := &Response{
token: m.token,
to: to,
sendAPIVersion: m.sendAPIVersion,
}
return response.InstagramReaction(mid, action, reaction...)
}
// classify determines what type of message a webhook event is.
func (m *Messenger) classify(info MessageInfo) Action {
if info.Message != nil {

View file

@ -35,8 +35,6 @@ type MessageInfo struct {
// Delivery is the contents of a message if it is a DeliveryAction.
// Nil if it is not a DeliveryAction.
Delivery *Delivery `json:"delivery"`
// Reaction represents reaction to Instagram message.
Reaction *IGMessageReaction `json:"reaction,omitempty"`
PostBack *PostBack `json:"postback"`
@ -84,8 +82,6 @@ type Referral struct {
AdID string `json:"ad_id,omitempty"`
// The data containing information about the CTM ad, the user initiated the thread from.
AdsContextData AdsContextData `json:"ads_context_data,omitempty"`
// URI of the site from which the message was sent to the Facebook chat plugin.
RefererURI string `json:"referer_uri,omitempty"`
}
// AdsContextData represents data containing information about the CTM ad, the user initiated the thread from.

View file

@ -182,7 +182,7 @@ func (r *Response) Image(im image.Image) (QueryResponse, error) {
return qr, err
}
return r.AttachmentData(ImageAttachment, "meme.jpg", "image/jpeg", imageBytes)
return r.AttachmentData(ImageAttachment, "meme.jpg", imageBytes)
}
// Attachment sends an image, sound, video or a regular file to a chat.
@ -228,14 +228,15 @@ func createFormFile(filename string, w *multipart.Writer, contentType string) (i
}
// AttachmentData sends an image, sound, video or a regular file to a chat via an io.Reader.
func (r *Response) AttachmentData(
dataType AttachmentType, filename string, contentType string, filedata io.Reader) (QueryResponse, error) {
func (r *Response) AttachmentData(dataType AttachmentType, filename string, filedata io.Reader) (QueryResponse, error) {
var qr QueryResponse
filedataBytes, err := ioutil.ReadAll(filedata)
if err != nil {
return qr, err
}
contentType := http.DetectContentType(filedataBytes[:512])
fmt.Println("Content-type detected:", contentType)
var body bytes.Buffer
multipartWriter := multipart.NewWriter(&body)
@ -351,8 +352,8 @@ func (r *Response) ListTemplate(elements *[]StructuredMessageElement, messagingT
return r.DispatchMessage(&m)
}
// SenderAction sends an info about sender action.
func (r *Response) SenderAction(action SenderAction) (QueryResponse, error) {
// SenderAction sends a info about sender action.
func (r *Response) SenderAction(action string) (QueryResponse, error) {
m := SendSenderAction{
Recipient: r.to,
SenderAction: action,
@ -360,21 +361,6 @@ func (r *Response) SenderAction(action SenderAction) (QueryResponse, error) {
return r.DispatchMessage(&m)
}
// InstagramReaction sends an info about Instagram reaction.
func (r *Response) InstagramReaction(mid string, action ReactionAction, reaction ...string) (QueryResponse, error) {
m := SendInstagramReaction{
Recipient: r.to,
SenderAction: action,
Payload: SenderInstagramReactionPayload{
MessageID: mid,
},
}
if len(reaction) > 0 {
m.Payload.Reaction = reaction[0]
}
return r.DispatchMessage(&m)
}
// DispatchMessage posts the message to messenger, return the error if there's any.
func (r *Response) DispatchMessage(m interface{}) (QueryResponse, error) {
var res QueryResponse
@ -561,29 +547,6 @@ type StructuredMessageButton struct {
// SendSenderAction is the information about sender action.
type SendSenderAction struct {
Recipient Recipient `json:"recipient"`
SenderAction SenderAction `json:"sender_action"`
}
// ReactionAction contains info about reaction action type.
type ReactionAction string
const (
// ReactionActionReact is used when user added a reaction.
ReactionActionReact ReactionAction = "react"
// ReactionActionUnReact is used when user removed a reaction.
ReactionActionUnReact ReactionAction = "unreact"
)
// SendInstagramReaction is the information about sender action.
type SendInstagramReaction struct {
Recipient Recipient `json:"recipient"`
SenderAction ReactionAction `json:"sender_action"`
Payload SenderInstagramReactionPayload `json:"payload"`
}
// SenderInstagramReactionPayload contains target message ID and reaction name.
type SenderInstagramReactionPayload struct {
MessageID string `json:"message_id"`
Reaction string `json:"reaction"`
Recipient Recipient `json:"recipient"`
SenderAction string `json:"sender_action"`
}