Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,31 @@ jobs:
runs-on: ubuntu-latest
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
uses: actions/checkout@v4
- name: Set up Go 1.24
uses: actions/setup-go@v5
with:
# TODO: Should migrate to 1.18 later
go-version: '1.17'
go-version: '1.24'
- name: Get dependencies
run: go mod tidy
- name: Lint code with golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: v1.62.2
only-new-issues: true
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.13', '1.14', '1.15', '1.16', '1.17']
go-version: ['1.16', '1.17', '1.18', '1.19', '1.20', '1.21', '1.22', '1.23', '1.24']
steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Get dependencies
run: go mod tidy
- name: Tests
Expand Down
63 changes: 21 additions & 42 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
run:
skip-dirs-use-default: true
allow-parallel-runners: true
modules-download-mode: readonly

output:
format: colored-line-number
formats:
- 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
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- unparam
- bodyclose
- dogsled
- dupl
- errorlint
- exhaustive
- exportloopref
- copyloopvar
- funlen
- gocognit
- goconst
Expand All @@ -46,16 +32,18 @@ linters:
- godot
- goimports
- revive
- mnd
- gosec
- lll
- makezero
- misspell
- nestif
- prealloc
- predeclared
- exportloopref
- sqlclosecheck
- unconvert
- whitespace
- unused
- testifylint

linters-settings:
govet:
Expand All @@ -64,11 +52,9 @@ linters-settings:
enable:
- assign
- atomic
- atomicalign
- bools
- buildtag
- copylocks
- fieldalignment
- httpresponse
- loopclosure
- lostcancel
Expand All @@ -80,6 +66,7 @@ linters-settings:
- unmarshal
- unreachable
- unsafeptr
- unused
settings:
printf:
funcs:
Expand Down Expand Up @@ -138,20 +125,18 @@ linters-settings:
threshold: 200
errorlint:
errorf: true
asserts: false
comparison: false
exhaustive:
check-generated: false
default-signifies-exhaustive: false
funlen:
lines: 90
statements: 40
lines: 65
statements: 50
gocognit:
min-complexity: 25
gocyclo:
min-complexity: 25
goimports:
local-prefixes: github.com/retailcrm/messenger
local-prefixes: github.com/retailcrm/mg-transport-api-client-go
lll:
line-length: 120
misspell:
Expand All @@ -161,36 +146,30 @@ 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:
- dupl
- mnd
- 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
Expand All @@ -202,4 +181,4 @@ severity:
case-sensitive: false

service:
golangci-lint-version: 1.50.x
golangci-lint-version: 1.62.x
3 changes: 2 additions & 1 deletion examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func main() {
fmt.Println("Something went wrong!", err)
}

r.Text(fmt.Sprintf("Hello, %v!", p.FirstName), messenger.ResponseType, "")
r.Text(fmt.Sprintf("Hello, %v!", p.FirstName),
messenger.ResponseType, "", messenger.NotificationRegularType)
})

// Setup a handler to be triggered when a message is delivered
Expand Down
3 changes: 2 additions & 1 deletion examples/extension/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func main() {
fmt.Println("Something went wrong!", err)
}

r.Text(fmt.Sprintf("Hello, %v!", p.FirstName), messenger.ResponseType, "")
r.Text(fmt.Sprintf("Hello, %v!", p.FirstName), messenger.ResponseType,
"", messenger.NotificationRegularType)
})

addr := fmt.Sprintf("%s:%d", *host, *port)
Expand Down
8 changes: 5 additions & 3 deletions examples/linked-account/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func main() {
text = "You've been logged out of your account."
}

if _, err := r.Text(text, messenger.ResponseType, ""); err != nil {
if _, err := r.Text(text, messenger.ResponseType,
"", messenger.NotificationRegularType); err != nil {
log.Println("Failed to send account linking feedback")
}
})
Expand Down Expand Up @@ -134,7 +135,8 @@ func logoutButton(r *messenger.Response) error {

// greeting salutes the user.
func greeting(p messenger.Profile, r *messenger.Response) error {
_, err := r.Text(fmt.Sprintf("Hello, %v!", p.FirstName), messenger.ResponseType, "")
_, err := r.Text(fmt.Sprintf("Hello, %v!", p.FirstName), messenger.ResponseType,
"", messenger.NotificationRegularType)
return err
}

Expand All @@ -156,7 +158,7 @@ func help(p messenger.Profile, r *messenger.Response) error {
},
}

_, err := r.TextWithReplies(text, replies, messenger.ResponseType, "")
_, err := r.TextWithReplies(text, replies, messenger.ResponseType, "", messenger.NotificationRegularType)
return err
}

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ require (
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
)

go 1.16

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
22 changes: 11 additions & 11 deletions messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import (
)

const (
// ProfileURL is the API endpoint used for retrieving profiles.
// Used in the form: https://graph.facebook.com/v2.6/<USER_ID>?fields=<PROFILE_FIELDS>&access_token=<PAGE_ACCESS_TOKEN>
ProfileURL = "https://graph.facebook.com/v2.6/"

// ProfileFields is a list of JSON field names which will be populated by the profile query.
ProfileFields = "first_name,last_name,profile_pic"

// ProfileURL is the API endpoint used for retrieving profiles.
// Used in the form: https://graph.facebook.com/v14.0/<USER_ID>?fields=<PROFILE_FIELDS>&access_token=<PAGE_ACCESS_TOKEN>
ProfileURL = "https://graph.facebook.com/v14.0/"

// SendSettingsURL is API endpoint for saving settings.
SendSettingsURL = "https://graph.facebook.com/v2.6/me/thread_settings"
SendSettingsURL = "https://graph.facebook.com/v11.0/me/thread_settings"

// MessengerProfileURL is the API endpoint where you set properties that define various aspects of the following Messenger Platform features.
// Used in the form https://graph.facebook.com/v2.6/me/messenger_profile?access_token=<PAGE_ACCESS_TOKEN>
// https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/
MessengerProfileURL = "https://graph.facebook.com/v2.6/me/messenger_profile"
MessengerProfileURL = "https://graph.facebook.com/v11.0/me/messenger_profile"
)

// Options are the settings used when creating a Messenger client.
Expand Down Expand Up @@ -303,8 +303,8 @@ func (m *Messenger) handle(w http.ResponseWriter, r *http.Request) {
return
}

if rec.Object != "page" {
fmt.Println("Object is not page, undefined behavior. Got", rec.Object)
if rec.Object != "page" && rec.Object != "instagram" {
fmt.Println("Object is not page or instagram, undefined behavior. Got", rec.Object)
respond(w, http.StatusUnprocessableEntity)
return
}
Expand Down Expand Up @@ -443,7 +443,7 @@ func (m *Messenger) Response(to int64) *Response {
}

// Send will send a textual message to a user. This user must have previously initiated a conversation with the bot.
func (m *Messenger) Send(to Recipient, message string, messagingType MessagingType, metadata string, tags ...string) (QueryResponse, error) {
func (m *Messenger) Send(to Recipient, message string, messagingType MessagingType, metadata string, tags ...TagType) (QueryResponse, error) {
return m.SendWithReplies(to, message, nil, messagingType, metadata, tags...)
}

Expand All @@ -458,14 +458,14 @@ func (m *Messenger) SendGeneralMessage(to Recipient, elements *[]StructuredMessa
}

// SendWithReplies sends a textual message to a user, but gives them the option of numerous quick response options.
func (m *Messenger) SendWithReplies(to Recipient, message string, replies []QuickReply, messagingType MessagingType, metadata string, tags ...string) (QueryResponse, error) {
func (m *Messenger) SendWithReplies(to Recipient, message string, replies []QuickReply, messagingType MessagingType, metadata string, tags ...TagType) (QueryResponse, error) {
response := &Response{
token: m.token,
to: to,
sendAPIVersion: m.sendAPIVersion,
}

return response.TextWithReplies(message, replies, messagingType, metadata, tags...)
return response.TextWithReplies(message, replies, messagingType, metadata, NotificationRegularType, tags...)
}

// Attachment sends an image, sound, video or a regular file to a given recipient.
Expand Down
9 changes: 9 additions & 0 deletions profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ type Profile struct {
Locale string `json:"locale"`
Timezone float64 `json:"timezone"`
Gender string `json:"gender"`

// instagram user profile
Username string `json:"username,omitempty"`
IsPrivate bool `json:"is_private,omitempty"`
// FollowCount int32 `json:"follow_count,omitempty"`
FollowedByCount int32 `json:"follower_count,omitempty"` // by the documentation followed_by_count
IsVerifiedUser bool `json:"is_verified_user"`
IsUserFollowBusiness bool `json:"is_user_follow_business"`
IsBusinessFollowUser bool `json:"is_business_follow_user"`
}
Loading
Loading