Compare commits

..

93 Commits

Author SHA1 Message Date
Wim
e45bbe4571 Release v1.22.3 (#1522)
* Release v1.22.3
2021-06-16 21:11:12 +02:00
Wim
fb5a84212c Update dependencies (#1521) 2021-06-16 21:00:49 +02:00
Nathanaël
dedc1c45a1 Update Rhymen/go-whatsapp module to latest master (2b8a3e9b8aa2) (#1518) 2021-06-16 20:35:09 +02:00
Wim
6a12f9ff84 Bump version 2021-06-02 00:05:46 +02:00
Wim
641ed1873b Release v1.22.2 (#1504) 2021-06-01 23:36:53 +02:00
Gary Kim
1d50da4b1c Add support for message deletion (nctalk) (#1492)
* nctalk: add message deletion support

Signed-off-by: Gary Kim <gary@garykim.dev>

* nctalk: seperate out deletion and sending logic

Signed-off-by: Gary Kim <gary@garykim.dev>

* nctalk: update library to v0.2.0

Signed-off-by: Gary Kim <gary@garykim.dev>

* Rename functions to be clearer

Signed-off-by: Gary Kim <gary@garykim.dev>

* Update to go-nc-talk v0.2.1

Signed-off-by: Gary Kim <gary@garykim.dev>

* Update to go-nc-talk v0.2.2

Signed-off-by: Gary Kim <gary@garykim.dev>

* Make deletions easier to debug

Signed-off-by: Gary Kim <gary@garykim.dev>
2021-06-01 23:17:07 +02:00
Wim
c7897cca5d Update irc references (#1499) 2021-05-30 00:38:13 +02:00
Wim
4091b6f6b4 Update vendor (#1498) 2021-05-30 00:25:30 +02:00
Gary Kim
766f35554e Fix content body issue for redactions (matrix) (#1496)
Signed-off-by: Gary Kim <gary@garykim.dev>
2021-05-29 23:47:36 +02:00
Wim
c86137449e Add a MessageClipped option to set your own clipped message. Closes #1359 (#1487) 2021-05-27 21:45:23 +02:00
Gary Kim
efec01a92f Support sending file URLs (nctalk) (#1489)
* nctalk: support sending file URLs

Signed-off-by: Gary Kim <gary@garykim.dev>

* nctalk: reduce nesting

Co-authored-by: Wim <wim@42.be>
Signed-off-by: Gary Kim <gary@garykim.dev>

Co-authored-by: Wim <wim@42.be>
2021-05-27 21:44:54 +02:00
Avinash Reddy
4fcad8e04b Make DocumentMessage handler use FileName attribute (whatsapp) (#1488)
* [whatsapp] make DocumentMessage handler use FileName attribute.

referenced: https://github.com/Rhymen/go-whatsapp/blob/master/message.go#L582

* fix lint
2021-05-26 00:06:45 +02:00
Chris Bobbe
4b4b2d790e Delete now-unused img/slack-setup-*.png files (#1491) 2021-05-25 03:51:52 +01:00
Avinash Reddy
ec6ae343dd Fix crash on encountering VideoMessage (whatsapp) (#1483)
* [whatsapp] fix crash on encountering VideoMessage

* Update handlers.go

* gofmt
2021-05-23 21:21:30 +02:00
Wim
b9fb361959 Rename .jpe files to .jpg Fixes #1463 (whatsapp) (#1485) 2021-05-23 00:17:55 +02:00
Avinash Reddy
a189298ab0 Handle document messages (whatsapp) (#1475)
* [Whatsapp] Add DocumentMessage handler

* Fix typo

Thanks @42wim :)

Co-authored-by: Wim <wim@42.be>

Co-authored-by: Wim <wim@42.be>
2021-05-21 22:50:47 +02:00
Jason Robinson
714a2ad730 Add MxId/Token login option for Matrix (#1438)
* Add possibility for using MxId/Token with Matrix

Makes it possible to configure a Matrix bot to use Matrix ID + Access token instead of username/password. This makes it possible to use the bot in environments where password login is disabled (for example SSO environments).

Matrix user ID's are commonly referred to as "MXID's". I thought about (ab)using "Login" here but it felt like a bad idea given it's used as "username" for the password login. None of the other configuration items felt fitting.

Closes #1429

* MxId -> MxID

* Add err != nil to matrix.NewClient
2021-05-17 00:10:13 +02:00
Funatiker
fa8b96dfa1 Add libwebp-dev to tgs.Dockerfile fixes Telegram sticker to WebP rendering (#1476) 2021-05-15 23:54:46 +02:00
Bill Mcilhargey
01955a0df8 Add additional variable for TGS conversion in sample config (#1472)
this was buried and wanted to bring it up in the config

Convert Tgs (Telegram animated sticker) images to PNG before upload.
This is useful when your bridge also contains platforms that do not support animated WebP files, like Discord.
This requires the external dependency `lottie`, which can be installed like this:
`pip install lottie cairosvg`
https://github.com/42wim/matterbridge/issues/874

https://github.com/42wim/matterbridge/pull/1173
2021-05-13 22:49:41 +02:00
Alexandre GV
ac4aee39e3 discord: Add AllowMention to restrict allowed mentions (#1462)
* Add DisablePingEveryoneHere/DisablePingRoles/DisablePingUsers keys to config

* Add basic AllowedMentions behavior to discord webhooks

* Initialize b.AllowedMentions on Discord Bridger init

* Call b.getAllowedMentions on each webhook to allow config hot reloading

* Add AllowedMentions on all Discord webhooks/messages

* Add DisablePingEveryoneHere/DisablePingRoles/DisablePingUsers to matterbridge.toml.sample

* Change 'Disable' for 'Allow' and revert logic in Discord AllowedMentions

* Update Discord AllowedMentions in matterbridge.toml.sample

* Fix typo in DisableWebPagePreview

* Replace 'AllowPingEveryoneHere' with 'AllowPingEveryone'

* Replace 3 AllowPingEveryone/Roles/Users bools with an array

* Fix typo
2021-05-13 22:39:25 +02:00
Wim
a0bca42a7a Update vendor (#1461)
* Update vendored libs

* Fix slack api changes
2021-05-05 22:03:28 +02:00
Sandro
af543dcd05 Follow up to 536823ce55 for the tgs.Dockerfile (#1448) 2021-05-03 23:47:36 +02:00
Wim
af77109a47 Bump version 2021-04-04 00:09:43 +02:00
Wim
b979aff270 Release v1.22.1 (#1447) 2021-04-03 23:55:06 +02:00
Paul
b293e3fa75 Adding caption to send telegram images. Fixes #1357 (#1358)
* Used tgbotapi caption option to attach caption to photos / documents

* remove "text/template/parse"

* added TGGetParseMode to clean up. Added tg upload function for video, audio and voice

* fixed varname Textout. Changed fileextension logic to avoid chaining regex

* fixed textout varname

* fixed parsemode varname

* gofmt

Co-authored-by: Wim <wim@42.be>
2021-04-03 23:15:19 +02:00
Wim
21eb37e471 Update vendor (#1446)
* Update vendor

* Use upstream emoji lib again
2021-04-03 19:16:46 +02:00
Millesimus
d3b60cc445 Add MatterBukkit and Forge / Bukkit distinction (#1444) 2021-04-02 23:40:04 +02:00
Wim
7466e1d014 Set ogg as default audiomessage when none found (whatsapp). Fixes #1427 (#1431) 2021-03-20 23:12:59 +01:00
James Lu
2a7f28606c Declare GUILD_MEMBERS privileged intent (discord) (#1428)
Without this declared, it seems that Discord will not send any member update
events after connection, even if the privileged gateway intent is enabled for
the bot in settings. This causes nick tracking to get out of sync when people
change their nicks after the bot connects.

See: https://discord.com/developers/docs/topics/gateway#gateway-intents
2021-03-20 22:46:36 +01:00
Ben Wiederhake
0450482e6e Make lottie_convert work on platforms without /dev/stdout (#1424)
Fixes #1423.
2021-03-20 22:42:41 +01:00
Wim
ee5d9b43b5 Update vendor (#1414) 2021-03-20 22:40:23 +01:00
powerjungle
3a8857c8c9 Add Facebook messenger api bridge URL to README.md (#1425) 2021-03-13 22:06:01 +01:00
Wim
be3dfb251d Check rune length instead of bytes (telegram). Fixes #1409 (#1412) 2021-02-25 23:28:54 +01:00
Wim
4e11e29f70 Use go1.16 as binary builder. Remove go1.14 (#1407) 2021-02-17 21:37:14 +01:00
Alexander
763bb95cea Fix webhooks for channels with special characters (xmpp) (#1405) 2021-02-17 21:30:06 +01:00
Qais Patankar
668e7407e6 Change workflow from go 1.16.0-rc1 to go 1.16.x (#1406) 2021-02-17 21:14:21 +01:00
Tadeo Kondrak
c147ba1da1 Handle Rocket.Chat attachments (#1395) 2021-02-15 22:34:14 +01:00
Qais Patankar
10f044c3dd Use valid transmitter Log default (discord) (#1402)
* Use valid transmitter Log default (discord)

Using a logger created by `log.NewEntry(nil)` would crash. (matterbridge does not encounter this issue as it updates the Log field manually.)
2021-02-15 22:20:08 +01:00
Alexander
ce5140febd Fix panic when the webhook fails (xmpp) (#1401) 2021-02-15 22:18:30 +01:00
PeGaSuS
858cdc86f5 Fix missing word in matterbridge.toml.sample (#1398)
Co-authored-by: Qais Patankar <qaisjp@gmail.com>
2021-02-11 13:11:59 +00:00
Wim
9a25297d51 Add scoop repo 2021-02-02 01:02:36 +01:00
Wim
e24f7f5151 Add go 1.16.0-rc1 to github workflow (#1386) 2021-02-02 00:05:12 +01:00
Wim
eff5f1e119 Bump version 2021-02-01 23:59:35 +01:00
Wim
afcd362cd1 Release v1.22.0 (#1385) 2021-02-01 23:44:17 +01:00
Wim
0452be0cb3 Update vendor (#1384) 2021-02-01 21:29:04 +01:00
Wim
1624f10773 Pick up all the webhooks (discord) (#1383) 2021-02-01 20:44:34 +01:00
Ivanik
8764be7461 Add vk bridge (#1372)
* Add vk bridge

* Vk bridge attachments

* Vk bridge forwarded messages

* Vk bridge sample config and code cleanup

* Vk bridge add vendor

* Vk bridge message edit

* Vk bridge: fix fetching names of other bots

* Vk bridge: code cleanup

* Vk bridge: fix shadows declaration

* Vk bridge: remove UseFileURL
2021-01-29 00:25:14 +01:00
Wim
5dd15ef8e7 Add an even more debug option (discord) (#1368)
Enable discordgo debugging with debuglevel=1 under the [discord.xxx] section, for even more debugging fun.
2021-01-23 00:09:56 +01:00
Alexander
4ac6366706 Allow the XMPP bridge to use slack compatible webhooks (xmpp) (#1364)
* Add mod_slack_webhook support to the XMPP bridge

* Replace b.webhookURL with b.GetString

* Do not return a message ID on webhook POST

* Add the XMPP webhook to the sample configuration
2021-01-21 22:50:04 +01:00
Wim
adc0912efa Update README (#1362) 2021-01-15 23:21:48 +01:00
Wim
536823ce55 Optimize Dockerfile (#1361) 2021-01-15 22:44:01 +01:00
Peter Dave Hello
207cd24edb Unify/sync apk index cache control in Dockerfile (#1352)
The second stage is using a single `apk` command with `--no-cache` which is better.
2021-01-14 23:48:02 +01:00
Paul
b039da1eba Add jpe as valid image filename extension (telegram) (#1360) 2021-01-14 23:42:13 +01:00
Qais Patankar
8fcd0f3b6f Improve Markdown in transmitter docs (discord) (#1351) 2021-01-03 18:57:06 +00:00
Wim
16fde6935c Rename .oga audio files to .ogg (telegram) (#1349) 2021-01-02 00:55:20 +01:00
Wim
9592cff9fa Update README about unsupported steam chat 2021-01-02 00:12:10 +01:00
Wim
109148988c Bump version 2020-12-31 23:42:41 +01:00
Wim
cf13fff7d2 Release v1.21.0 (#1348) 2020-12-31 22:32:13 +01:00
Qais Patankar
a9d8ac8bc0 Refactor "msg-parent-not-found" to config.ParentIDNotFound (#1347) 2020-12-31 18:01:57 +00:00
Qais Patankar
1a4717b366 Reject cross-channel message references (discord) (#1345)
Discord message references have been designed in a way for this to
support cross-channel or even cross-guild references in the future.

This will ensure the ParentID is *not* set when the message refers to a
message that was sent in a different channel.
2020-12-31 16:21:37 +00:00
Qais Patankar
6cadf12260 Add a prefix handler for unthreaded messages (discord) (#1346) 2020-12-31 16:15:42 +00:00
Wim
19d47784bd Add threading support with token (discord) (#1342)
Webhooks don't support the threading yet, so this is token only.
In discord you can reply on each message of a thread, but this is not possible in mattermost (so some changes added there to make sure we always answer on the rootID of the thread).

Also needs some more testing with slack.

update : It now also uses the token when replying to a thread (even if webhooks are enabled), until webhooks have support for threads.
2020-12-31 16:59:47 +01:00
Qais Patankar
b89102c5fc Fix 'webook' typo in discord/webhook.go (#1344) 2020-12-31 16:51:49 +01:00
Wim
4f20ebead3 Update vendor for next release (#1343) 2020-12-31 14:48:12 +01:00
James Lu
a9f89dbc64 Add support for stateless bridging via draft/relaymsg (irc) (#1339)
* irc: add support for stateless bridging via draft/relaymsg

As discussed at https://github.com/42wim/matterbridge/issues/667#issuecomment-634214165

* irc: handle the draft/relaymsg tag in spoofed messages too

* Apply suggestions from code review

Co-authored-by: Wim <wim@42.be>

* Run gofmt on irc.go

* Document relaymsg in matterbridge.toml.sample

Co-authored-by: Wim <wim@42.be>
2020-12-30 18:21:32 +01:00
wschwab
58ea1e07d2 Update README.md (#1340)
added using `chmod a+x` to make the binary executable in the installation section
2020-12-29 20:42:00 +01:00
Qais Patankar
6de4c7e971 Update webhook documentation (discord) (#1335) 2020-12-17 20:27:52 +01:00
Qais Patankar
03dc51ffa2 Split Bdiscord.Send into handleEventWebhook and handleEventBotUser (discord) 2020-12-13 23:19:48 +01:00
Qais Patankar
aef2dcdfdd Move webhook specific logic to its own file (discord) 2020-12-13 23:19:48 +01:00
Qais Patankar
0494119bf4 Extract maybeGetLocalAvatar into its own function (discord) 2020-12-13 23:19:48 +01:00
Qais Patankar
0a17e21119 Remove WebhookURL support (discord) 2020-12-13 23:19:48 +01:00
Qais Patankar
52e2f926f4 Add initial transmitter implementation (discord)
This has been tested with one webhook in one channel.

Sends, edits and deletions work fine
2020-12-13 23:19:48 +01:00
Qais Patankar
611fb279bc Revert "Disable webhook editing (#1296)" (discord)
This reverts commit c23252ab53.
2020-12-13 23:19:48 +01:00
Gary Kim
41b4e64be9 Update go-nc-talk (nctalk) (#1333)
Signed-off-by: Gary Kim <gary@garykim.dev>
2020-12-10 00:06:27 +01:00
Wim
0d7315249d Update vendor (#1330) 2020-12-06 23:16:02 +01:00
Wim
4913766d58 Parse fencedcode in ParseMarkdown. Fixes #1127 (#1329) 2020-12-06 19:38:32 +01:00
Wim
92da8c7044 Mark messages as read (matrix). Fixes #1317 (#1328) 2020-12-06 17:49:35 +01:00
Wim
9dba3d5385 Update rocketchat vendor (#1327)
Contains fixes for #992 and adds more random ID
2020-12-06 17:23:37 +01:00
Wim
2d3c26a4b2 Implement ratelimiting (matrix). Fixes #1238 (#1326) 2020-12-06 17:18:25 +01:00
Wim
8eba2d3e50 Make handlers run async (irc) (#1325)
This makes the handlers run in a seperate go-routine in girc, and makes
sure that girc isn't blocked on executing PONG requests when
matterbridge takes a long time handling the incoming message.

This can happen when another bridge is in a backoff state where the
backoff time exceeds the IRC ping timeout.
2020-12-05 21:41:45 +01:00
Qais Patankar
a8d4a27de1 Remove locale from golangci misspell (#1324) 2020-12-05 15:22:23 +01:00
Qais Patankar
c42167c6f4 Refactor guild finding code (discord) (#1319) 2020-12-03 22:36:08 +01:00
Sebastian P
44d182e2f9 Add nil checks to text message handling (mumble) (#1321) 2020-12-03 22:25:33 +01:00
Wim
ad95e35687 Rename jfif to jpg (whatsapp). Fixes #1292 2020-11-29 15:37:20 +01:00
Wim
640a9995f4 Refactor handleTextMessage (whatsapp) 2020-11-29 15:37:20 +01:00
Wim
95625f6871 Refactor image downloads (whatsapp) 2020-11-29 15:37:20 +01:00
Wim
2c20f72a9c Handle audio downloads (whatsapp) 2020-11-29 15:37:20 +01:00
Wim
5ad788e768 Handle video downloads (whatsapp) 2020-11-29 15:37:20 +01:00
Wim
ed98c586c6 Add support for deleting messages (whatsapp) 2020-11-29 15:37:20 +01:00
Wim
3e865708d6 Refactor/cleanup code (whatsapp) 2020-11-29 15:37:20 +01:00
JeremyRand
c3bcbd63c0 Add UserID to RemoteNickFormat and Tengo (#1308)
* Add UserID to RemoteNickFormat and Tengo

* Use strings.ReplaceAll in gateway.modifyUsername

Fixes a warning from gocritic linter.

* Use Unicode escape sequence instead of raw ZWSP in gateway.modifyUsername

Fixes a warning from stylecheck linter.
2020-11-25 23:54:27 +01:00
Simon THOBY
29e29439ee Show mxids in case of clashing usernames (matrix) (#1309)
Fixes #1302.
2020-11-25 23:51:23 +01:00
Wim
0c19716f44 Join on invite (irc). Fixes #1231 (#1306) 2020-11-22 22:44:15 +01:00
1018 changed files with 101705 additions and 30877 deletions

View File

@@ -16,7 +16,7 @@ jobs:
test-build-upload:
strategy:
matrix:
go-version: [1.14.x, 1.15.x]
go-version: [1.15.x, 1.16.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
@@ -24,6 +24,7 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
stable: false
- name: Checkout code
uses: actions/checkout@v2
with:
@@ -34,23 +35,23 @@ jobs:
run: |
mkdir -p output/{win,lin,arm,mac}
VERSION=$(git describe --tags)
GOOS=linux GOARCH=amd64 go build -mod=vendor -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/lin/matterbridge-$VERSION-linux-amd64
GOOS=windows GOARCH=amd64 go build -mod=vendor -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/win/matterbridge-$VERSION-windows-amd64.exe
GOOS=darwin GOARCH=amd64 go build -mod=vendor -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/mac/matterbridge-$VERSION-darwin-amd64
GOOS=linux GOARCH=amd64 go build -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/lin/matterbridge-$VERSION-linux-amd64
GOOS=windows GOARCH=amd64 go build -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/win/matterbridge-$VERSION-windows-amd64.exe
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/mac/matterbridge-$VERSION-darwin-amd64
- name: Upload linux 64-bit
if: startsWith(matrix.go-version,'1.15')
if: startsWith(matrix.go-version,'1.16')
uses: actions/upload-artifact@v2
with:
name: matterbridge-linux-64bit
path: output/lin
- name: Upload windows 64-bit
if: startsWith(matrix.go-version,'1.15')
if: startsWith(matrix.go-version,'1.16')
uses: actions/upload-artifact@v2
with:
name: matterbridge-windows-64bit
path: output/win
- name: Upload darwin 64-bit
if: startsWith(matrix.go-version,'1.15')
if: startsWith(matrix.go-version,'1.16')
uses: actions/upload-artifact@v2
with:
name: matterbridge-darwin-64bit

View File

@@ -91,7 +91,6 @@ linters-settings:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
locale: US
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option

View File

@@ -1,11 +1,9 @@
FROM alpine AS builder
COPY . /go/src/github.com/42wim/matterbridge
RUN apk update && apk add go git gcc musl-dev \
&& cd /go/src/github.com/42wim/matterbridge \
&& export GOPATH=/go \
&& go get \
&& go build -x -ldflags "-X main.githash=$(git log --pretty=format:'%h' -n 1)" -o /bin/matterbridge
COPY . /go/src/matterbridge
RUN apk --no-cache add go git \
&& cd /go/src/matterbridge \
&& go build -mod vendor -ldflags "-X main.githash=$(git log --pretty=format:'%h' -n 1)" -o /bin/matterbridge
FROM alpine
RUN apk --no-cache add ca-certificates mailcap

View File

@@ -70,7 +70,7 @@ And more...
- [Changelog](#changelog)
- [FAQ](#faq)
- [Related projects](#related-projects)
- [Articles](#articles)
- [Articles / Tutorials](#articles--tutorials)
- [Thanks](#thanks)
## Features
@@ -91,16 +91,18 @@ And more...
- [IRC](http://www.mirc.com/servers.html)
- [Keybase](https://keybase.io)
- [Matrix](https://matrix.org)
- [Mattermost](https://github.com/mattermost/mattermost-server/) 4.x, 5.x
- [Mattermost](https://github.com/mattermost/mattermost-server/)
- [Microsoft Teams](https://teams.microsoft.com)
- [Mumble](https://www.mumble.info/)
- [Nextcloud Talk](https://nextcloud.com/talk/)
- [Rocket.chat](https://rocket.chat)
- [Slack](https://slack.com)
- [Ssh-chat](https://github.com/shazow/ssh-chat)
- [Steam](https://store.steampowered.com/)
- ~~[Steam](https://store.steampowered.com/)~~
- Not supported anymore, see [here](https://github.com/Philipp15b/go-steam/issues/94) for more info.
- [Telegram](https://telegram.org)
- [Twitch](https://twitch.tv)
- [VK](https://vk.com/)
- [WhatsApp](https://www.whatsapp.com/)
- [XMPP](https://xmpp.org)
- [Zulip](https://zulipchat.com)
@@ -108,11 +110,15 @@ And more...
### 3rd party via matterbridge api
- [Discourse](https://github.com/DeclanHoare/matterbabble)
- [Facebook messenger](https://github.com/powerjungle/fbridge-asyncio)
- [Facebook messenger](https://github.com/VictorNine/fbridge)
- [Minecraft](https://github.com/elytra/MatterLink)
- [Minecraft](https://github.com/raws/mattercraft)
- [Minecraft](https://gitlab.com/Programie/MatterBukkit)
- [Reddit](https://github.com/bonehurtingjuice/mattereddit)
- [Counter-Strike, half-life and more](https://forums.alliedmods.net/showthread.php?t=319430)
- [MatterAMXX](https://github.com/GabeIggy/MatterAMXX)
- [Vintage Story](https://github.com/NikkyAI/vs-matterbridge)
### API
@@ -121,12 +127,16 @@ More info and examples on the [wiki](https://github.com/42wim/matterbridge/wiki/
Used by the projects below. Feel free to make a PR to add your project to this list.
- [MatterLink](https://github.com/elytra/MatterLink) (Matterbridge link for Minecraft Server chat)
- [MatterLink](https://github.com/elytra/MatterLink) (Matterbridge link for Minecraft Forge server chat, archived)
- [MatterCraft](https://github.com/raws/mattercraft) (Matterbridge link for Minecraft Forge server chat)
- [MatterBukkit](https://gitlab.com/Programie/MatterBukkit) (Matterbridge link for Minecraft Bukkit/Spigot server chat)
- [pyCord](https://github.com/NikkyAI/pyCord) (crossplatform chatbot)
- [Mattereddit](https://github.com/bonehurtingjuice/mattereddit) (Reddit chat support)
- [fbridge-asyncio](https://github.com/powerjungle/fbridge-asyncio) (Facebook messenger support)
- [fbridge](https://github.com/VictorNine/fbridge) (Facebook messenger support)
- [matterbabble](https://github.com/DeclanHoare/matterbabble) (Discourse support)
- [MatterAMXX](https://forums.alliedmods.net/showthread.php?t=319430) (Counter-Strike, half-life and more via AMXX mod)
- [Vintage Story](https://github.com/NikkyAI/vs-matterbridge)
## Chat with us
@@ -153,22 +163,23 @@ See <https://github.com/42wim/matterbridge/wiki>
### Binaries
- Latest stable release [v1.20.0](https://github.com/42wim/matterbridge/releases/latest)
- Latest stable release [v1.22.3](https://github.com/42wim/matterbridge/releases/latest)
- Development releases (follows master) can be downloaded [here](https://github.com/42wim/matterbridge/actions) selecting the latest green build and then artifacts.
To install or upgrade just download the latest [binary](https://github.com/42wim/matterbridge/releases/latest) and follow the instructions on the [howto](https://github.com/42wim/matterbridge/wiki/How-to-create-your-config) for a step by step walkthrough for creating your configuration.
To install or upgrade just download the latest [binary](https://github.com/42wim/matterbridge/releases/latest). On \*nix platforms you may need to make the binary executable - you can do this by running `chmod a+x` on the binary (example: `chmod a+x matterbridge-1.20.0-linux-64bit`). After downloading (and making the binary executable, if necessary), follow the instructions on the [howto](https://github.com/42wim/matterbridge/wiki/How-to-create-your-config) for a step by step walkthrough for creating your configuration.
### Packages
- [Overview](https://repology.org/metapackage/matterbridge/versions)
- [snap](https://snapcraft.io/matterbridge)
- [scoop](https://github.com/42wim/scoop-bucket)
## Building
Most people just want to use binaries, you can find those [here](https://github.com/42wim/matterbridge/releases/latest)
If you really want to build from source, follow these instructions:
Go 1.12+ is required. Make sure you have [Go](https://golang.org/doc/install) properly installed.
Go 1.13+ is required. Make sure you have [Go](https://golang.org/doc/install) properly installed.
```bash
go get github.com/42wim/matterbridge
@@ -201,8 +212,8 @@ All possible [settings](https://github.com/42wim/matterbridge/wiki/Settings) for
```toml
[irc]
[irc.freenode]
Server="irc.freenode.net:6667"
[irc.libera]
Server="irc.libera.chat:6667"
Nick="yourbotname"
[mattermost]
@@ -218,7 +229,7 @@ All possible [settings](https://github.com/42wim/matterbridge/wiki/Settings) for
name="mygateway"
enable=true
[[gateway.inout]]
account="irc.freenode"
account="irc.libera"
channel="#testing"
[[gateway.inout]]
@@ -296,8 +307,11 @@ See [FAQ](https://github.com/42wim/matterbridge/wiki/FAQ)
- [fbridge](https://github.com/VictorNine/fbridge) (Facebook messenger support)
- [isla](https://github.com/alphachung/isla) (Bot for Discord-Telegram groups used alongside matterbridge)
- [matterbabble](https://github.com/DeclanHoare/matterbabble) (Connect Discourse threads to Matterbridge)
- [nextcloud talk](https://github.com/nextcloud/talk_matterbridge) (Integrates matterbridge in Nextcloud Talk)
- [mattercraft](https://github.com/raws/mattercraft) (Minecraft bridge)
- [vs-matterbridge](https://github.com/NikkyAI/vs-matterbridge) (Vintage Story bridge)
## Articles
## Articles / Tutorials
- [matterbridge on kubernetes](https://medium.freecodecamp.org/using-kubernetes-to-deploy-a-chat-gateway-or-when-technology-works-like-its-supposed-to-a169a8cd69a3)
- <https://mattermost.com/blog/connect-irc-to-mattermost/>
@@ -308,6 +322,8 @@ See [FAQ](https://github.com/42wim/matterbridge/wiki/FAQ)
- <https://www.stitcher.com/s/?eid=52382713>
- <https://daniele.tech/2019/02/how-to-use-matterbridge-to-connect-2-different-slack-workspaces/>
- <https://userlinux.net/mattermost-and-matterbridge.html>
- <https://nextcloud.com/blog/bridging-chat-services-in-talk/>
- Youtube: [whatsapp - telegram bridging](https://www.youtube.com/watch?v=W-VXISoKtNc)
## Thanks
@@ -338,6 +354,7 @@ Matterbridge wouldn't exist without these libraries:
- steam - <https://github.com/Philipp15b/go-steam>
- telegram - <https://github.com/go-telegram-bot-api/telegram-bot-api>
- tengo - <https://github.com/d5/tengo>
- vk - <https://github.com/SevereCloud/vksdk>
- whatsapp - <https://github.com/Rhymen/go-whatsapp>
- xmpp - <https://github.com/mattn/go-xmpp>
- zulip - <https://github.com/ifo/gozulipbot>
@@ -346,7 +363,7 @@ Matterbridge wouldn't exist without these libraries:
[mb-discord]: https://discord.gg/AkKPtrQ
[mb-gitter]: https://gitter.im/42wim/matterbridge
[mb-irc]: https://webchat.freenode.net/?channels=matterbridgechat
[mb-irc]: https://web.libera.chat/#matterbridge
[mb-keybase]: https://keybase.io/team/matterbridge
[mb-matrix]: https://riot.im/app/#/room/#matterbridge:matrix.org
[mb-mattermost]: https://framateam.org/signup_user_complete/?id=tfqm33ggop8x3qgu4boeieta6e

View File

@@ -29,6 +29,8 @@ const (
EventNoticeIRC = "notice_irc"
)
const ParentIDNotFound = "msg-parent-not-found"
type Message struct {
Text string `json:"text"`
Channel string `json:"channel"`
@@ -45,6 +47,14 @@ type Message struct {
Extra map[string][]interface{}
}
func (m Message) ParentNotFound() bool {
return m.ParentID == ParentIDNotFound
}
func (m Message) ParentValid() bool {
return m.ParentID != "" && !m.ParentNotFound()
}
type FileInfo struct {
Name string
Data *[]byte
@@ -75,27 +85,28 @@ type ChannelMember struct {
type ChannelMembers []ChannelMember
type Protocol struct {
AuthCode string // steam
BindAddress string // mattermost, slack // DEPRECATED
Buffer int // api
Charset string // irc
ClientID string // msteams
ColorNicks bool // only irc for now
Debug bool // general
DebugLevel int // only for irc now
DisableWebPagePreview bool // telegram
EditSuffix string // mattermost, slack, discord, telegram, gitter
EditDisable bool // mattermost, slack, discord, telegram, gitter
HTMLDisable bool // matrix
IconURL string // mattermost, slack
IgnoreFailureOnStart bool // general
IgnoreNicks string // all protocols
IgnoreMessages string // all protocols
Jid string // xmpp
JoinDelay string // all protocols
Label string // all protocols
Login string // mattermost, matrix
LogFile string // general
AllowMention []string // discord
AuthCode string // steam
BindAddress string // mattermost, slack // DEPRECATED
Buffer int // api
Charset string // irc
ClientID string // msteams
ColorNicks bool // only irc for now
Debug bool // general
DebugLevel int // only for irc now
DisableWebPagePreview bool // telegram
EditSuffix string // mattermost, slack, discord, telegram, gitter
EditDisable bool // mattermost, slack, discord, telegram, gitter
HTMLDisable bool // matrix
IconURL string // mattermost, slack
IgnoreFailureOnStart bool // general
IgnoreNicks string // all protocols
IgnoreMessages string // all protocols
Jid string // xmpp
JoinDelay string // all protocols
Label string // all protocols
Login string // mattermost, matrix
LogFile string // general
MediaDownloadBlackList []string
MediaDownloadPath string // Basically MediaServerUpload, but instead of uploading it, just write it to a file on the same server.
MediaDownloadSize int // all protocols
@@ -109,6 +120,7 @@ type Protocol struct {
MessageQueue int // IRC, size of message queue for flood control
MessageSplit bool // IRC, split long messages with newlines on MessageLength instead of clipping
Muc string // xmpp
MxID string // matrix
Name string // all protocols
Nick string // all protocols
NickFormatter string // mattermost, slack
@@ -131,7 +143,7 @@ type Protocol struct {
ReplaceNicks [][]string // all protocols
RemoteNickFormat string // all protocols
RunCommands []string // IRC
Server string // IRC,mattermost,XMPP,discord
Server string // IRC,mattermost,XMPP,discord,matrix
SessionFile string // msteams,whatsapp
ShowJoinPart bool // all protocols
ShowTopicChange bool // slack
@@ -146,7 +158,7 @@ type Protocol struct {
Team string // mattermost, keybase
TeamID string // msteams
TenantID string // msteams
Token string // gitter, slack, discord, api
Token string // gitter, slack, discord, api, matrix
Topic string // zulip
URL string // mattermost, slack // DEPRECATED
UseAPI bool // mattermost, slack

View File

@@ -2,13 +2,13 @@ package bdiscord
import (
"bytes"
"errors"
"fmt"
"strings"
"sync"
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/discord/transmitter"
"github.com/42wim/matterbridge/bridge/helper"
"github.com/matterbridge/discordgo"
)
@@ -20,12 +20,9 @@ type Bdiscord struct {
c *discordgo.Session
nick string
userID string
guildID string
webhookID string
webhookToken string
canEditWebhooks bool
nick string
userID string
guildID string
channelsMutex sync.RWMutex
channels []*discordgo.Channel
@@ -34,6 +31,10 @@ type Bdiscord struct {
membersMutex sync.RWMutex
userMemberMap map[string]*discordgo.Member
nickMemberMap map[string]*discordgo.Member
// Webhook specific logic
useAutoWebhooks bool
transmitter *transmitter.Transmitter
}
func New(cfg *bridge.Config) bridge.Bridger {
@@ -41,23 +42,18 @@ func New(cfg *bridge.Config) bridge.Bridger {
b.userMemberMap = make(map[string]*discordgo.Member)
b.nickMemberMap = make(map[string]*discordgo.Member)
b.channelInfoMap = make(map[string]*config.ChannelInfo)
if b.GetString("WebhookURL") != "" {
b.Log.Debug("Configuring Discord Incoming Webhook")
b.webhookID, b.webhookToken = b.splitURL(b.GetString("WebhookURL"))
b.useAutoWebhooks = b.GetBool("AutoWebhooks")
if b.useAutoWebhooks {
b.Log.Debug("Using automatic webhooks")
}
return b
}
func (b *Bdiscord) Connect() error {
var err error
var guildFound bool
token := b.GetString("Token")
b.Log.Info("Connecting")
if b.GetString("WebhookURL") == "" {
b.Log.Info("Connecting using token")
} else {
b.Log.Info("Connecting using webhookurl (for posting) and token")
}
if !strings.HasPrefix(b.GetString("Token"), "Bot ") {
token = "Bot " + b.GetString("Token")
}
@@ -79,6 +75,11 @@ func (b *Bdiscord) Connect() error {
b.c.AddHandler(b.messageDeleteBulk)
b.c.AddHandler(b.memberAdd)
b.c.AddHandler(b.memberRemove)
// Add privileged intent for guild member tracking. This is needed to track nicks
// for display names and @mention translation
b.c.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsAllWithoutPrivileged |
discordgo.IntentsGuildMembers)
err = b.c.Open()
if err != nil {
return err
@@ -94,66 +95,107 @@ func (b *Bdiscord) Connect() error {
serverName := strings.Replace(b.GetString("Server"), "ID:", "", -1)
b.nick = userinfo.Username
b.userID = userinfo.ID
// Try and find this account's guild, and populate channels
b.channelsMutex.Lock()
for _, guild := range guilds {
if guild.Name == serverName || guild.ID == serverName {
b.channels, err = b.c.GuildChannels(guild.ID)
if err != nil {
break
}
b.guildID = guild.ID
guildFound = true
// Skip, if the server name does not match the visible name or the ID
if guild.Name != serverName && guild.ID != serverName {
continue
}
// Complain about an ambiguous Server setting. Two Discord servers could have the same title!
// For IDs, practically this will never happen. It would only trigger if some server's name is also an ID.
if b.guildID != "" {
return fmt.Errorf("found multiple Discord servers with the same name %#v, expected to see only one", serverName)
}
// Getting this guild's channel could result in a permission error
b.channels, err = b.c.GuildChannels(guild.ID)
if err != nil {
return fmt.Errorf("could not get %#v's channels: %w", b.GetString("Server"), err)
}
b.guildID = guild.ID
}
b.channelsMutex.Unlock()
if !guildFound {
msg := fmt.Sprintf("Server \"%s\" not found", b.GetString("Server"))
err = errors.New(msg)
b.Log.Error(msg)
b.Log.Info("Possible values:")
// If we couldn't find a guild, we print extra debug information and return a nice error
if b.guildID == "" {
err = fmt.Errorf("could not find Discord server %#v", b.GetString("Server"))
b.Log.Error(err.Error())
// Print all of the possible server values
b.Log.Info("Possible server values:")
for _, guild := range guilds {
b.Log.Infof("Server=\"%s\" # Server name", guild.Name)
b.Log.Infof("Server=\"%s\" # Server ID", guild.ID)
b.Log.Infof("\t- Server=%#v # by name", guild.Name)
b.Log.Infof("\t- Server=%#v # by ID", guild.ID)
}
}
if err != nil {
// If there are no results, we should say that
if len(guilds) == 0 {
b.Log.Info("\t- (none found)")
}
return err
}
b.channelsMutex.RLock()
if b.GetString("WebhookURL") == "" {
for _, channel := range b.channels {
b.Log.Debugf("found channel %#v", channel)
}
} else {
manageWebhooks := discordgo.PermissionManageWebhooks
var channelsDenied []string
for _, info := range b.Channels {
id := b.getChannelID(info.Name) // note(qaisjp): this readlocks channelsMutex
b.Log.Debugf("Verifying PermissionManageWebhooks for %s with ID %s", info.ID, id)
perms, permsErr := b.c.UserChannelPermissions(userinfo.ID, id)
if permsErr != nil {
b.Log.Warnf("Failed to check PermissionManageWebhooks in channel \"%s\": %s", info.Name, permsErr.Error())
} else if perms&manageWebhooks == manageWebhooks {
continue
}
channelsDenied = append(channelsDenied, fmt.Sprintf("%#v", info.Name))
}
b.canEditWebhooks = len(channelsDenied) == 0
b.canEditWebhooks = false
b.Log.Info("Webhook editing is disabled because of ratelimit issues")
/*
if b.canEditWebhooks {
b.Log.Info("Can manage webhooks; will edit channel for global webhook on send")
} else {
b.Log.Warn("Can't manage webhooks; won't edit channel for global webhook on send")
b.Log.Warn("Can't manage webhooks in channels: ", strings.Join(channelsDenied, ", "))
}
*/
// Legacy note: WebhookURL used to have an actual webhook URL that we would edit,
// but we stopped doing that due to Discord making rate limits more aggressive.
//
// Even older: the same WebhookURL used to be used by every channel, which is usually unexpected.
// This is no longer possible.
if b.GetString("WebhookURL") != "" {
message := "The global WebhookURL setting has been removed. "
message += "You can get similar \"webhook editing\" behaviour by replacing this line with `AutoWebhooks=true`. "
message += "If you rely on the old-OLD (non-editing) behaviour, can move the WebhookURL to specific channel sections."
b.Log.Errorln(message)
return fmt.Errorf("use of removed WebhookURL setting")
}
if b.GetInt("debuglevel") > 0 {
b.Log.Debug("enabling even more discord debug")
b.c.Debug = true
}
// Initialise webhook management
b.transmitter = transmitter.New(b.c, b.guildID, "matterbridge", b.useAutoWebhooks)
b.transmitter.Log = b.Log
var webhookChannelIDs []string
for _, channel := range b.Channels {
channelID := b.getChannelID(channel.Name) // note(qaisjp): this readlocks channelsMutex
// If a WebhookURL was not explicitly provided for this channel,
// there are two options: just a regular bot message (ugly) or this is should be webhook sent
if channel.Options.WebhookURL == "" {
// If it should be webhook sent, we should enforce this via the transmitter
if b.useAutoWebhooks {
webhookChannelIDs = append(webhookChannelIDs, channelID)
}
continue
}
whID, whToken, ok := b.splitURL(channel.Options.WebhookURL)
if !ok {
return fmt.Errorf("failed to parse WebhookURL %#v for channel %#v", channel.Options.WebhookURL, channel.ID)
}
b.transmitter.AddWebhook(channelID, &discordgo.Webhook{
ID: whID,
Token: whToken,
GuildID: b.guildID,
ChannelID: channelID,
})
}
if b.useAutoWebhooks {
err = b.transmitter.RefreshGuildWebhooks(webhookChannelIDs)
if err != nil {
b.Log.WithError(err).Println("transmitter could not refresh guild webhooks")
return err
}
}
b.channelsMutex.RUnlock()
// Obtaining guild members and initializing nickname mapping.
b.membersMutex.Lock()
@@ -210,80 +252,23 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
msg.Text = "_" + msg.Text + "_"
}
// use initial webhook configured for the entire Discord account
isGlobalWebhook := true
wID := b.webhookID
wToken := b.webhookToken
// check if have a channel specific webhook
b.channelsMutex.RLock()
if ci, ok := b.channelInfoMap[msg.Channel+b.Account]; ok {
if ci.Options.WebhookURL != "" {
wID, wToken = b.splitURL(ci.Options.WebhookURL)
isGlobalWebhook = false
}
// Handle prefix hint for unthreaded messages.
if msg.ParentNotFound() {
msg.ParentID = ""
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
}
b.channelsMutex.RUnlock()
// Use webhook to send the message
if wID != "" && msg.Event != config.EventMsgDelete {
// skip events
if msg.Event != "" && msg.Event != config.EventUserAction && msg.Event != config.EventJoinLeave && msg.Event != config.EventTopicChange {
return "", nil
}
// skip empty messages
if msg.Text == "" && (msg.Extra == nil || len(msg.Extra["file"]) == 0) {
b.Log.Debugf("Skipping empty message %#v", msg)
return "", nil
}
msg.Text = helper.ClipMessage(msg.Text, MessageLength)
msg.Text = b.replaceUserMentions(msg.Text)
// discord username must be [0..32] max
if len(msg.Username) > 32 {
msg.Username = msg.Username[0:32]
}
if msg.ID != "" {
b.Log.Debugf("Editing webhook message")
uri := discordgo.EndpointWebhookToken(wID, wToken) + "/messages/" + msg.ID
_, err := b.c.RequestWithBucketID("PATCH", uri, discordgo.WebhookParams{
Content: msg.Text,
Username: msg.Username,
}, discordgo.EndpointWebhookToken("", ""))
if err == nil {
return msg.ID, nil
}
b.Log.Errorf("Could not edit webhook message: %s", err)
}
b.Log.Debugf("Broadcasting using Webhook")
// if we have a global webhook for this Discord account, and permission
// to modify webhooks (previously verified), then set its channel to
// the message channel before using it.
if isGlobalWebhook && b.canEditWebhooks {
b.Log.Debugf("Setting webhook channel to \"%s\"", msg.Channel)
_, err := b.c.WebhookEdit(wID, "", "", channelID)
if err != nil {
b.Log.Errorf("Could not set webhook channel: %s", err)
return "", err
}
}
b.Log.Debugf("Processing webhook sending for message %#v", msg)
msg, err := b.webhookSend(&msg, wID, wToken)
if err != nil {
b.Log.Errorf("Could not broadcast via webook for message %#v: %s", msg, err)
return "", err
}
if msg == nil {
return "", nil
}
return msg.ID, nil
useWebhooks := b.shouldMessageUseWebhooks(&msg)
if useWebhooks && msg.Event != config.EventMsgDelete && msg.ParentID == "" {
return b.handleEventWebhook(&msg, channelID)
}
return b.handleEventBotUser(&msg, channelID)
}
// handleEventDirect handles events via the bot user
func (b *Bdiscord) handleEventBotUser(msg *config.Message, channelID string) (string, error) {
b.Log.Debugf("Broadcasting using token (API)")
// Delete message
@@ -297,19 +282,19 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
// Upload a file if it exists
if msg.Extra != nil {
for _, rmsg := range helper.HandleExtra(&msg, b.General) {
rmsg.Text = helper.ClipMessage(rmsg.Text, MessageLength)
for _, rmsg := range helper.HandleExtra(msg, b.General) {
rmsg.Text = helper.ClipMessage(rmsg.Text, MessageLength, b.GetString("MessageClipped"))
if _, err := b.c.ChannelMessageSend(channelID, rmsg.Username+rmsg.Text); err != nil {
b.Log.Errorf("Could not send message %#v: %s", rmsg, err)
}
}
// check if we have files to upload (from slack, telegram or mattermost)
if len(msg.Extra["file"]) > 0 {
return b.handleUploadFile(&msg, channelID)
return b.handleUploadFile(msg, channelID)
}
}
msg.Text = helper.ClipMessage(msg.Text, MessageLength)
msg.Text = helper.ClipMessage(msg.Text, MessageLength, b.GetString("MessageClipped"))
msg.Text = b.replaceUserMentions(msg.Text)
// Edit message
@@ -318,54 +303,28 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
return msg.ID, err
}
m := discordgo.MessageSend{
Content: msg.Username + msg.Text,
AllowedMentions: b.getAllowedMentions(),
}
if msg.ParentValid() {
m.Reference = &discordgo.MessageReference{
MessageID: msg.ParentID,
ChannelID: channelID,
GuildID: b.guildID,
}
}
// Post normal message
res, err := b.c.ChannelMessageSend(channelID, msg.Username+msg.Text)
res, err := b.c.ChannelMessageSendComplex(channelID, &m)
if err != nil {
return "", err
}
return res.ID, nil
}
// useWebhook returns true if we have a webhook defined somewhere
func (b *Bdiscord) useWebhook() bool {
if b.GetString("WebhookURL") != "" {
return true
}
b.channelsMutex.RLock()
defer b.channelsMutex.RUnlock()
for _, channel := range b.channelInfoMap {
if channel.Options.WebhookURL != "" {
return true
}
}
return false
}
// isWebhookID returns true if the specified id is used in a defined webhook
func (b *Bdiscord) isWebhookID(id string) bool {
if b.GetString("WebhookURL") != "" {
wID, _ := b.splitURL(b.GetString("WebhookURL"))
if wID == id {
return true
}
}
b.channelsMutex.RLock()
defer b.channelsMutex.RUnlock()
for _, channel := range b.channelInfoMap {
if channel.Options.WebhookURL != "" {
wID, _ := b.splitURL(channel.Options.WebhookURL)
if wID == id {
return true
}
}
}
return false
}
// handleUploadFile handles native upload of files
func (b *Bdiscord) handleUploadFile(msg *config.Message, channelID string) (string, error) {
var err error
@@ -377,8 +336,9 @@ func (b *Bdiscord) handleUploadFile(msg *config.Message, channelID string) (stri
Reader: bytes.NewReader(*fi.Data),
}
m := discordgo.MessageSend{
Content: msg.Username + fi.Comment,
Files: []*discordgo.File{&file},
Content: msg.Username + fi.Comment,
Files: []*discordgo.File{&file},
AllowedMentions: b.getAllowedMentions(),
}
_, err = b.c.ChannelMessageSendComplex(channelID, &m)
if err != nil {
@@ -387,83 +347,3 @@ func (b *Bdiscord) handleUploadFile(msg *config.Message, channelID string) (stri
}
return "", nil
}
// webhookSend send one or more message via webhook, taking care of file
// uploads (from slack, telegram or mattermost).
// Returns messageID and error.
func (b *Bdiscord) webhookSend(msg *config.Message, webhookID, token string) (*discordgo.Message, error) {
var (
res *discordgo.Message
err error
)
// If avatar is unset, check if UseLocalAvatar contains the message's
// account or protocol, and if so, try to find a local avatar
if msg.Avatar == "" {
for _, val := range b.GetStringSlice("UseLocalAvatar") {
if msg.Protocol == val || msg.Account == val {
if avatar := b.findAvatar(msg); avatar != "" {
msg.Avatar = avatar
}
break
}
}
}
// WebhookParams can have either `Content` or `File`.
// We can't send empty messages.
if msg.Text != "" {
res, err = b.c.WebhookExecute(
webhookID,
token,
true,
&discordgo.WebhookParams{
Content: msg.Text,
Username: msg.Username,
AvatarURL: msg.Avatar,
},
)
if err != nil {
b.Log.Errorf("Could not send text (%s) for message %#v: %s", msg.Text, msg, err)
}
}
if msg.Extra != nil {
for _, f := range msg.Extra["file"] {
fi := f.(config.FileInfo)
file := discordgo.File{
Name: fi.Name,
ContentType: "",
Reader: bytes.NewReader(*fi.Data),
}
content := ""
if msg.Text == "" {
content = fi.Comment
}
_, e2 := b.c.WebhookExecute(
webhookID,
token,
false,
&discordgo.WebhookParams{
Username: msg.Username,
AvatarURL: msg.Avatar,
File: &file,
Content: content,
},
)
if e2 != nil {
b.Log.Errorf("Could not send file %#v for message %#v: %s", file, msg, e2)
}
}
}
return res, err
}
func (b *Bdiscord) findAvatar(m *config.Message) string {
member, err := b.getGuildMemberByNick(m.Username)
if err != nil {
return ""
}
return member.User.AvatarURL("")
}

View File

@@ -69,7 +69,7 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
return
}
// if using webhooks, do not relay if it's ours
if b.useWebhook() && m.Author.Bot && b.isWebhookID(m.Author.ID) {
if m.Author.Bot && b.transmitter.HasWebhook(m.Author.ID) {
return
}
@@ -127,6 +127,11 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
// Replace emotes
rmsg.Text = replaceEmotes(rmsg.Text)
// Add our parent id if it exists, and if it's not referring to a message in another channel
if ref := m.MessageReference; ref != nil && ref.ChannelID == m.ChannelID {
rmsg.ParentID = ref.MessageID
}
b.Log.Debugf("<= Sending message from %s on %s to gateway", m.Author.Username, b.Account)
b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg

View File

@@ -9,6 +9,30 @@ import (
"github.com/matterbridge/discordgo"
)
func (b *Bdiscord) getAllowedMentions() *discordgo.MessageAllowedMentions {
// If AllowMention is not specified, then allow all mentions (default Discord behavior)
if !b.IsKeySet("AllowMention") {
return nil
}
// Otherwise, allow only the mentions that are specified
allowedMentionTypes := make([]discordgo.AllowedMentionType, 0, 3)
for _, m := range b.GetStringSlice("AllowMention") {
switch m {
case "everyone":
allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeEveryone)
case "roles":
allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeRoles)
case "users":
allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeUsers)
}
}
return &discordgo.MessageAllowedMentions{
Parse: allowedMentionTypes,
}
}
func (b *Bdiscord) getNick(user *discordgo.User, guildID string) string {
b.membersMutex.RLock()
defer b.membersMutex.RUnlock()
@@ -196,7 +220,7 @@ func (b *Bdiscord) replaceAction(text string) (string, bool) {
}
// splitURL splits a webhookURL and returns the ID and token.
func (b *Bdiscord) splitURL(url string) (string, string) {
func (b *Bdiscord) splitURL(url string) (string, string, bool) {
const (
expectedWebhookSplitCount = 7
webhookIdxID = 5
@@ -204,9 +228,9 @@ func (b *Bdiscord) splitURL(url string) (string, string) {
)
webhookURLSplit := strings.Split(url, "/")
if len(webhookURLSplit) != expectedWebhookSplitCount {
b.Log.Fatalf("%s is no correct discord WebhookURL", url)
return "", "", false
}
return webhookURLSplit[webhookIdxID], webhookURLSplit[webhookIdxToken]
return webhookURLSplit[webhookIdxID], webhookURLSplit[webhookIdxToken], true
}
func enumerateUsernames(s string) []string {

View File

@@ -0,0 +1,257 @@
// Package transmitter provides functionality for transmitting
// arbitrary webhook messages to Discord.
//
// The package provides the following functionality:
//
// - Creating new webhooks, whenever necessary
// - Loading webhooks that we have previously created
// - Sending new messages
// - Editing messages, via message ID
// - Deleting messages, via message ID
//
// The package has been designed for matterbridge, but with other
// Go bots in mind. The public API should be matterbridge-agnostic.
package transmitter
import (
"errors"
"fmt"
"strings"
"sync"
"time"
"github.com/matterbridge/discordgo"
log "github.com/sirupsen/logrus"
)
// A Transmitter represents a message manager for a single guild.
type Transmitter struct {
session *discordgo.Session
guild string
title string
autoCreate bool
// channelWebhooks maps from a channel ID to a webhook instance
channelWebhooks map[string]*discordgo.Webhook
mutex sync.RWMutex
Log *log.Entry
}
// ErrWebhookNotFound is returned when a valid webhook for this channel/message combination does not exist
var ErrWebhookNotFound = errors.New("webhook for this channel and message does not exist")
// ErrPermissionDenied is returned if the bot does not have permission to manage webhooks.
//
// Bots can be granted a guild-wide permission and channel-specific permissions to manage webhooks.
// Despite potentially having guild-wide permission, channel specific overrides could deny a bot's permission to manage webhooks.
var ErrPermissionDenied = errors.New("missing 'Manage Webhooks' permission")
// New returns a new Transmitter given a Discord session, guild ID, and title.
func New(session *discordgo.Session, guild string, title string, autoCreate bool) *Transmitter {
return &Transmitter{
session: session,
guild: guild,
title: title,
autoCreate: autoCreate,
channelWebhooks: make(map[string]*discordgo.Webhook),
Log: log.NewEntry(log.StandardLogger()),
}
}
// Send transmits a message to the given channel with the provided webhook data, and waits until Discord responds with message data.
func (t *Transmitter) Send(channelID string, params *discordgo.WebhookParams) (*discordgo.Message, error) {
wh, err := t.getOrCreateWebhook(channelID)
if err != nil {
return nil, err
}
msg, err := t.session.WebhookExecute(wh.ID, wh.Token, true, params)
if err != nil {
return nil, fmt.Errorf("execute failed: %w", err)
}
return msg, nil
}
// Edit will edit a message in a channel, if possible.
func (t *Transmitter) Edit(channelID string, messageID string, params *discordgo.WebhookParams) error {
wh := t.getWebhook(channelID)
if wh == nil {
return ErrWebhookNotFound
}
uri := discordgo.EndpointWebhookToken(wh.ID, wh.Token) + "/messages/" + messageID
_, err := t.session.RequestWithBucketID("PATCH", uri, params, discordgo.EndpointWebhookToken("", ""))
if err != nil {
return err
}
return nil
}
// HasWebhook checks whether the transmitter is using a particular webhook.
func (t *Transmitter) HasWebhook(id string) bool {
t.mutex.RLock()
defer t.mutex.RUnlock()
for _, wh := range t.channelWebhooks {
if wh.ID == id {
return true
}
}
return false
}
// AddWebhook allows you to register a channel's webhook with the transmitter.
func (t *Transmitter) AddWebhook(channelID string, webhook *discordgo.Webhook) bool {
t.Log.Debugf("Manually added webhook %#v to channel %#v", webhook.ID, channelID)
t.mutex.Lock()
defer t.mutex.Unlock()
_, replaced := t.channelWebhooks[channelID]
t.channelWebhooks[channelID] = webhook
return replaced
}
// RefreshGuildWebhooks loads "relevant" webhooks into the transmitter, with careful permission handling.
//
// Notes:
//
// - A webhook is "relevant" if it was created by this bot -- the ApplicationID should match the bot's ID.
// - The term "having permission" means having the "Manage Webhooks" permission. See ErrPermissionDenied for more information.
// - This function is additive and will not unload previously loaded webhooks.
// - A nil channelIDs slice is treated the same as an empty one.
//
// If the bot has guild-wide permission:
//
// 1. it will load any "relevant" webhooks from the entire guild
// 2. the given slice is ignored
//
// If the bot does not have guild-wide permission:
//
// 1. it will load any "relevant" webhooks in each channel
// 2. a single error will be returned if any error occurs (incl. if there is no permission for any of these channels)
//
// If any channel has more than one "relevant" webhook, it will randomly pick one.
func (t *Transmitter) RefreshGuildWebhooks(channelIDs []string) error {
t.Log.Debugln("Refreshing guild webhooks")
botID, err := getDiscordUserID(t.session)
if err != nil {
return fmt.Errorf("could not get current user: %w", err)
}
// Get all existing webhooks
hooks, err := t.session.GuildWebhooks(t.guild)
if err != nil {
switch {
case isDiscordPermissionError(err):
// We fallback on manually fetching hooks from individual channels
// if we don't have the "Manage Webhooks" permission globally.
// We can only do this if we were provided channelIDs, though.
if len(channelIDs) == 0 {
return ErrPermissionDenied
}
t.Log.Debugln("Missing global 'Manage Webhooks' permission, falling back on per-channel permission")
return t.fetchChannelsHooks(channelIDs, botID)
default:
return fmt.Errorf("could not get webhooks: %w", err)
}
}
t.Log.Debugln("Refreshing guild webhooks using global permission")
t.assignHooksByAppID(hooks, botID, false)
return nil
}
// createWebhook creates a webhook for a specific channel.
func (t *Transmitter) createWebhook(channel string) (*discordgo.Webhook, error) {
t.mutex.Lock()
defer t.mutex.Unlock()
wh, err := t.session.WebhookCreate(channel, t.title+time.Now().Format(" 3:04:05PM"), "")
if err != nil {
return nil, err
}
t.channelWebhooks[channel] = wh
return wh, nil
}
func (t *Transmitter) getWebhook(channel string) *discordgo.Webhook {
t.mutex.RLock()
defer t.mutex.RUnlock()
return t.channelWebhooks[channel]
}
func (t *Transmitter) getOrCreateWebhook(channelID string) (*discordgo.Webhook, error) {
// If we have a webhook for this channel, immediately return it
wh := t.getWebhook(channelID)
if wh != nil {
return wh, nil
}
// Early exit if we don't want to automatically create one
if !t.autoCreate {
return nil, ErrWebhookNotFound
}
t.Log.Infof("Creating a webhook for %s\n", channelID)
wh, err := t.createWebhook(channelID)
if err != nil {
return nil, fmt.Errorf("could not create webhook: %w", err)
}
return wh, nil
}
// fetchChannelsHooks fetches hooks for the given channelIDs and calls assignHooksByAppID for each channel's hooks
func (t *Transmitter) fetchChannelsHooks(channelIDs []string, botID string) error {
// For each channel, search for relevant hooks
var failedHooks []string
for _, channelID := range channelIDs {
hooks, err := t.session.ChannelWebhooks(channelID)
if err != nil {
failedHooks = append(failedHooks, "\n- "+channelID+": "+err.Error())
continue
}
t.assignHooksByAppID(hooks, botID, true)
}
// Compose an error if any hooks failed
if len(failedHooks) > 0 {
return errors.New("failed to fetch hooks:" + strings.Join(failedHooks, ""))
}
return nil
}
func (t *Transmitter) assignHooksByAppID(hooks []*discordgo.Webhook, appID string, channelTargeted bool) {
logLine := "Picking up webhook"
if channelTargeted {
logLine += " (channel targeted)"
}
t.mutex.Lock()
defer t.mutex.Unlock()
for _, wh := range hooks {
if wh.ApplicationID != appID {
continue
}
t.channelWebhooks[wh.ChannelID] = wh
t.Log.WithFields(log.Fields{
"id": wh.ID,
"name": wh.Name,
"channel": wh.ChannelID,
}).Println(logLine)
}
}

View File

@@ -0,0 +1,32 @@
package transmitter
import (
"github.com/matterbridge/discordgo"
)
// isDiscordPermissionError returns false for nil, and true if a Discord RESTError with code discordgo.ErrorCodeMissionPermissions
func isDiscordPermissionError(err error) bool {
if err == nil {
return false
}
restErr, ok := err.(*discordgo.RESTError)
if !ok {
return false
}
return restErr.Message != nil && restErr.Message.Code == discordgo.ErrCodeMissingPermissions
}
// getDiscordUserID gets own user ID from state, and fallback on API request
func getDiscordUserID(session *discordgo.Session) (string, error) {
if user := session.State.User; user != nil {
return user.ID, nil
}
user, err := session.User("@me")
if err != nil {
return "", err
}
return user.ID, nil
}

150
bridge/discord/webhook.go Normal file
View File

@@ -0,0 +1,150 @@
package bdiscord
import (
"bytes"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
"github.com/matterbridge/discordgo"
)
// shouldMessageUseWebhooks checks if have a channel specific webhook, if we're not using auto webhooks
func (b *Bdiscord) shouldMessageUseWebhooks(msg *config.Message) bool {
if b.useAutoWebhooks {
return true
}
b.channelsMutex.RLock()
defer b.channelsMutex.RUnlock()
if ci, ok := b.channelInfoMap[msg.Channel+b.Account]; ok {
if ci.Options.WebhookURL != "" {
return true
}
}
return false
}
// maybeGetLocalAvatar checks if UseLocalAvatar contains the message's
// account or protocol, and if so, returns the Discord avatar (if exists)
func (b *Bdiscord) maybeGetLocalAvatar(msg *config.Message) string {
for _, val := range b.GetStringSlice("UseLocalAvatar") {
if msg.Protocol != val && msg.Account != val {
continue
}
member, err := b.getGuildMemberByNick(msg.Username)
if err != nil {
return ""
}
return member.User.AvatarURL("")
}
return ""
}
// webhookSend send one or more message via webhook, taking care of file
// uploads (from slack, telegram or mattermost).
// Returns messageID and error.
func (b *Bdiscord) webhookSend(msg *config.Message, channelID string) (*discordgo.Message, error) {
var (
res *discordgo.Message
err error
)
// If avatar is unset, mutate the message to include the local avatar (but only if settings say we should do this)
if msg.Avatar == "" {
msg.Avatar = b.maybeGetLocalAvatar(msg)
}
// WebhookParams can have either `Content` or `File`.
// We can't send empty messages.
if msg.Text != "" {
res, err = b.transmitter.Send(
channelID,
&discordgo.WebhookParams{
Content: msg.Text,
Username: msg.Username,
AvatarURL: msg.Avatar,
AllowedMentions: b.getAllowedMentions(),
},
)
if err != nil {
b.Log.Errorf("Could not send text (%s) for message %#v: %s", msg.Text, msg, err)
}
}
if msg.Extra != nil {
for _, f := range msg.Extra["file"] {
fi := f.(config.FileInfo)
file := discordgo.File{
Name: fi.Name,
ContentType: "",
Reader: bytes.NewReader(*fi.Data),
}
content := ""
if msg.Text == "" {
content = fi.Comment
}
_, e2 := b.transmitter.Send(
channelID,
&discordgo.WebhookParams{
Username: msg.Username,
AvatarURL: msg.Avatar,
File: &file,
Content: content,
AllowedMentions: b.getAllowedMentions(),
},
)
if e2 != nil {
b.Log.Errorf("Could not send file %#v for message %#v: %s", file, msg, e2)
}
}
}
return res, err
}
func (b *Bdiscord) handleEventWebhook(msg *config.Message, channelID string) (string, error) {
// skip events
if msg.Event != "" && msg.Event != config.EventUserAction && msg.Event != config.EventJoinLeave && msg.Event != config.EventTopicChange {
return "", nil
}
// skip empty messages
if msg.Text == "" && (msg.Extra == nil || len(msg.Extra["file"]) == 0) {
b.Log.Debugf("Skipping empty message %#v", msg)
return "", nil
}
msg.Text = helper.ClipMessage(msg.Text, MessageLength, b.GetString("MessageClipped"))
msg.Text = b.replaceUserMentions(msg.Text)
// discord username must be [0..32] max
if len(msg.Username) > 32 {
msg.Username = msg.Username[0:32]
}
if msg.ID != "" {
b.Log.Debugf("Editing webhook message")
err := b.transmitter.Edit(channelID, msg.ID, &discordgo.WebhookParams{
Content: msg.Text,
Username: msg.Username,
AllowedMentions: b.getAllowedMentions(),
})
if err == nil {
return msg.ID, nil
}
b.Log.Errorf("Could not edit webhook message: %s", err)
}
b.Log.Debugf("Processing webhook sending for message %#v", msg)
discordMsg, err := b.webhookSend(msg, channelID)
if err != nil {
b.Log.Errorf("Could not broadcast via webhook for message %#v: %s", msg, err)
return "", err
}
if discordMsg == nil {
return "", nil
}
return discordMsg.ID, nil
}

View File

@@ -16,11 +16,7 @@ import (
"golang.org/x/image/webp"
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/internal"
"github.com/d5/tengo/v2"
"github.com/d5/tengo/v2/stdlib"
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
@@ -55,6 +51,30 @@ func DownloadFileAuth(url string, auth string) (*[]byte, error) {
return &data, nil
}
// DownloadFileAuthRocket downloads the given URL using the specified Rocket user ID and authentication token.
func DownloadFileAuthRocket(url, token, userID string) (*[]byte, error) {
var buf bytes.Buffer
client := &http.Client{
Timeout: time.Second * 5,
}
req, err := http.NewRequest("GET", url, nil)
req.Header.Add("X-Auth-Token", token)
req.Header.Add("X-User-Id", userID)
if err != nil {
return nil, err
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
_, err = io.Copy(&buf, resp.Body)
data := buf.Bytes()
return &data, err
}
// GetSubLines splits messages in newline-delimited lines. If maxLineLength is
// specified as non-zero GetSubLines will also clip long lines to the maximum
// length and insert a warning marker that the line was clipped.
@@ -62,8 +82,10 @@ func DownloadFileAuth(url string, auth string) (*[]byte, error) {
// TODO: The current implementation has the inconvenient that it disregards
// word boundaries when splitting but this is hard to solve without potentially
// breaking formatting and other stylistic effects.
func GetSubLines(message string, maxLineLength int) []string {
const clippingMessage = " <clipped message>"
func GetSubLines(message string, maxLineLength int, clippingMessage string) []string {
if clippingMessage == "" {
clippingMessage = " <clipped message>"
}
var lines []string
for _, line := range strings.Split(strings.TrimSpace(message), "\n") {
@@ -118,62 +140,6 @@ func GetAvatar(av map[string]string, userid string, general *config.Protocol) st
return ""
}
func handleDownloadTengo(br *bridge.Bridge, msg *config.Message, name string, size int64, general *config.Protocol) (bool, error) {
var (
res []byte
err error
drop bool
)
filename := br.GetString("tengo.download")
if filename == "" {
res, err = internal.Asset("tengo/download.tengo")
if err != nil {
return drop, err
}
} else {
res, err = ioutil.ReadFile(filename)
if err != nil {
return drop, err
}
}
s := tengo.NewScript(res)
s.SetImports(stdlib.GetModuleMap(stdlib.AllModuleNames()...))
_ = s.Add("inAccount", msg.Account)
_ = s.Add("inProtocol", msg.Protocol)
_ = s.Add("inChannel", msg.Channel)
_ = s.Add("inGateway", msg.Gateway)
_ = s.Add("inEvent", msg.Event)
_ = s.Add("outAccount", br.Account)
_ = s.Add("outProtocol", br.Protocol)
_ = s.Add("outChannel", msg.Channel)
_ = s.Add("outEvent", msg.Event)
_ = s.Add("msgText", msg.Text)
_ = s.Add("msgUsername", msg.Username)
_ = s.Add("msgDrop", drop)
_ = s.Add("downloadName", name)
_ = s.Add("downloadSize", size)
c, err := s.Compile()
if err != nil {
return drop, err
}
if err := c.Run(); err != nil {
return drop, err
}
drop = c.Get("msgDrop").Bool()
msg.Text = c.Get("msgText").String()
msg.Username = c.Get("msgUsername").String()
return drop, nil
}
// HandleDownloadSize checks a specified filename against the configured download blacklist
// and checks a specified file-size against the configure limit.
func HandleDownloadSize(logger *logrus.Entry, msg *config.Message, name string, size int64, general *config.Protocol) error {
@@ -229,8 +195,11 @@ func RemoveEmptyNewLines(msg string) string {
// ClipMessage trims a message to the specified length if it exceeds it and adds a warning
// to the message in case it does so.
func ClipMessage(text string, length int) string {
const clippingMessage = " <clipped message>"
func ClipMessage(text string, length int, clippingMessage string) string {
if clippingMessage == "" {
clippingMessage = " <clipped message>"
}
if len(text) > length {
text = text[:length-len(clippingMessage)]
if r, size := utf8.DecodeLastRuneInString(text); r == utf8.RuneError {
@@ -243,7 +212,7 @@ func ClipMessage(text string, length int) string {
// ParseMarkdown takes in an input string as markdown and parses it to html
func ParseMarkdown(input string) string {
extensions := parser.HardLineBreak | parser.NoIntraEmphasis
extensions := parser.HardLineBreak | parser.NoIntraEmphasis | parser.FencedCode
markdownParser := parser.NewWithExtensions(extensions)
renderer := html.NewRenderer(html.RendererOptions{
Flags: 0,
@@ -284,35 +253,52 @@ func CanConvertTgsToX() error {
// This relies on an external command, which is ugly, but works.
func ConvertTgsToX(data *[]byte, outputFormat string, logger *logrus.Entry) error {
// lottie can't handle input from a pipe, so write to a temporary file:
tmpFile, err := ioutil.TempFile(os.TempDir(), "matterbridge-lottie-*.tgs")
tmpInFile, err := ioutil.TempFile(os.TempDir(), "matterbridge-lottie-input-*.tgs")
if err != nil {
return err
}
tmpFileName := tmpFile.Name()
tmpInFileName := tmpInFile.Name()
defer func() {
if removeErr := os.Remove(tmpFileName); removeErr != nil {
logger.Errorf("Could not delete temporary file %s: %v", tmpFileName, removeErr)
if removeErr := os.Remove(tmpInFileName); removeErr != nil {
logger.Errorf("Could not delete temporary (input) file %s: %v", tmpInFileName, removeErr)
}
}()
// lottie can handle writing to a pipe, but there is no way to do that platform-independently.
// "/dev/stdout" won't work on Windows, and "-" upsets Cairo for some reason. So we need another file:
tmpOutFile, err := ioutil.TempFile(os.TempDir(), "matterbridge-lottie-output-*.data")
if err != nil {
return err
}
tmpOutFileName := tmpOutFile.Name()
defer func() {
if removeErr := os.Remove(tmpOutFileName); removeErr != nil {
logger.Errorf("Could not delete temporary (output) file %s: %v", tmpOutFileName, removeErr)
}
}()
if _, writeErr := tmpFile.Write(*data); writeErr != nil {
if _, writeErr := tmpInFile.Write(*data); writeErr != nil {
return writeErr
}
// Must close before calling lottie to avoid data races:
if closeErr := tmpFile.Close(); closeErr != nil {
if closeErr := tmpInFile.Close(); closeErr != nil {
return closeErr
}
// Call lottie to transform:
cmd := exec.Command("lottie_convert.py", "--input-format", "lottie", "--output-format", outputFormat, tmpFileName, "/dev/stdout")
cmd := exec.Command("lottie_convert.py", "--input-format", "lottie", "--output-format", outputFormat, tmpInFileName, tmpOutFileName)
cmd.Stdout = nil
cmd.Stderr = nil
// NB: lottie writes progress into to stderr in all cases.
stdout, stderr := cmd.Output()
_, stderr := cmd.Output()
if stderr != nil {
// 'stderr' already contains some parts of Stderr, because it was set to 'nil'.
return stderr
}
dataContents, err := ioutil.ReadFile(tmpOutFileName)
if err != nil {
return err
}
*data = stdout
*data = dataContents
return nil
}

View File

@@ -10,98 +10,96 @@ import (
const testLineLength = 64
var (
lineSplittingTestCases = map[string]struct {
input string
splitOutput []string
nonSplitOutput []string
}{
"Short single-line message": {
input: "short",
splitOutput: []string{"short"},
nonSplitOutput: []string{"short"},
var lineSplittingTestCases = map[string]struct {
input string
splitOutput []string
nonSplitOutput []string
}{
"Short single-line message": {
input: "short",
splitOutput: []string{"short"},
nonSplitOutput: []string{"short"},
},
"Long single-line message": {
input: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
splitOutput: []string{
"Lorem ipsum dolor sit amet, consectetur adipis <clipped message>",
"cing elit, sed do eiusmod tempor incididunt ut <clipped message>",
" labore et dolore magna aliqua.",
},
"Long single-line message": {
input: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
splitOutput: []string{
"Lorem ipsum dolor sit amet, consectetur adipis <clipped message>",
"cing elit, sed do eiusmod tempor incididunt ut <clipped message>",
" labore et dolore magna aliqua.",
},
nonSplitOutput: []string{"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."},
nonSplitOutput: []string{"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."},
},
"Short multi-line message": {
input: "I\ncan't\nget\nno\nsatisfaction!",
splitOutput: []string{
"I",
"can't",
"get",
"no",
"satisfaction!",
},
"Short multi-line message": {
input: "I\ncan't\nget\nno\nsatisfaction!",
splitOutput: []string{
"I",
"can't",
"get",
"no",
"satisfaction!",
},
nonSplitOutput: []string{
"I",
"can't",
"get",
"no",
"satisfaction!",
},
nonSplitOutput: []string{
"I",
"can't",
"get",
"no",
"satisfaction!",
},
"Long multi-line message": {
input: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n" +
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n" +
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n" +
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
splitOutput: []string{
"Lorem ipsum dolor sit amet, consectetur adipis <clipped message>",
"cing elit, sed do eiusmod tempor incididunt ut <clipped message>",
" labore et dolore magna aliqua.",
"Ut enim ad minim veniam, quis nostrud exercita <clipped message>",
"tion ullamco laboris nisi ut aliquip ex ea com <clipped message>",
"modo consequat.",
"Duis aute irure dolor in reprehenderit in volu <clipped message>",
"ptate velit esse cillum dolore eu fugiat nulla <clipped message>",
" pariatur.",
"Excepteur sint occaecat cupidatat non proident <clipped message>",
", sunt in culpa qui officia deserunt mollit an <clipped message>",
"im id est laborum.",
},
nonSplitOutput: []string{
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
},
},
"Long multi-line message": {
input: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n" +
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n" +
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n" +
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
splitOutput: []string{
"Lorem ipsum dolor sit amet, consectetur adipis <clipped message>",
"cing elit, sed do eiusmod tempor incididunt ut <clipped message>",
" labore et dolore magna aliqua.",
"Ut enim ad minim veniam, quis nostrud exercita <clipped message>",
"tion ullamco laboris nisi ut aliquip ex ea com <clipped message>",
"modo consequat.",
"Duis aute irure dolor in reprehenderit in volu <clipped message>",
"ptate velit esse cillum dolore eu fugiat nulla <clipped message>",
" pariatur.",
"Excepteur sint occaecat cupidatat non proident <clipped message>",
", sunt in culpa qui officia deserunt mollit an <clipped message>",
"im id est laborum.",
},
"Message ending with new-line.": {
input: "Newline ending\n",
splitOutput: []string{"Newline ending"},
nonSplitOutput: []string{"Newline ending"},
nonSplitOutput: []string{
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
},
"Long message containing UTF-8 multi-byte runes": {
input: "不布人個我此而及單石業喜資富下我河下日沒一我臺空達的常景便物沒為……子大我別名解成?生賣的全直黑,我自我結毛分洲了世當,是政福那是東;斯說",
splitOutput: []string{
"不布人個我此而及單石業喜資富下 <clipped message>",
"我河下日沒一我臺空達的常景便物 <clipped message>",
"沒為……子大我別名解成?生賣的 <clipped message>",
"全直黑,我自我結毛分洲了世當, <clipped message>",
"是政福那是東;斯說",
},
nonSplitOutput: []string{"不布人個我此而及單石業喜資富下我河下日沒一我臺空達的常景便物沒為……子大我別名解成?生賣的全直黑,我自我結毛分洲了世當,是政福那是東;斯說"},
},
"Message ending with new-line.": {
input: "Newline ending\n",
splitOutput: []string{"Newline ending"},
nonSplitOutput: []string{"Newline ending"},
},
"Long message containing UTF-8 multi-byte runes": {
input: "不布人個我此而及單石業喜資富下我河下日沒一我臺空達的常景便物沒為……子大我別名解成?生賣的全直黑,我自我結毛分洲了世當,是政福那是東;斯說",
splitOutput: []string{
"不布人個我此而及單石業喜資富下 <clipped message>",
"我河下日沒一我臺空達的常景便物 <clipped message>",
"沒為……子大我別名解成?生賣的 <clipped message>",
"全直黑,我自我結毛分洲了世當, <clipped message>",
"是政福那是東;斯說",
},
}
)
nonSplitOutput: []string{"不布人個我此而及單石業喜資富下我河下日沒一我臺空達的常景便物沒為……子大我別名解成?生賣的全直黑,我自我結毛分洲了世當,是政福那是東;斯說"},
},
}
func TestGetSubLines(t *testing.T) {
for testname, testcase := range lineSplittingTestCases {
splitLines := GetSubLines(testcase.input, testLineLength)
splitLines := GetSubLines(testcase.input, testLineLength, "")
assert.Equalf(t, testcase.splitOutput, splitLines, "'%s' testcase should give expected lines with splitting.", testname)
for _, splitLine := range splitLines {
byteLength := len([]byte(splitLine))
assert.True(t, byteLength <= testLineLength, "Splitted line '%s' of testcase '%s' should not exceed the maximum byte-length (%d vs. %d).", splitLine, testcase, byteLength, testLineLength)
}
nonSplitLines := GetSubLines(testcase.input, 0)
nonSplitLines := GetSubLines(testcase.input, 0, "")
assert.Equalf(t, testcase.nonSplitOutput, nonSplitLines, "'%s' testcase should give expected lines without splitting.", testname)
}
}
@@ -110,16 +108,19 @@ func TestConvertWebPToPNG(t *testing.T) {
if os.Getenv("LOCAL_TEST") == "" {
t.Skip()
}
input, err := ioutil.ReadFile("test.webp")
if err != nil {
t.Fail()
}
d := &input
err = ConvertWebPToPNG(d)
if err != nil {
t.Fail()
}
err = ioutil.WriteFile("test.png", *d, 0644)
err = ioutil.WriteFile("test.png", *d, 0o644) // nolint:gosec
if err != nil {
t.Fail()
}

View File

@@ -67,6 +67,20 @@ func (b *Birc) handleFiles(msg *config.Message) bool {
return true
}
func (b *Birc) handleInvite(client *girc.Client, event girc.Event) {
if len(event.Params) != 2 {
return
}
channel := event.Params[1]
b.Log.Debugf("got invite for %s", channel)
if _, ok := b.channels[channel]; ok {
b.i.Cmd.Join(channel)
}
}
func (b *Birc) handleJoinPart(client *girc.Client, event girc.Event) {
if len(event.Params) == 0 {
b.Log.Debugf("handleJoinPart: empty Params? %#v", event)
@@ -109,14 +123,15 @@ func (b *Birc) handleNewConnection(client *girc.Client, event girc.Event) {
i := b.i
b.Nick = event.Params[0]
i.Handlers.Add("PRIVMSG", b.handlePrivMsg)
i.Handlers.Add("CTCP_ACTION", b.handlePrivMsg)
i.Handlers.AddBg("PRIVMSG", b.handlePrivMsg)
i.Handlers.AddBg("CTCP_ACTION", b.handlePrivMsg)
i.Handlers.Add(girc.RPL_TOPICWHOTIME, b.handleTopicWhoTime)
i.Handlers.Add(girc.NOTICE, b.handleNotice)
i.Handlers.Add("JOIN", b.handleJoinPart)
i.Handlers.Add("PART", b.handleJoinPart)
i.Handlers.Add("QUIT", b.handleJoinPart)
i.Handlers.Add("KICK", b.handleJoinPart)
i.Handlers.AddBg(girc.NOTICE, b.handleNotice)
i.Handlers.AddBg("JOIN", b.handleJoinPart)
i.Handlers.AddBg("PART", b.handleJoinPart)
i.Handlers.AddBg("QUIT", b.handleJoinPart)
i.Handlers.AddBg("KICK", b.handleJoinPart)
i.Handlers.Add("INVITE", b.handleInvite)
}
func (b *Birc) handleNickServ() {

View File

@@ -30,6 +30,7 @@ type Birc struct {
Local chan config.Message // local queue for flood control
FirstConnection, authDone bool
MessageDelay, MessageQueue, MessageLength int
channels map[string]bool
*bridge.Config
}
@@ -40,6 +41,8 @@ func New(cfg *bridge.Config) bridge.Bridger {
b.Nick = b.GetString("Nick")
b.names = make(map[string][]string)
b.connected = make(chan error)
b.channels = make(map[string]bool)
if b.GetInt("MessageDelay") == 0 {
b.MessageDelay = 1300
} else {
@@ -112,6 +115,7 @@ func (b *Birc) Disconnect() error {
}
func (b *Birc) JoinChannel(channel config.ChannelInfo) error {
b.channels[channel.Name] = true
// need to check if we have nickserv auth done before joining channels
for {
if b.authDone {
@@ -163,9 +167,9 @@ func (b *Birc) Send(msg config.Message) (string, error) {
}
if b.GetBool("MessageSplit") {
msgLines = helper.GetSubLines(msg.Text, b.MessageLength)
msgLines = helper.GetSubLines(msg.Text, b.MessageLength, b.GetString("MessageClipped"))
} else {
msgLines = helper.GetSubLines(msg.Text, 0)
msgLines = helper.GetSubLines(msg.Text, 0, b.GetString("MessageClipped"))
}
for i := range msgLines {
if len(b.Local) >= b.MessageQueue {
@@ -201,27 +205,58 @@ func (b *Birc) doConnect() {
}
}
// Sanitize nicks for RELAYMSG: replace IRC characters with special meanings with "-"
func sanitizeNick(nick string) string {
sanitize := func(r rune) rune {
if strings.ContainsRune("!+%@&#$:'\"?*,. ", r) {
return '-'
}
return r
}
return strings.Map(sanitize, nick)
}
func (b *Birc) doSend() {
rate := time.Millisecond * time.Duration(b.MessageDelay)
throttle := time.NewTicker(rate)
for msg := range b.Local {
<-throttle.C
username := msg.Username
if b.GetBool("Colornicks") && len(username) > 1 {
checksum := crc32.ChecksumIEEE([]byte(msg.Username))
colorCode := checksum%14 + 2 // quick fix - prevent white or black color codes
username = fmt.Sprintf("\x03%02d%s\x0F", colorCode, msg.Username)
}
// Optional support for the proposed RELAYMSG extension, described at
// https://github.com/jlu5/ircv3-specifications/blob/master/extensions/relaymsg.md
// nolint:nestif
if (b.i.HasCapability("overdrivenetworks.com/relaymsg") || b.i.HasCapability("draft/relaymsg")) &&
b.GetBool("UseRelayMsg") {
username = sanitizeNick(username)
text := msg.Text
switch msg.Event {
case config.EventUserAction:
b.i.Cmd.Action(msg.Channel, username+msg.Text)
case config.EventNoticeIRC:
b.Log.Debugf("Sending notice to channel %s", msg.Channel)
b.i.Cmd.Notice(msg.Channel, username+msg.Text)
default:
b.Log.Debugf("Sending to channel %s", msg.Channel)
b.i.Cmd.Message(msg.Channel, username+msg.Text)
// Work around girc chomping leading commas on single word messages?
if strings.HasPrefix(text, ":") && !strings.ContainsRune(text, ' ') {
text = ":" + text
}
if msg.Event == config.EventUserAction {
b.i.Cmd.SendRawf("RELAYMSG %s %s :\x01ACTION %s\x01", msg.Channel, username, text) //nolint:errcheck
} else {
b.Log.Debugf("Sending RELAYMSG to channel %s: nick=%s", msg.Channel, username)
b.i.Cmd.SendRawf("RELAYMSG %s %s :%s", msg.Channel, username, text) //nolint:errcheck
}
} else {
if b.GetBool("Colornicks") {
checksum := crc32.ChecksumIEEE([]byte(msg.Username))
colorCode := checksum%14 + 2 // quick fix - prevent white or black color codes
username = fmt.Sprintf("\x03%02d%s\x0F", colorCode, msg.Username)
}
switch msg.Event {
case config.EventUserAction:
b.i.Cmd.Action(msg.Channel, username+msg.Text)
case config.EventNoticeIRC:
b.Log.Debugf("Sending notice to channel %s", msg.Channel)
b.i.Cmd.Notice(msg.Channel, username+msg.Text)
default:
b.Log.Debugf("Sending to channel %s", msg.Channel)
b.i.Cmd.Message(msg.Channel, username+msg.Text)
}
}
}
}
@@ -269,8 +304,9 @@ func (b *Birc) getClient() (*girc.Client, error) {
TLSConfig: &tls.Config{InsecureSkipVerify: b.GetBool("SkipTLSVerify"), ServerName: server}, //nolint:gosec
PingDelay: pingDelay,
// skip gIRC internal rate limiting, since we have our own throttling
AllowFlood: true,
Debug: debug,
AllowFlood: true,
Debug: debug,
SupportedCaps: map[string][]string{"overdrivenetworks.com/relaymsg": nil, "draft/relaymsg": nil},
})
return i, nil
}
@@ -280,12 +316,16 @@ func (b *Birc) endNames(client *girc.Client, event girc.Event) {
sort.Strings(b.names[channel])
maxNamesPerPost := (300 / b.nicksPerRow()) * b.nicksPerRow()
for len(b.names[channel]) > maxNamesPerPost {
b.Remote <- config.Message{Username: b.Nick, Text: b.formatnicks(b.names[channel][0:maxNamesPerPost]),
Channel: channel, Account: b.Account}
b.Remote <- config.Message{
Username: b.Nick, Text: b.formatnicks(b.names[channel][0:maxNamesPerPost]),
Channel: channel, Account: b.Account,
}
b.names[channel] = b.names[channel][maxNamesPerPost:]
}
b.Remote <- config.Message{Username: b.Nick, Text: b.formatnicks(b.names[channel]),
Channel: channel, Account: b.Account}
b.Remote <- config.Message{
Username: b.Nick, Text: b.formatnicks(b.names[channel]),
Channel: channel, Account: b.Account,
}
b.names[channel] = nil
b.i.Handlers.Clear(girc.RPL_NAMREPLY)
b.i.Handlers.Clear(girc.RPL_ENDOFNAMES)
@@ -307,6 +347,15 @@ func (b *Birc) skipPrivMsg(event girc.Event) bool {
if event.Source.Name == b.Nick {
return true
}
// don't forward messages we sent via RELAYMSG
if relayedNick, ok := event.Tags.Get("draft/relaymsg"); ok && relayedNick == b.Nick {
return true
}
// This is the old name of the cap sent in spoofed messages; I've kept this in
// for compatibility reasons
if relayedNick, ok := event.Tags.Get("relaymsg"); ok && relayedNick == b.Nick {
return true
}
return false
}

View File

@@ -3,6 +3,7 @@ package bmatrix
import (
"encoding/json"
"errors"
"fmt"
"html"
"strings"
"time"
@@ -82,20 +83,36 @@ func (b *Bmatrix) getDisplayName(mxid string) string {
func (b *Bmatrix) cacheDisplayName(mxid string, displayName string) string {
now := time.Now()
// scan to delete old entries, to stop memory usage from becoming too high with old entries
// scan to delete old entries, to stop memory usage from becoming too high with old entries.
// In addition, we also detect if another user have the same username, and if so, we append their mxids to their usernames to differentiate them.
toDelete := []string{}
b.RLock()
for k, v := range b.NicknameMap {
if now.Sub(v.lastUpdated) > 10*time.Minute {
toDelete = append(toDelete, k)
}
}
b.RUnlock()
conflict := false
b.Lock()
for mxid, v := range b.NicknameMap {
// to prevent username reuse across matrix servers - or even on the same server, append
// the mxid to the username when there is a conflict
if v.displayName == displayName {
conflict = true
// TODO: it would be nice to be able to rename previous messages from this user.
// The current behavior is that only users with clashing usernames and *that have spoken since the bridge last started* will get their mxids shown, and I don't know if that's the expected behavior.
v.displayName = fmt.Sprintf("%s (%s)", displayName, mxid)
b.NicknameMap[mxid] = v
}
if now.Sub(v.lastUpdated) > 10*time.Minute {
toDelete = append(toDelete, mxid)
}
}
if conflict {
displayName = fmt.Sprintf("%s (%s)", displayName, mxid)
}
for _, v := range toDelete {
delete(b.NicknameMap, v)
}
b.NicknameMap[mxid] = NicknameCacheEntry{
displayName: displayName,
lastUpdated: now,
@@ -164,3 +181,35 @@ func (b *Bmatrix) getAvatarURL(sender string) string {
return url
}
// handleRatelimit handles the ratelimit errors and return if we're ratelimited and the amount of time to sleep
func (b *Bmatrix) handleRatelimit(err error) (time.Duration, bool) {
httpErr := handleError(err)
if httpErr.Errcode != "M_LIMIT_EXCEEDED" {
return 0, false
}
b.Log.Debugf("ratelimited: %s", httpErr.Err)
b.Log.Infof("getting ratelimited by matrix, sleeping approx %d seconds before retrying", httpErr.RetryAfterMs/1000)
return time.Duration(httpErr.RetryAfterMs) * time.Millisecond, true
}
// retry function will check if we're ratelimited and retries again when backoff time expired
// returns original error if not 429 ratelimit
func (b *Bmatrix) retry(f func() error) error {
b.rateMutex.Lock()
defer b.rateMutex.Unlock()
for {
if err := f(); err != nil {
if backoff, ok := b.handleRatelimit(err); ok {
time.Sleep(backoff)
} else {
return err
}
} else {
return nil
}
}
}

View File

@@ -30,6 +30,7 @@ type Bmatrix struct {
UserID string
NicknameMap map[string]NicknameCacheEntry
RoomMap map[string]string
rateMutex sync.RWMutex
sync.RWMutex
*bridge.Config
}
@@ -74,22 +75,33 @@ func New(cfg *bridge.Config) bridge.Bridger {
func (b *Bmatrix) Connect() error {
var err error
b.Log.Infof("Connecting %s", b.GetString("Server"))
b.mc, err = matrix.NewClient(b.GetString("Server"), "", "")
if err != nil {
return err
if b.GetString("MxID") != "" && b.GetString("Token") != "" {
b.mc, err = matrix.NewClient(
b.GetString("Server"), b.GetString("MxID"), b.GetString("Token"),
)
if err != nil {
return err
}
b.UserID = b.GetString("MxID")
b.Log.Info("Using existing Matrix credentials")
} else {
b.mc, err = matrix.NewClient(b.GetString("Server"), "", "")
if err != nil {
return err
}
resp, err := b.mc.Login(&matrix.ReqLogin{
Type: "m.login.password",
User: b.GetString("Login"),
Password: b.GetString("Password"),
Identifier: matrix.NewUserIdentifier(b.GetString("Login")),
})
if err != nil {
return err
}
b.mc.SetCredentials(resp.UserID, resp.AccessToken)
b.UserID = resp.UserID
b.Log.Info("Connection succeeded")
}
resp, err := b.mc.Login(&matrix.ReqLogin{
Type: "m.login.password",
User: b.GetString("Login"),
Password: b.GetString("Password"),
Identifier: matrix.NewUserIdentifier(b.GetString("Login")),
})
if err != nil {
return err
}
b.mc.SetCredentials(resp.UserID, resp.AccessToken)
b.UserID = resp.UserID
b.Log.Info("Connection succeeded")
go b.handlematrix()
return nil
}
@@ -99,25 +111,18 @@ func (b *Bmatrix) Disconnect() error {
}
func (b *Bmatrix) JoinChannel(channel config.ChannelInfo) error {
retry:
resp, err := b.mc.JoinRoom(channel.Name, "", nil)
if err != nil {
httpErr := handleError(err)
if httpErr.Errcode == "M_LIMIT_EXCEEDED" {
b.Log.Infof("getting ratelimited by matrix, sleeping approx %d seconds before joining %s", httpErr.RetryAfterMs/1000, channel.Name)
time.Sleep((time.Duration(httpErr.RetryAfterMs) * time.Millisecond))
goto retry
return b.retry(func() error {
resp, err := b.mc.JoinRoom(channel.Name, "", nil)
if err != nil {
return err
}
return err
}
b.Lock()
b.RoomMap[resp.RoomID] = channel.Name
b.Unlock()
b.Lock()
b.RoomMap[resp.RoomID] = channel.Name
b.Unlock()
return nil
return nil
})
}
func (b *Bmatrix) Send(msg config.Message) (string, error) {
@@ -135,11 +140,21 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
Body: username.plain + msg.Text,
FormattedBody: username.formatted + msg.Text,
}
resp, err := b.mc.SendMessageEvent(channel, "m.room.message", m)
if err != nil {
return "", err
}
return resp.EventID, err
msgID := ""
err := b.retry(func() error {
resp, err := b.mc.SendMessageEvent(channel, "m.room.message", m)
if err != nil {
return err
}
msgID = resp.EventID
return err
})
return msgID, err
}
// Delete message
@@ -147,17 +162,34 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
if msg.ID == "" {
return "", nil
}
resp, err := b.mc.RedactEvent(channel, msg.ID, &matrix.ReqRedact{})
if err != nil {
return "", err
}
return resp.EventID, err
msgID := ""
err := b.retry(func() error {
resp, err := b.mc.RedactEvent(channel, msg.ID, &matrix.ReqRedact{})
if err != nil {
return err
}
msgID = resp.EventID
return err
})
return msgID, err
}
// Upload a file if it exists
if msg.Extra != nil {
for _, rmsg := range helper.HandleExtra(&msg, b.General) {
if _, err := b.mc.SendText(channel, rmsg.Username+rmsg.Text); err != nil {
rmsg := rmsg
err := b.retry(func() error {
_, err := b.mc.SendText(channel, rmsg.Username+rmsg.Text)
return err
})
if err != nil {
b.Log.Errorf("sendText failed: %s", err)
}
}
@@ -187,7 +219,12 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
EventID: msg.ID,
Type: "m.replace",
}
_, err := b.mc.SendMessageEvent(channel, "m.room.message", rmsg)
err := b.retry(func() error {
_, err := b.mc.SendMessageEvent(channel, "m.room.message", rmsg)
return err
})
if err != nil {
return "", err
}
@@ -202,26 +239,58 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
Body: username.plain + msg.Text,
FormattedBody: username.formatted + msg.Text,
}
resp, err := b.mc.SendMessageEvent(channel, "m.room.message", m)
var (
resp *matrix.RespSendEvent
err error
)
err = b.retry(func() error {
resp, err = b.mc.SendMessageEvent(channel, "m.room.message", m)
return err
})
if err != nil {
return "", err
}
return resp.EventID, err
}
if b.GetBool("HTMLDisable") {
resp, err := b.mc.SendText(channel, username.plain+msg.Text)
var (
resp *matrix.RespSendEvent
err error
)
err = b.retry(func() error {
resp, err = b.mc.SendText(channel, username.plain+msg.Text)
return err
})
if err != nil {
return "", err
}
return resp.EventID, err
}
// Post normal message with HTML support (eg riot.im)
resp, err := b.mc.SendFormattedText(channel, username.plain+msg.Text, username.formatted+helper.ParseMarkdown(msg.Text))
var (
resp *matrix.RespSendEvent
err error
)
err = b.retry(func() error {
resp, err = b.mc.SendFormattedText(channel, username.plain+msg.Text,
username.formatted+helper.ParseMarkdown(msg.Text))
return err
})
if err != nil {
return "", err
}
return resp.EventID, err
}
@@ -299,13 +368,6 @@ func (b *Bmatrix) handleEvent(ev *matrix.Event) {
Avatar: b.getAvatarURL(ev.Sender),
}
// Text must be a string
if rmsg.Text, ok = ev.Content["body"].(string); !ok {
b.Log.Errorf("Content[body] is not a string: %T\n%#v",
ev.Content["body"], ev.Content)
return
}
// Remove homeserver suffix if configured
if b.GetBool("NoHomeServerSuffix") {
re := regexp.MustCompile("(.*?):.*")
@@ -321,6 +383,13 @@ func (b *Bmatrix) handleEvent(ev *matrix.Event) {
return
}
// Text must be a string
if rmsg.Text, ok = ev.Content["body"].(string); !ok {
b.Log.Errorf("Content[body] is not a string: %T\n%#v",
ev.Content["body"], ev.Content)
return
}
// Do we have a /me action
if ev.Content["msgtype"].(string) == "m.emote" {
rmsg.Event = config.EventUserAction
@@ -341,6 +410,11 @@ func (b *Bmatrix) handleEvent(ev *matrix.Event) {
b.Log.Debugf("<= Sending message from %s on %s to gateway", ev.Sender, b.Account)
b.Remote <- rmsg
// not crucial, so no ratelimit check here
if err := b.mc.MarkRead(ev.RoomID, ev.ID); err != nil {
b.Log.Errorf("couldn't mark message as read %s", err.Error())
}
}
}
@@ -420,13 +494,25 @@ func (b *Bmatrix) handleUploadFile(msg *config.Message, channel string, fi *conf
sp := strings.Split(fi.Name, ".")
mtype := mime.TypeByExtension("." + sp[len(sp)-1])
// image and video uploads send no username, we have to do this ourself here #715
_, err := b.mc.SendFormattedText(channel, username.plain+fi.Comment, username.formatted+fi.Comment)
err := b.retry(func() error {
_, err := b.mc.SendFormattedText(channel, username.plain+fi.Comment, username.formatted+fi.Comment)
return err
})
if err != nil {
b.Log.Errorf("file comment failed: %#v", err)
}
b.Log.Debugf("uploading file: %s %s", fi.Name, mtype)
res, err := b.mc.UploadToContentRepo(content, mtype, int64(len(*fi.Data)))
var res *matrix.RespMediaUpload
err = b.retry(func() error {
res, err = b.mc.UploadToContentRepo(content, mtype, int64(len(*fi.Data)))
return err
})
if err != nil {
b.Log.Errorf("file upload failed: %#v", err)
return
@@ -435,40 +521,56 @@ func (b *Bmatrix) handleUploadFile(msg *config.Message, channel string, fi *conf
switch {
case strings.Contains(mtype, "video"):
b.Log.Debugf("sendVideo %s", res.ContentURI)
_, err = b.mc.SendVideo(channel, fi.Name, res.ContentURI)
err = b.retry(func() error {
_, err = b.mc.SendVideo(channel, fi.Name, res.ContentURI)
return err
})
if err != nil {
b.Log.Errorf("sendVideo failed: %#v", err)
}
case strings.Contains(mtype, "image"):
b.Log.Debugf("sendImage %s", res.ContentURI)
_, err = b.mc.SendImage(channel, fi.Name, res.ContentURI)
err = b.retry(func() error {
_, err = b.mc.SendImage(channel, fi.Name, res.ContentURI)
return err
})
if err != nil {
b.Log.Errorf("sendImage failed: %#v", err)
}
case strings.Contains(mtype, "audio"):
b.Log.Debugf("sendAudio %s", res.ContentURI)
_, err = b.mc.SendMessageEvent(channel, "m.room.message", matrix.AudioMessage{
MsgType: "m.audio",
Body: fi.Name,
URL: res.ContentURI,
Info: matrix.AudioInfo{
Mimetype: mtype,
Size: uint(len(*fi.Data)),
},
err = b.retry(func() error {
_, err = b.mc.SendMessageEvent(channel, "m.room.message", matrix.AudioMessage{
MsgType: "m.audio",
Body: fi.Name,
URL: res.ContentURI,
Info: matrix.AudioInfo{
Mimetype: mtype,
Size: uint(len(*fi.Data)),
},
})
return err
})
if err != nil {
b.Log.Errorf("sendAudio failed: %#v", err)
}
default:
b.Log.Debugf("sendFile %s", res.ContentURI)
_, err = b.mc.SendMessageEvent(channel, "m.room.message", matrix.FileMessage{
MsgType: "m.file",
Body: fi.Name,
URL: res.ContentURI,
Info: matrix.FileInfo{
Mimetype: mtype,
Size: uint(len(*fi.Data)),
},
err = b.retry(func() error {
_, err = b.mc.SendMessageEvent(channel, "m.room.message", matrix.FileMessage{
MsgType: "m.file",
Body: fi.Name,
URL: res.ContentURI,
Info: matrix.FileInfo{
Mimetype: mtype,
Size: uint(len(*fi.Data)),
},
})
return err
})
if err != nil {
b.Log.Errorf("sendFile failed: %#v", err)

View File

@@ -108,7 +108,7 @@ func (b *Bmattermost) handleMatterClient(messages chan *config.Message) {
Channel: message.Channel,
Text: message.Text,
ID: message.Post.Id,
ParentID: message.Post.ParentId,
ParentID: message.Post.RootId, // ParentID is obsolete with mattermost
Extra: make(map[string][]interface{}),
}

View File

@@ -122,11 +122,20 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
}
// Handle prefix hint for unthreaded messages.
if msg.ParentID == "msg-parent-not-found" {
if msg.ParentNotFound() {
msg.ParentID = ""
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
}
// we only can reply to the root of the thread, not to a specific ID (like discord for example does)
if msg.ParentID != "" {
post, res := b.mc.Client.GetPost(msg.ParentID, "")
if res.Error != nil {
b.Log.Errorf("getting post %s failed: %s", msg.ParentID, res.Error.DetailedError)
}
msg.ParentID = post.RootId
}
// Upload a file if it exists
if msg.Extra != nil {
for _, rmsg := range helper.HandleExtra(&msg, b.General) {

View File

@@ -86,13 +86,16 @@ func (b *Bmsteams) JoinChannel(channel config.ChannelInfo) error {
func (b *Bmsteams) Send(msg config.Message) (string, error) {
b.Log.Debugf("=> Receiving %#v", msg)
if msg.ParentID != "" && msg.ParentID != "msg-parent-not-found" {
if msg.ParentValid() {
return b.sendReply(msg)
}
if msg.ParentID == "msg-parent-not-found" {
// Handle prefix hint for unthreaded messages.
if msg.ParentNotFound() {
msg.ParentID = ""
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
}
ct := b.gc.Teams().ID(b.GetString("TeamID")).Channels().ID(msg.Channel).Messages().Request()
text := msg.Username + msg.Text
content := &msgraph.ItemBody{Content: &text}

View File

@@ -19,6 +19,12 @@ func (b *Bmumble) handleTextMessage(event *gumble.TextMessageEvent) {
if event.TextMessage.Sender != nil {
sender = event.TextMessage.Sender.Name
}
// If the text message is received before receiving a ServerSync
// and UserState, Client.Self or Self.Channel are nil
if event.Client.Self == nil || event.Client.Self.Channel == nil {
b.Log.Warn("Connection bootstrap not finished, discarding text message")
return
}
// Convert Mumble HTML messages to markdown
parts, err := b.convertHTMLtoMarkdown(event.TextMessage.Message)
if err != nil {

View File

@@ -248,9 +248,9 @@ func (b *Bmumble) processMessage(msg *config.Message) {
// If there is a maximum message length, split and truncate the lines
var msgLines []string
if maxLength := b.serverConfig.MaximumMessageLength; maxLength != nil {
msgLines = helper.GetSubLines(msg.Text, *maxLength-len(msg.Username))
msgLines = helper.GetSubLines(msg.Text, *maxLength-len(msg.Username), b.GetString("MessageClipped"))
} else {
msgLines = helper.GetSubLines(msg.Text, 0)
msgLines = helper.GetSubLines(msg.Text, 0, b.GetString("MessageClipped"))
}
// Send the individual lindes
for i := range msgLines {

View File

@@ -74,44 +74,33 @@ func (b *Btalk) JoinChannel(channel config.ChannelInfo) error {
}
b.rooms = append(b.rooms, newRoom)
// Config
guestSuffix := " (Guest)"
if b.IsKeySet("GuestSuffix") {
guestSuffix = b.GetString("GuestSuffix")
}
go func() {
for msg := range c {
msg := msg
// ignore messages that are one of the following
// * not a message from a user
// * from ourselves
if msg.MessageType != ocs.MessageComment || msg.ActorID == b.user.User {
continue
}
remoteMessage := config.Message{
Text: formatRichObjectString(msg.Message, msg.MessageParameters),
Channel: newRoom.room.Token,
Username: DisplayName(msg, guestSuffix),
UserID: msg.ActorID,
Account: b.Account,
}
// It is possible for the ID to not be set on older versions of Talk so we only set it if
// the ID is not blank
if msg.ID != 0 {
remoteMessage.ID = strconv.Itoa(msg.ID)
if msg.Error != nil {
b.Log.Errorf("Fatal message poll error: %s\n", msg.Error)
return
}
// Handle Files
err = b.handleFiles(&remoteMessage, &msg)
if err != nil {
b.Log.Errorf("Error handling file: %#v", msg)
// Ignore messages that are from the bot user
if msg.ActorID == b.user.User {
continue
}
// Handle deleting messages
if msg.MessageType == ocs.MessageSystem && msg.Parent != nil && msg.Parent.MessageType == ocs.MessageDelete {
b.handleDeletingMessage(&msg, &newRoom)
continue
}
// Handle sending messages
if msg.MessageType == ocs.MessageComment {
b.handleSendingMessage(&msg, &newRoom)
continue
}
b.Log.Debugf("<= Message is %#v", remoteMessage)
b.Remote <- remoteMessage
}
}()
return nil
@@ -124,16 +113,40 @@ func (b *Btalk) Send(msg config.Message) (string, error) {
return "", nil
}
// Talk currently only supports sending normal messages
if msg.Event != "" {
return "", nil
// Standard Message Send
if msg.Event == "" {
// Handle sending files if they are included
err := b.handleSendingFile(&msg, r)
if err != nil {
b.Log.Errorf("Could not send files in message to room %v from %v: %v", msg.Channel, msg.Username, err)
return "", nil
}
sentMessage, err := r.room.SendMessage(msg.Username + msg.Text)
if err != nil {
b.Log.Errorf("Could not send message to room %v from %v: %v", msg.Channel, msg.Username, err)
return "", nil
}
return strconv.Itoa(sentMessage.ID), nil
}
sentMessage, err := r.room.SendMessage(msg.Username + msg.Text)
if err != nil {
b.Log.Errorf("Could not send message to room %v from %v: %v", msg.Channel, msg.Username, err)
return "", nil
// Message Deletion
if msg.Event == config.EventMsgDelete {
messageID, err := strconv.Atoi(msg.ID)
if err != nil {
return "", err
}
data, err := r.room.DeleteMessage(messageID)
if err != nil {
return "", err
}
return strconv.Itoa(data.ID), nil
}
return strconv.Itoa(sentMessage.ID), nil
// Message is not a type that is currently supported
return "", nil
}
func (b *Btalk) getRoom(token string) *Broom {
@@ -170,6 +183,74 @@ func (b *Btalk) handleFiles(mmsg *config.Message, message *ocs.TalkRoomMessageDa
return nil
}
func (b *Btalk) handleSendingFile(msg *config.Message, r *Broom) error {
for _, f := range msg.Extra["file"] {
fi := f.(config.FileInfo)
if fi.URL == "" {
continue
}
message := msg.Username
if fi.Comment != "" {
message += fi.Comment + " "
}
message += fi.URL
_, err := r.room.SendMessage(message)
if err != nil {
return err
}
}
return nil
}
func (b *Btalk) handleSendingMessage(msg *ocs.TalkRoomMessageData, r *Broom) {
remoteMessage := config.Message{
Text: formatRichObjectString(msg.Message, msg.MessageParameters),
Channel: r.room.Token,
Username: DisplayName(msg, b.guestSuffix()),
UserID: msg.ActorID,
Account: b.Account,
}
// It is possible for the ID to not be set on older versions of Talk so we only set it if
// the ID is not blank
if msg.ID != 0 {
remoteMessage.ID = strconv.Itoa(msg.ID)
}
// Handle Files
err := b.handleFiles(&remoteMessage, msg)
if err != nil {
b.Log.Errorf("Error handling file: %#v", msg)
return
}
b.Log.Debugf("<= Message is %#v", remoteMessage)
b.Remote <- remoteMessage
}
func (b *Btalk) handleDeletingMessage(msg *ocs.TalkRoomMessageData, r *Broom) {
remoteMessage := config.Message{
Event: config.EventMsgDelete,
Text: config.EventMsgDelete,
Channel: r.room.Token,
ID: strconv.Itoa(msg.Parent.ID),
Account: b.Account,
}
b.Log.Debugf("<= Message being deleted is %#v", remoteMessage)
b.Remote <- remoteMessage
}
func (b *Btalk) guestSuffix() string {
guestSuffix := " (Guest)"
if b.IsKeySet("GuestSuffix") {
guestSuffix = b.GetString("GuestSuffix")
}
return guestSuffix
}
// Spec: https://github.com/nextcloud/server/issues/1706#issue-182308785
func formatRichObjectString(message string, parameters map[string]ocs.RichObjectString) string {
for id, parameter := range parameters {
@@ -190,7 +271,7 @@ func formatRichObjectString(message string, parameters map[string]ocs.RichObject
return message
}
func DisplayName(msg ocs.TalkRoomMessageData, suffix string) string {
func DisplayName(msg *ocs.TalkRoomMessageData, suffix string) string {
if msg.ActorType == ocs.ActorGuest {
if msg.ActorDisplayName == "" {
return "Guest"

View File

@@ -1,7 +1,10 @@
package brocketchat
import (
"fmt"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
"github.com/matterbridge/Rocket.Chat.Go.SDK/models"
)
@@ -58,6 +61,7 @@ func (b *Brocketchat) handleStatusEvent(ev models.Message, rmsg *config.Message)
func (b *Brocketchat) handleRocketClient(messages chan *config.Message) {
for message := range b.messageChan {
message := message
// skip messages with same ID, apparently messages get duplicated for an unknown reason
if _, ok := b.cache.Get(message.ID); ok {
continue
@@ -76,8 +80,11 @@ func (b *Brocketchat) handleRocketClient(messages chan *config.Message) {
Account: b.Account,
UserID: message.User.ID,
ID: message.ID,
Extra: make(map[string][]interface{}),
}
b.handleAttachments(&message, rmsg)
// handleStatusEvent returns false if the message should be dropped
// in that case it is probably some modification to the channel we do not want to relay
if b.handleStatusEvent(m, rmsg) {
@@ -86,6 +93,38 @@ func (b *Brocketchat) handleRocketClient(messages chan *config.Message) {
}
}
func (b *Brocketchat) handleAttachments(message *models.Message, rmsg *config.Message) {
if rmsg.Text == "" {
for _, attachment := range message.Attachments {
if attachment.Title != "" {
rmsg.Text = attachment.Title + "\n"
}
if attachment.Title != "" && attachment.Text != "" {
rmsg.Text += "\n"
}
if attachment.Text != "" {
rmsg.Text += attachment.Text
}
}
}
for i := range message.Attachments {
if err := b.handleDownloadFile(rmsg, &message.Attachments[i]); err != nil {
b.Log.Errorf("Could not download incoming file: %#v", err)
}
}
}
func (b *Brocketchat) handleDownloadFile(rmsg *config.Message, file *models.Attachment) error {
downloadURL := b.GetString("server") + file.TitleLink
data, err := helper.DownloadFileAuthRocket(downloadURL, b.user.Token, b.user.ID)
if err != nil {
return fmt.Errorf("download %s failed %#v", downloadURL, err)
}
helper.HandleDownloadData(b.Log, rmsg, file.Title, rmsg.Text, downloadURL, data, b.General)
return nil
}
func (b *Brocketchat) handleUploadFile(msg *config.Message) error {
for _, f := range msg.Extra["file"] {
fi := f.(config.FileInfo)

View File

@@ -156,7 +156,7 @@ func (b *Bslack) JoinChannel(channel config.ChannelInfo) error {
// try to join a channel when in legacy
if b.legacy {
_, err := b.sc.JoinChannel(channel.Name)
_, _, _, err := b.sc.JoinConversation(channel.Name)
if err != nil {
switch err.Error() {
case "name_taken", "restricted_action":
@@ -195,7 +195,7 @@ func (b *Bslack) Send(msg config.Message) (string, error) {
b.Log.Debugf("=> Receiving %#v", msg)
}
msg.Text = helper.ClipMessage(msg.Text, messageLength)
msg.Text = helper.ClipMessage(msg.Text, messageLength, b.GetString("MessageClipped"))
msg.Text = b.replaceCodeFence(msg.Text)
// Make a action /me of the message
@@ -299,7 +299,7 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
}
// Handle prefix hint for unthreaded messages.
if msg.ParentID == "msg-parent-not-found" {
if msg.ParentNotFound() {
msg.ParentID = ""
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
}

View File

@@ -283,7 +283,7 @@ func (b *channels) populateChannels(wait bool) {
// We only retrieve public and private channels, not IMs
// and MPIMs as those do not have a channel name.
queryParams := &slack.GetConversationsParameters{
ExcludeArchived: "true",
ExcludeArchived: true,
Types: []string{"public_channel,private_channel"},
}
for {

View File

@@ -2,7 +2,7 @@ package btelegram
import (
"html"
"regexp"
"path/filepath"
"strconv"
"strings"
"unicode/utf16"
@@ -181,13 +181,15 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
// sends a EVENT_AVATAR_DOWNLOAD message to the gateway if successful.
// logs an error message if it fails
func (b *Btelegram) handleDownloadAvatar(userid int, channel string) {
rmsg := config.Message{Username: "system",
Text: "avatar",
Channel: channel,
Account: b.Account,
UserID: strconv.Itoa(userid),
Event: config.EventAvatarDownload,
Extra: make(map[string][]interface{})}
rmsg := config.Message{
Username: "system",
Text: "avatar",
Channel: channel,
Account: b.Account,
UserID: strconv.Itoa(userid),
Event: config.EventAvatarDownload,
Extra: make(map[string][]interface{}),
}
if _, ok := b.avatarMap[strconv.Itoa(userid)]; !ok {
photos, err := b.c.GetUserProfilePhotos(tgbotapi.UserProfilePhotosConfig{UserID: userid, Limit: 1})
@@ -311,6 +313,11 @@ func (b *Btelegram) handleDownload(rmsg *config.Message, message *tgbotapi.Messa
b.maybeConvertWebp(&name, data)
}
// rename .oga to .ogg https://github.com/42wim/matterbridge/issues/906#issuecomment-741793512
if strings.HasSuffix(name, ".oga") && message.Audio != nil {
name = strings.Replace(name, ".oga", ".ogg", 1)
}
helper.HandleDownloadData(b.Log, rmsg, name, message.Caption, "", data, b.General)
return nil
}
@@ -384,21 +391,32 @@ func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64) string {
Name: fi.Name,
Bytes: *fi.Data,
}
re := regexp.MustCompile(".(jpg|png)$")
if re.MatchString(fi.Name) {
c = tgbotapi.NewPhotoUpload(chatid, file)
} else {
c = tgbotapi.NewDocumentUpload(chatid, file)
switch filepath.Ext(fi.Name) {
case ".jpg", ".jpe", ".png":
pc := tgbotapi.NewPhotoUpload(chatid, file)
pc.Caption, pc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment)
c = pc
case ".mp4", ".m4v":
vc := tgbotapi.NewVideoUpload(chatid, file)
vc.Caption, vc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment)
c = vc
case ".mp3", ".oga":
ac := tgbotapi.NewAudioUpload(chatid, file)
ac.Caption, ac.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment)
c = ac
case ".ogg":
voc := tgbotapi.NewVoiceUpload(chatid, file)
voc.Caption, voc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment)
c = voc
default:
dc := tgbotapi.NewDocumentUpload(chatid, file)
dc.Caption, dc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment)
c = dc
}
_, err := b.c.Send(c)
if err != nil {
b.Log.Errorf("file upload failed: %#v", err)
}
if fi.Comment != "" {
if _, err := b.sendMessage(chatid, msg.Username, fi.Comment); err != nil {
b.Log.Errorf("posting file comment %s failed: %s", fi.Comment, err)
}
}
}
return ""
}
@@ -408,7 +426,7 @@ func (b *Btelegram) handleQuote(message, quoteNick, quoteMessage string) string
if format == "" {
format = "{MESSAGE} (re @{QUOTENICK}: {QUOTEMESSAGE})"
}
quoteMessagelength := len(quoteMessage)
quoteMessagelength := len([]rune(quoteMessage))
if b.GetInt("QuoteLengthLimit") != 0 && quoteMessagelength >= b.GetInt("QuoteLengthLimit") {
runes := []rune(quoteMessage)
quoteMessage = string(runes[0:b.GetInt("QuoteLengthLimit")])

View File

@@ -69,6 +69,28 @@ func (b *Btelegram) JoinChannel(channel config.ChannelInfo) error {
return nil
}
func TGGetParseMode(b *Btelegram, username string, text string) (textout string, parsemode string) {
textout = username + text
if b.GetString("MessageFormat") == HTMLFormat {
b.Log.Debug("Using mode HTML")
parsemode = tgbotapi.ModeHTML
}
if b.GetString("MessageFormat") == "Markdown" {
b.Log.Debug("Using mode markdown")
parsemode = tgbotapi.ModeMarkdown
}
if b.GetString("MessageFormat") == MarkdownV2 {
b.Log.Debug("Using mode MarkdownV2")
parsemode = MarkdownV2
}
if strings.ToLower(b.GetString("MessageFormat")) == HTMLNick {
b.Log.Debug("Using mode HTML - nick only")
textout = username + html.EscapeString(text)
parsemode = tgbotapi.ModeHTML
}
return textout, parsemode
}
func (b *Btelegram) Send(msg config.Message) (string, error) {
b.Log.Debugf("=> Receiving %#v", msg)
@@ -131,24 +153,7 @@ func (b *Btelegram) getFileDirectURL(id string) string {
func (b *Btelegram) sendMessage(chatid int64, username, text string) (string, error) {
m := tgbotapi.NewMessage(chatid, "")
m.Text = username + text
if b.GetString("MessageFormat") == HTMLFormat {
b.Log.Debug("Using mode HTML")
m.ParseMode = tgbotapi.ModeHTML
}
if b.GetString("MessageFormat") == "Markdown" {
b.Log.Debug("Using mode markdown")
m.ParseMode = tgbotapi.ModeMarkdown
}
if b.GetString("MessageFormat") == MarkdownV2 {
b.Log.Debug("Using mode MarkdownV2")
m.ParseMode = MarkdownV2
}
if strings.ToLower(b.GetString("MessageFormat")) == HTMLNick {
b.Log.Debug("Using mode HTML - nick only")
m.Text = username + html.EscapeString(text)
m.ParseMode = tgbotapi.ModeHTML
}
m.Text, m.ParseMode = TGGetParseMode(b, username, text)
m.DisableWebPagePreview = b.GetBool("DisableWebPagePreview")

327
bridge/vk/vk.go Normal file
View File

@@ -0,0 +1,327 @@
package bvk
import (
"bytes"
"context"
"regexp"
"strconv"
"strings"
"time"
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
"github.com/SevereCloud/vksdk/v2/api"
"github.com/SevereCloud/vksdk/v2/events"
longpoll "github.com/SevereCloud/vksdk/v2/longpoll-bot"
"github.com/SevereCloud/vksdk/v2/object"
)
const (
audioMessage = "audio_message"
document = "doc"
photo = "photo"
video = "video"
graffiti = "graffiti"
sticker = "sticker"
wall = "wall"
)
type user struct {
lastname, firstname, avatar string
}
type Bvk struct {
c *api.VK
usernamesMap map[int]user // cache of user names and avatar URLs
*bridge.Config
}
func New(cfg *bridge.Config) bridge.Bridger {
return &Bvk{usernamesMap: make(map[int]user), Config: cfg}
}
func (b *Bvk) Connect() error {
b.Log.Info("Connecting")
b.c = api.NewVK(b.GetString("Token"))
lp, err := longpoll.NewLongPoll(b.c, b.GetInt("GroupID"))
if err != nil {
b.Log.Debugf("%#v", err)
return err
}
lp.MessageNew(func(ctx context.Context, obj events.MessageNewObject) {
b.handleMessage(obj.Message, false)
})
b.Log.Info("Connection succeeded")
go func() {
err := lp.Run()
if err != nil {
b.Log.Fatal("Enable longpoll in group management")
}
}()
return nil
}
func (b *Bvk) Disconnect() error {
return nil
}
func (b *Bvk) JoinChannel(channel config.ChannelInfo) error {
return nil
}
func (b *Bvk) Send(msg config.Message) (string, error) {
b.Log.Debugf("=> Receiving %#v", msg)
peerID, err := strconv.Atoi(msg.Channel)
if err != nil {
return "", err
}
params := api.Params{}
text := msg.Username + msg.Text
if msg.Extra != nil {
if len(msg.Extra["file"]) > 0 {
// generate attachments string
attachment, urls := b.uploadFiles(msg.Extra, peerID)
params["attachment"] = attachment
text += urls
}
}
params["message"] = text
if msg.ID == "" {
// New message
params["random_id"] = time.Now().Unix()
params["peer_ids"] = msg.Channel
res, e := b.c.MessagesSendPeerIDs(params)
if e != nil {
return "", err
}
return strconv.Itoa(res[0].ConversationMessageID), nil
}
// Edit message
messageID, err := strconv.ParseInt(msg.ID, 10, 64)
if err != nil {
return "", err
}
params["peer_id"] = peerID
params["conversation_message_id"] = messageID
_, err = b.c.MessagesEdit(params)
if err != nil {
return "", err
}
return msg.ID, nil
}
func (b *Bvk) getUser(id int) user {
u, found := b.usernamesMap[id]
if !found {
b.Log.Debug("Fetching username for ", id)
if id >= 0 {
result, _ := b.c.UsersGet(api.Params{
"user_ids": id,
"fields": "photo_200",
})
resUser := result[0]
u = user{lastname: resUser.LastName, firstname: resUser.FirstName, avatar: resUser.Photo200}
b.usernamesMap[id] = u
} else {
result, _ := b.c.GroupsGetByID(api.Params{
"group_id": id * -1,
})
resGroup := result[0]
u = user{lastname: resGroup.Name, avatar: resGroup.Photo200}
}
}
return u
}
func (b *Bvk) handleMessage(msg object.MessagesMessage, isFwd bool) {
b.Log.Debug("ChatID: ", msg.PeerID)
// fetch user info
u := b.getUser(msg.FromID)
rmsg := config.Message{
Text: msg.Text,
Username: u.firstname + " " + u.lastname,
Avatar: u.avatar,
Channel: strconv.Itoa(msg.PeerID),
Account: b.Account,
UserID: strconv.Itoa(msg.FromID),
ID: strconv.Itoa(msg.ConversationMessageID),
Extra: make(map[string][]interface{}),
}
if msg.ReplyMessage != nil {
ur := b.getUser(msg.ReplyMessage.FromID)
rmsg.Text = "Re: " + ur.firstname + " " + ur.lastname + "\n" + rmsg.Text
}
if isFwd {
rmsg.Username = "Fwd: " + rmsg.Username
}
if len(msg.Attachments) > 0 {
urls, text := b.getFiles(msg.Attachments)
if text != "" {
rmsg.Text += "\n" + text
}
// download
b.downloadFiles(&rmsg, urls)
}
if len(msg.FwdMessages) > 0 {
rmsg.Text += strconv.Itoa(len(msg.FwdMessages)) + " forwarded messages"
}
b.Remote <- rmsg
if len(msg.FwdMessages) > 0 {
// recursive processing of forwarded messages
for _, m := range msg.FwdMessages {
m.PeerID = msg.PeerID
b.handleMessage(m, true)
}
}
}
func (b *Bvk) uploadFiles(extra map[string][]interface{}, peerID int) (string, string) {
var attachments []string
text := ""
for _, f := range extra["file"] {
fi := f.(config.FileInfo)
if fi.Comment != "" {
text += fi.Comment + "\n"
}
a, err := b.uploadFile(fi, peerID)
if err != nil {
b.Log.Error("File upload error ", fi.Name)
}
attachments = append(attachments, a)
}
return strings.Join(attachments, ","), text
}
func (b *Bvk) uploadFile(file config.FileInfo, peerID int) (string, error) {
r := bytes.NewReader(*file.Data)
photoRE := regexp.MustCompile(".(jpg|jpe|png)$")
if photoRE.MatchString(file.Name) {
p, err := b.c.UploadMessagesPhoto(peerID, r)
if err != nil {
return "", err
}
return photo + strconv.Itoa(p[0].OwnerID) + "_" + strconv.Itoa(p[0].ID), nil
}
var doctype string
if strings.Contains(file.Name, ".ogg") {
doctype = audioMessage
} else {
doctype = document
}
doc, err := b.c.UploadMessagesDoc(peerID, doctype, file.Name, "", r)
if err != nil {
return "", err
}
switch doc.Type {
case audioMessage:
return document + strconv.Itoa(doc.AudioMessage.OwnerID) + "_" + strconv.Itoa(doc.AudioMessage.ID), nil
case document:
return document + strconv.Itoa(doc.Doc.OwnerID) + "_" + strconv.Itoa(doc.Doc.ID), nil
}
return "", nil
}
func (b *Bvk) getFiles(attachments []object.MessagesMessageAttachment) ([]string, string) {
var urls []string
var text []string
for _, a := range attachments {
switch a.Type {
case photo:
var resolution float64 = 0
url := a.Photo.Sizes[0].URL
for _, size := range a.Photo.Sizes {
r := size.Height * size.Width
if resolution < r {
resolution = r
url = size.URL
}
}
urls = append(urls, url)
case document:
urls = append(urls, a.Doc.URL)
case graffiti:
urls = append(urls, a.Graffiti.URL)
case audioMessage:
urls = append(urls, a.AudioMessage.DocsDocPreviewAudioMessage.LinkOgg)
case sticker:
var resolution float64 = 0
url := a.Sticker.Images[0].URL
for _, size := range a.Sticker.Images {
r := size.Height * size.Width
if resolution < r {
resolution = r
url = size.URL
}
}
urls = append(urls, url+".png")
case video:
text = append(text, "https://vk.com/video"+strconv.Itoa(a.Video.OwnerID)+"_"+strconv.Itoa(a.Video.ID))
case wall:
text = append(text, "https://vk.com/wall"+strconv.Itoa(a.Wall.FromID)+"_"+strconv.Itoa(a.Wall.ID))
default:
text = append(text, "This attachment is not supported ("+a.Type+")")
}
}
return urls, strings.Join(text, "\n")
}
func (b *Bvk) downloadFiles(rmsg *config.Message, urls []string) {
for _, url := range urls {
data, err := helper.DownloadFile(url)
if err == nil {
urlPart := strings.Split(url, "/")
name := strings.Split(urlPart[len(urlPart)-1], "?")[0]
helper.HandleDownloadData(b.Log, rmsg, name, "", url, data, b.General)
}
}
}

View File

@@ -24,7 +24,8 @@ Check:
func (b *Bwhatsapp) HandleError(err error) {
// ignore received invalid data errors. https://github.com/42wim/matterbridge/issues/843
// ignore tag 174 errors. https://github.com/42wim/matterbridge/issues/1094
if strings.Contains(err.Error(), "error processing data: received invalid data") || strings.Contains(err.Error(), "invalid string with tag 174") {
if strings.Contains(err.Error(), "error processing data: received invalid data") ||
strings.Contains(err.Error(), "invalid string with tag 174") {
return
}
@@ -47,16 +48,22 @@ func (b *Bwhatsapp) reconnect(err error) {
Max: 5 * time.Minute,
Jitter: true,
}
for {
d := bf.Duration()
b.Log.Errorf("Connection failed, underlying error: %v", err)
b.Log.Infof("Waiting %s...", d)
time.Sleep(d)
b.Log.Info("Reconnecting...")
err := b.conn.Restore()
if err == nil {
bf.Reset()
b.startedAt = uint64(time.Now().Unix())
return
}
}
@@ -64,7 +71,7 @@ func (b *Bwhatsapp) reconnect(err error) {
// HandleTextMessage sent from WhatsApp, relay it to the brige
func (b *Bwhatsapp) HandleTextMessage(message whatsapp.TextMessage) {
if message.Info.FromMe { // || !strings.Contains(strings.ToLower(message.Text), "@echo") {
if message.Info.FromMe {
return
}
// whatsapp sends last messages to show context , cut them
@@ -72,12 +79,10 @@ func (b *Bwhatsapp) HandleTextMessage(message whatsapp.TextMessage) {
return
}
messageTime := time.Unix(int64(message.Info.Timestamp), 0) // TODO check how behaves between timezones
groupJID := message.Info.RemoteJid
senderJID := message.Info.SenderJid
if len(senderJID) == 0 {
// TODO workaround till https://github.com/Rhymen/go-whatsapp/issues/86 resolved
if message.Info.Source != nil && message.Info.Source.Participant != nil {
senderJID = *message.Info.Source.Participant
}
@@ -101,110 +106,275 @@ func (b *Bwhatsapp) HandleTextMessage(message whatsapp.TextMessage) {
if mention == "" {
mention = "someone"
}
message.Text = strings.Replace(message.Text, "@"+numberAndSuffix[0], "@"+mention, 1)
}
}
b.Log.Debugf("<= Sending message from %s on %s to gateway", senderJID, b.Account)
rmsg := config.Message{
UserID: senderJID,
Username: senderName,
Text: message.Text,
Timestamp: messageTime,
Channel: groupJID,
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
UserID: senderJID,
Username: senderName,
Text: message.Text,
Channel: groupJID,
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
// ParentID: TODO, // TODO handle thread replies // map from Info.QuotedMessageID string
// Event string `json:"event"`
// Gateway string // will be added during message processing
ID: message.Info.Id}
ID: message.Info.Id,
}
if avatarURL, exists := b.userAvatars[senderJID]; exists {
rmsg.Avatar = avatarURL
}
b.Log.Debugf("<= Sending message from %s on %s to gateway", senderJID, b.Account)
b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg
}
// HandleImageMessage sent from WhatsApp, relay it to the brige
func (b *Bwhatsapp) HandleImageMessage(message whatsapp.ImageMessage) {
if message.Info.FromMe { // || !strings.Contains(strings.ToLower(message.Text), "@echo") {
if message.Info.FromMe || message.Info.Timestamp < b.startedAt {
return
}
// whatsapp sends last messages to show context , cut them
if message.Info.Timestamp < b.startedAt {
return
}
messageTime := time.Unix(int64(message.Info.Timestamp), 0) // TODO check how behaves between timezones
groupJID := message.Info.RemoteJid
senderJID := message.Info.SenderJid
if len(senderJID) == 0 {
// TODO workaround till https://github.com/Rhymen/go-whatsapp/issues/86 resolved
if message.Info.Source != nil && message.Info.Source.Participant != nil {
senderJID = *message.Info.Source.Participant
}
if len(message.Info.SenderJid) == 0 && message.Info.Source != nil && message.Info.Source.Participant != nil {
senderJID = *message.Info.Source.Participant
}
// translate sender's Jid to the nicest username we can get
senderName := b.getSenderName(senderJID)
senderName := b.getSenderName(message.Info.SenderJid)
if senderName == "" {
senderName = "Someone" // don't expose telephone number
}
b.Log.Debugf("<= Sending message from %s on %s to gateway", senderJID, b.Account)
rmsg := config.Message{
UserID: senderJID,
Username: senderName,
Timestamp: messageTime,
Channel: groupJID,
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
// ParentID: TODO, // TODO handle thread replies // map from Info.QuotedMessageID string
// Event string `json:"event"`
// Gateway string // will be added during message processing
ID: message.Info.Id}
UserID: senderJID,
Username: senderName,
Channel: message.Info.RemoteJid,
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
ID: message.Info.Id,
}
if avatarURL, exists := b.userAvatars[senderJID]; exists {
rmsg.Avatar = avatarURL
}
// Download and unencrypt content
data, err := message.Download()
fileExt, err := mime.ExtensionsByType(message.Type)
if err != nil {
b.Log.Errorf("%v", err)
b.Log.Errorf("Mimetype detection error: %s", err)
return
}
// Get file extension by mimetype
fileExt, err := mime.ExtensionsByType(message.Type)
if err != nil {
b.Log.Errorf("%v", err)
return
// rename .jfif to .jpg https://github.com/42wim/matterbridge/issues/1292
if fileExt[0] == ".jfif" {
fileExt[0] = ".jpg"
}
// rename .jpe to .jpg https://github.com/42wim/matterbridge/issues/1463
if fileExt[0] == ".jpe" {
fileExt[0] = ".jpg"
}
filename := fmt.Sprintf("%v%v", message.Info.Id, fileExt[0])
b.Log.Debugf("<= Image downloaded and unencrypted")
b.Log.Debugf("Trying to download %s with type %s", filename, message.Type)
data, err := message.Download()
if err != nil {
b.Log.Errorf("Download image failed: %s", err)
return
}
// Move file to bridge storage
helper.HandleDownloadData(b.Log, &rmsg, filename, message.Caption, "", &data, b.General)
b.Log.Debugf("<= Image Message is %#v", rmsg)
b.Log.Debugf("<= Sending message from %s on %s to gateway", senderJID, b.Account)
b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg
}
//func (b *Bwhatsapp) HandleVideoMessage(message whatsapp.VideoMessage) {
// fmt.Println(message) // TODO implement
//}
//
//func (b *Bwhatsapp) HandleJsonMessage(message string) {
// fmt.Println(message) // TODO implement
//}
// TODO HandleRawMessage
// TODO HandleAudioMessage
// HandleVideoMessage downloads video messages
func (b *Bwhatsapp) HandleVideoMessage(message whatsapp.VideoMessage) {
if message.Info.FromMe || message.Info.Timestamp < b.startedAt {
return
}
senderJID := message.Info.SenderJid
if len(message.Info.SenderJid) == 0 && message.Info.Source != nil && message.Info.Source.Participant != nil {
senderJID = *message.Info.Source.Participant
}
senderName := b.getSenderName(message.Info.SenderJid)
if senderName == "" {
senderName = "Someone" // don't expose telephone number
}
rmsg := config.Message{
UserID: senderJID,
Username: senderName,
Channel: message.Info.RemoteJid,
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
ID: message.Info.Id,
}
if avatarURL, exists := b.userAvatars[senderJID]; exists {
rmsg.Avatar = avatarURL
}
fileExt, err := mime.ExtensionsByType(message.Type)
if err != nil {
b.Log.Errorf("Mimetype detection error: %s", err)
return
}
if len(fileExt) == 0 {
fileExt = append(fileExt, ".mp4")
}
filename := fmt.Sprintf("%v%v", message.Info.Id, fileExt[0])
b.Log.Debugf("Trying to download %s with size %#v and type %s", filename, message.Length, message.Type)
data, err := message.Download()
if err != nil {
b.Log.Errorf("Download video failed: %s", err)
return
}
// Move file to bridge storage
helper.HandleDownloadData(b.Log, &rmsg, filename, message.Caption, "", &data, b.General)
b.Log.Debugf("<= Sending message from %s on %s to gateway", senderJID, b.Account)
b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg
}
// HandleAudioMessage downloads audio messages
func (b *Bwhatsapp) HandleAudioMessage(message whatsapp.AudioMessage) {
if message.Info.FromMe || message.Info.Timestamp < b.startedAt {
return
}
senderJID := message.Info.SenderJid
if len(message.Info.SenderJid) == 0 && message.Info.Source != nil && message.Info.Source.Participant != nil {
senderJID = *message.Info.Source.Participant
}
senderName := b.getSenderName(message.Info.SenderJid)
if senderName == "" {
senderName = "Someone" // don't expose telephone number
}
rmsg := config.Message{
UserID: senderJID,
Username: senderName,
Channel: message.Info.RemoteJid,
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
ID: message.Info.Id,
}
if avatarURL, exists := b.userAvatars[senderJID]; exists {
rmsg.Avatar = avatarURL
}
fileExt, err := mime.ExtensionsByType(message.Type)
if err != nil {
b.Log.Errorf("Mimetype detection error: %s", err)
return
}
if len(fileExt) == 0 {
fileExt = append(fileExt, ".ogg")
}
filename := fmt.Sprintf("%v%v", message.Info.Id, fileExt[0])
b.Log.Debugf("Trying to download %s with size %#v and type %s", filename, message.Length, message.Type)
data, err := message.Download()
if err != nil {
b.Log.Errorf("Download audio failed: %s", err)
return
}
// Move file to bridge storage
helper.HandleDownloadData(b.Log, &rmsg, filename, "audio message", "", &data, b.General)
b.Log.Debugf("<= Sending message from %s on %s to gateway", senderJID, b.Account)
b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg
}
// HandleDocumentMessage downloads documents
func (b *Bwhatsapp) HandleDocumentMessage(message whatsapp.DocumentMessage) {
if message.Info.FromMe || message.Info.Timestamp < b.startedAt {
return
}
senderJID := message.Info.SenderJid
if len(message.Info.SenderJid) == 0 && message.Info.Source != nil && message.Info.Source.Participant != nil {
senderJID = *message.Info.Source.Participant
}
senderName := b.getSenderName(message.Info.SenderJid)
if senderName == "" {
senderName = "Someone" // don't expose telephone number
}
rmsg := config.Message{
UserID: senderJID,
Username: senderName,
Channel: message.Info.RemoteJid,
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
ID: message.Info.Id,
}
if avatarURL, exists := b.userAvatars[senderJID]; exists {
rmsg.Avatar = avatarURL
}
fileExt, err := mime.ExtensionsByType(message.Type)
if err != nil {
b.Log.Errorf("Mimetype detection error: %s", err)
return
}
filename := fmt.Sprintf("%v", message.FileName)
b.Log.Debugf("Trying to download %s with extension %s and type %s", filename, fileExt, message.Type)
data, err := message.Download()
if err != nil {
b.Log.Errorf("Download document message failed: %s", err)
return
}
// Move file to bridge storage
helper.HandleDownloadData(b.Log, &rmsg, filename, "document", "", &data, b.General)
b.Log.Debugf("<= Sending message from %s on %s to gateway", senderJID, b.Account)
b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg
}

View File

@@ -6,22 +6,24 @@ import (
"errors"
"fmt"
"os"
"strings"
qrcodeTerminal "github.com/Baozisoftware/qrcode-terminal-go"
"github.com/Rhymen/go-whatsapp"
)
type ProfilePicInfo struct {
URL string `json:"eurl"`
Tag string `json:"tag"`
Status int16 `json:"status"`
URL string `json:"eurl"`
Tag string `json:"tag"`
Status int16 `json:"status"`
}
func qrFromTerminal(invert bool) chan string {
qr := make(chan string)
go func() {
terminal := qrcodeTerminal.New()
if invert {
terminal = qrcodeTerminal.New2(qrcodeTerminal.ConsoleColors.BrightWhite, qrcodeTerminal.ConsoleColors.BrightBlack, qrcodeTerminal.QRCodeRecoveryLevels.Medium)
}
@@ -44,13 +46,12 @@ func (b *Bwhatsapp) readSession() (whatsapp.Session, error) {
if err != nil {
return session, err
}
defer file.Close()
decoder := gob.NewDecoder(file)
err = decoder.Decode(&session)
if err != nil {
return session, err
}
return session, nil
return session, decoder.Decode(&session)
}
func (b *Bwhatsapp) writeSession(session whatsapp.Session) error {
@@ -65,11 +66,31 @@ func (b *Bwhatsapp) writeSession(session whatsapp.Session) error {
if err != nil {
return err
}
defer file.Close()
encoder := gob.NewEncoder(file)
err = encoder.Encode(session)
return err
defer file.Close()
encoder := gob.NewEncoder(file)
return encoder.Encode(session)
}
func (b *Bwhatsapp) restoreSession() (*whatsapp.Session, error) {
session, err := b.readSession()
if err != nil {
b.Log.Warn(err.Error())
}
b.Log.Debugln("Restoring WhatsApp session..")
session, err = b.conn.RestoreWithSession(session)
if err != nil {
// restore session connection timed out (I couldn't get over it without logging in again)
return nil, errors.New("failed to restore session: " + err.Error())
}
b.Log.Debugln("Session restored successfully!")
return &session, nil
}
func (b *Bwhatsapp) getSenderName(senderJid string) string {
@@ -114,6 +135,7 @@ func (b *Bwhatsapp) getSenderNotify(senderJid string) string {
if sender, exists := b.users[senderJid]; exists {
return sender.Notify
}
return ""
}
@@ -122,11 +144,20 @@ func (b *Bwhatsapp) GetProfilePicThumb(jid string) (*ProfilePicInfo, error) {
if err != nil {
return nil, fmt.Errorf("failed to get avatar: %v", err)
}
content := <-data
info := &ProfilePicInfo{}
err = json.Unmarshal([]byte(content), info)
if err != nil {
return info, fmt.Errorf("failed to unmarshal avatar info: %v", err)
}
return info, nil
}
func isGroupJid(identifier string) bool {
return strings.HasSuffix(identifier, "@g.us") ||
strings.HasSuffix(identifier, "@temp") ||
strings.HasSuffix(identifier, "@broadcast")
}

View File

@@ -28,7 +28,6 @@ const (
type Bwhatsapp struct {
*bridge.Config
// https://github.com/Rhymen/go-whatsapp/blob/c31092027237441cffba1b9cb148eadf7c83c3d2/session.go#L18-L21
session *whatsapp.Session
conn *whatsapp.Conn
startedAt uint64
@@ -40,6 +39,7 @@ type Bwhatsapp struct {
// New Create a new WhatsApp bridge. This will be called for each [whatsapp.<server>] entry you have in the config file
func New(cfg *bridge.Config) bridge.Bridger {
number := cfg.GetString(cfgNumber)
if number == "" {
cfg.Log.Fatalf("Missing configuration for WhatsApp bridge: Number")
}
@@ -50,21 +50,17 @@ func New(cfg *bridge.Config) bridge.Bridger {
users: make(map[string]whatsapp.Contact),
userAvatars: make(map[string]string),
}
return b
}
// Connect to WhatsApp. Required implementation of the Bridger interface
// https://github.com/42wim/matterbridge/blob/2cfd880cdb0df29771bf8f31df8d990ab897889d/bridge/bridge.go#L11-L16
func (b *Bwhatsapp) Connect() error {
b.RLock() // TODO do we need locking for Whatsapp?
defer b.RUnlock()
number := b.GetString(cfgNumber)
if number == "" {
return errors.New("WhatsApp's telephone Number need to be configured")
return errors.New("whatsapp's telephone number need to be configured")
}
// https://github.com/Rhymen/go-whatsapp#creating-a-connection
b.Log.Debugln("Connecting to WhatsApp..")
conn, err := whatsapp.NewConn(20 * time.Second)
if err != nil {
@@ -77,35 +73,18 @@ func (b *Bwhatsapp) Connect() error {
b.Log.Debugln("WhatsApp connection successful")
// load existing session in order to keep it between restarts
if b.session == nil {
var session whatsapp.Session
session, err = b.readSession()
if err == nil {
b.Log.Debugln("Restoring WhatsApp session..")
// https://github.com/Rhymen/go-whatsapp#restore
session, err = b.conn.RestoreWithSession(session)
if err != nil {
// TODO return or continue to normal login?
// restore session connection timed out (I couldn't get over it without logging in again)
return errors.New("failed to restore session: " + err.Error())
}
b.session = &session
b.Log.Debugln("Session restored successfully!")
} else {
b.Log.Warn(err.Error())
}
b.session, err = b.restoreSession()
if err != nil {
b.Log.Warn(err.Error())
}
// login to a new session
if b.session == nil {
err = b.Login()
if err != nil {
if err = b.Login(); err != nil {
return err
}
}
b.startedAt = uint64(time.Now().Unix())
_, err = b.conn.Contacts()
@@ -116,6 +95,7 @@ func (b *Bwhatsapp) Connect() error {
// see https://github.com/Rhymen/go-whatsapp/issues/137#issuecomment-480316013
for len(b.conn.Store.Contacts) == 0 {
b.conn.Contacts() // nolint:errcheck
<-time.After(1 * time.Second)
}
@@ -135,12 +115,13 @@ func (b *Bwhatsapp) Connect() error {
info, err := b.GetProfilePicThumb(jid)
if err != nil {
b.Log.Warnf("Could not get profile photo of %s: %v", jid, err)
} else {
// TODO any race conditions here?
b.Lock()
b.userAvatars[jid] = info.URL
b.Unlock()
}
}
b.Log.Debug("Finished getting avatars..")
}()
@@ -157,8 +138,10 @@ func (b *Bwhatsapp) Login() error {
session, err := b.conn.Login(qrChan)
if err != nil {
b.Log.Warnln("Failed to log in:", err)
return err
}
b.session = &session
b.Log.Infof("Logged into session: %#v", session)
@@ -169,29 +152,17 @@ func (b *Bwhatsapp) Login() error {
fmt.Fprintf(os.Stderr, "error saving session: %v\n", err)
}
// TODO change connection strings to configured ones longClientName:"github.com/rhymen/go-whatsapp", shortClientName:"go-whatsapp"}" prefix=whatsapp
// TODO get also a nice logo
// TODO notification about unplugged and dead battery
// conn.Info: Wid, Pushname, Connected, Battery, Plugged
return nil
}
// Disconnect is called while reconnecting to the bridge
// TODO 42wim Documentation would be helpful on when reconnects happen and what should be done in this function
// Required implementation of the Bridger interface
// https://github.com/42wim/matterbridge/blob/2cfd880cdb0df29771bf8f31df8d990ab897889d/bridge/bridge.go#L11-L16
func (b *Bwhatsapp) Disconnect() error {
// We could Logout, but that would close the session completely and would require a new QR code scan
// https://github.com/Rhymen/go-whatsapp/blob/c31092027237441cffba1b9cb148eadf7c83c3d2/session.go#L377-L381
return nil
}
func isGroupJid(identifier string) bool {
return strings.HasSuffix(identifier, "@g.us") || strings.HasSuffix(identifier, "@temp") || strings.HasSuffix(identifier, "@broadcast")
}
// JoinChannel Join a WhatsApp group specified in gateway config as channel='number-id@g.us' or channel='Channel name'
// Required implementation of the Bridger interface
// https://github.com/42wim/matterbridge/blob/2cfd880cdb0df29771bf8f31df8d990ab897889d/bridge/bridge.go#L11-L16
@@ -210,39 +181,33 @@ func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error {
if _, exists := b.conn.Store.Contacts[channel.Name]; !exists {
return fmt.Errorf("account doesn't belong to group with jid %s", channel.Name)
}
} else {
// channel.Name specifies group name that might change, warn about it
var jids []string
for id, contact := range b.conn.Store.Contacts {
if isGroupJid(id) && contact.Name == channel.Name {
jids = append(jids, id)
}
}
switch len(jids) {
case 0:
// didn't match any group - print out possibilites
// TODO sort
// copy b;
//sort.Slice(people, func(i, j int) bool {
// return people[i].Age > people[j].Age
//})
for id, contact := range b.conn.Store.Contacts {
if isGroupJid(id) {
b.Log.Infof("%s %s", contact.Jid, contact.Name)
}
}
return fmt.Errorf("please specify group's JID from the list above instead of the name '%s'", channel.Name)
return nil
}
case 1:
return fmt.Errorf("group name might change. Please configure gateway with channel=\"%v\" instead of channel=\"%v\"", jids[0], channel.Name)
default:
return fmt.Errorf("there is more than one group with name '%s'. Please specify one of JIDs as channel name: %v", channel.Name, jids)
// channel.Name specifies group name that might change, warn about it
var jids []string
for id, contact := range b.conn.Store.Contacts {
if isGroupJid(id) && contact.Name == channel.Name {
jids = append(jids, id)
}
}
return nil
switch len(jids) {
case 0:
// didn't match any group - print out possibilites
for id, contact := range b.conn.Store.Contacts {
if isGroupJid(id) {
b.Log.Infof("%s %s", contact.Jid, contact.Name)
}
}
return fmt.Errorf("please specify group's JID from the list above instead of the name '%s'", channel.Name)
case 1:
return fmt.Errorf("group name might change. Please configure gateway with channel=\"%v\" instead of channel=\"%v\"", jids[0], channel.Name)
default:
return fmt.Errorf("there is more than one group with name '%s'. Please specify one of JIDs as channel name: %v", channel.Name, jids)
}
}
// Post a document message from the bridge to WhatsApp
@@ -316,14 +281,12 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
if msg.ID == "" {
// No message ID in case action is executed on a message sent before the bridge was started
// and then the bridge cache doesn't have this message ID mapped
// TODO 42wim Doesn't the app get clogged with a ton of IDs after some time of running?
// WhatsApp allows to set any ID so in that case we could use external IDs and don't do mapping
// but external IDs are not set
return "", nil
}
// TODO delete message on WhatsApp https://github.com/Rhymen/go-whatsapp/issues/100
return "", nil
_, err := b.conn.RevokeMessage(msg.Channel, msg.ID, true)
return "", err
}
// Edit message
@@ -331,7 +294,6 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
b.Log.Debugf("updating message with id %s", msg.ID)
msg.Text += " (edited)"
// TODO handle edit as a message reply with updated text
}
// Handle Upload a file
@@ -361,16 +323,7 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
b.Log.Debugf("=> Sending %#v", msg)
// create message ID
// TODO follow and act if https://github.com/Rhymen/go-whatsapp/issues/101 implemented
idBytes := make([]byte, 10)
if _, err := rand.Read(idBytes); err != nil {
b.Log.Warn(err.Error())
}
message.Info.Id = strings.ToUpper(hex.EncodeToString(idBytes))
_, err := b.conn.Send(message)
return message.Info.Id, err
return b.conn.Send(message)
}
// TODO do we want that? to allow login with QR code from a bridged channel? https://github.com/tulir/mautrix-whatsapp/blob/513eb18e2d59bada0dd515ee1abaaf38a3bfe3d5/commands.go#L76

View File

@@ -1,8 +1,12 @@
package bxmpp
import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
"sync"
"time"
@@ -86,14 +90,21 @@ func (b *Bxmpp) Send(msg config.Message) (string, error) {
}
// Upload a file (in XMPP case send the upload URL because XMPP has no native upload support).
var err error
if msg.Extra != nil {
for _, rmsg := range helper.HandleExtra(&msg, b.General) {
b.Log.Debugf("=> Sending attachement message %#v", rmsg)
if _, err := b.xc.Send(xmpp.Chat{
Type: "groupchat",
Remote: rmsg.Channel + "@" + b.GetString("Muc"),
Text: rmsg.Username + rmsg.Text,
}); err != nil {
if b.GetString("WebhookURL") != "" {
err = b.postSlackCompatibleWebhook(msg)
} else {
_, err = b.xc.Send(xmpp.Chat{
Type: "groupchat",
Remote: rmsg.Channel + "@" + b.GetString("Muc"),
Text: rmsg.Username + rmsg.Text,
})
}
if err != nil {
b.Log.WithError(err).Error("Unable to send message with share URL.")
}
}
@@ -102,13 +113,24 @@ func (b *Bxmpp) Send(msg config.Message) (string, error) {
}
}
if b.GetString("WebhookURL") != "" {
b.Log.Debugf("Sending message using Webhook")
err := b.postSlackCompatibleWebhook(msg)
if err != nil {
b.Log.Errorf("Failed to send message using webhook: %s", err)
return "", err
}
return "", nil
}
// Post normal message.
var msgReplaceID string
msgID := xid.New().String()
if msg.ID != "" {
msgID = msg.ID
msgReplaceID = msg.ID
}
// Post normal message.
b.Log.Debugf("=> Sending message %#v", msg)
if _, err := b.xc.Send(xmpp.Chat{
Type: "groupchat",
@@ -122,6 +144,30 @@ func (b *Bxmpp) Send(msg config.Message) (string, error) {
return msgID, nil
}
func (b *Bxmpp) postSlackCompatibleWebhook(msg config.Message) error {
type XMPPWebhook struct {
Username string `json:"username"`
Text string `json:"text"`
}
webhookBody, err := json.Marshal(XMPPWebhook{
Username: msg.Username,
Text: msg.Text,
})
if err != nil {
b.Log.Errorf("Failed to marshal webhook: %s", err)
return err
}
resp, err := http.Post(b.GetString("WebhookURL")+"/"+url.QueryEscape(msg.Channel), "application/json", bytes.NewReader(webhookBody))
if err != nil {
b.Log.Errorf("Failed to POST webhook: %s", err)
return err
}
resp.Body.Close()
return nil
}
func (b *Bxmpp) createXMPP() error {
if !strings.Contains(b.GetString("Jid"), "@") {
return fmt.Errorf("the Jid %s doesn't contain an @", b.GetString("Jid"))
@@ -378,6 +424,11 @@ func (b *Bxmpp) skipMessage(message xmpp.Chat) bool {
return true
}
// Ignore messages posted by our webhook
if b.GetString("WebhookURL") != "" && strings.Contains(message.ID, "webhookbot") {
return true
}
// skip delayed messages
return !message.Stamp.IsZero() && time.Since(message.Stamp).Minutes() > 5
}

File diff suppressed because it is too large Load Diff

11
gateway/bridgemap/bvk.go Normal file
View File

@@ -0,0 +1,11 @@
// +build !novk
package bridgemap
import (
bvk "github.com/42wim/matterbridge/bridge/vk"
)
func init() {
FullMap["vk"] = bvk.New
}

View File

@@ -14,7 +14,7 @@ import (
"github.com/d5/tengo/v2"
"github.com/d5/tengo/v2/stdlib"
lru "github.com/hashicorp/golang-lru"
"github.com/matterbridge/emoji"
"github.com/kyokomi/emoji/v2"
"github.com/sirupsen/logrus"
)
@@ -127,7 +127,7 @@ func (gw *Gateway) AddConfig(cfg *config.Gateway) error {
gw.logger.Errorf("mapChannels() failed: %s", err)
}
for _, br := range append(gw.MyConfig.In, append(gw.MyConfig.InOut, gw.MyConfig.Out...)...) {
br := br //scopelint
br := br // scopelint
err := gw.AddBridge(&br)
if err != nil {
return err
@@ -337,20 +337,21 @@ func (gw *Gateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) stri
}
i++
}
nick = strings.Replace(nick, "{NOPINGNICK}", msg.Username[:i]+""+msg.Username[i:], -1)
nick = strings.ReplaceAll(nick, "{NOPINGNICK}", msg.Username[:i]+"\u200b"+msg.Username[i:])
}
nick = strings.Replace(nick, "{BRIDGE}", br.Name, -1)
nick = strings.Replace(nick, "{PROTOCOL}", br.Protocol, -1)
nick = strings.Replace(nick, "{GATEWAY}", gw.Name, -1)
nick = strings.Replace(nick, "{LABEL}", br.GetString("Label"), -1)
nick = strings.Replace(nick, "{NICK}", msg.Username, -1)
nick = strings.Replace(nick, "{CHANNEL}", msg.Channel, -1)
nick = strings.ReplaceAll(nick, "{BRIDGE}", br.Name)
nick = strings.ReplaceAll(nick, "{PROTOCOL}", br.Protocol)
nick = strings.ReplaceAll(nick, "{GATEWAY}", gw.Name)
nick = strings.ReplaceAll(nick, "{LABEL}", br.GetString("Label"))
nick = strings.ReplaceAll(nick, "{NICK}", msg.Username)
nick = strings.ReplaceAll(nick, "{USERID}", msg.UserID)
nick = strings.ReplaceAll(nick, "{CHANNEL}", msg.Channel)
tengoNick, err := gw.modifyUsernameTengo(msg, br)
if err != nil {
gw.logger.Errorf("modifyUsernameTengo error: %s", err)
}
nick = strings.Replace(nick, "{TENGO}", tengoNick, -1) //nolint:gocritic
nick = strings.ReplaceAll(nick, "{TENGO}", tengoNick)
return nick
}
@@ -385,6 +386,7 @@ func (gw *Gateway) modifyMessage(msg *config.Message) {
}
// replace :emoji: to unicode
emoji.ReplacePadding = ""
msg.Text = emoji.Sprint(msg.Text)
br := gw.Bridges[msg.Account]
@@ -458,9 +460,9 @@ func (gw *Gateway) SendMessage(
}
// if the parentID is still empty and we have a parentID set in the original message
// this means that we didn't find it in the cache so set it "msg-parent-not-found"
// this means that we didn't find it in the cache so set it to a "msg-parent-not-found" constant
if msg.ParentID == "" && rmsg.ParentID != "" {
msg.ParentID = "msg-parent-not-found"
msg.ParentID = config.ParentIDNotFound
}
drop, err := gw.modifyOutMessageTengo(rmsg, &msg, dest)
@@ -495,7 +497,7 @@ func (gw *Gateway) SendMessage(
if mID != "" {
gw.logger.Debugf("mID %s: %s", dest.Account, mID)
return mID, nil
//brMsgIDs = append(brMsgIDs, &BrMsgID{dest, dest.Protocol + " " + mID, channel.ID})
// brMsgIDs = append(brMsgIDs, &BrMsgID{dest, dest.Protocol + " " + mID, channel.ID})
}
return "", nil
}
@@ -549,6 +551,7 @@ func modifyInMessageTengo(filename string, msg *config.Message) error {
s.SetImports(stdlib.GetModuleMap(stdlib.AllModuleNames()...))
_ = s.Add("msgText", msg.Text)
_ = s.Add("msgUsername", msg.Username)
_ = s.Add("msgUserID", msg.UserID)
_ = s.Add("msgAccount", msg.Account)
_ = s.Add("msgChannel", msg.Channel)
c, err := s.Compile()
@@ -577,6 +580,7 @@ func (gw *Gateway) modifyUsernameTengo(msg *config.Message, br *bridge.Bridge) (
_ = s.Add("result", "")
_ = s.Add("msgText", msg.Text)
_ = s.Add("msgUsername", msg.Username)
_ = s.Add("msgUserID", msg.UserID)
_ = s.Add("nick", msg.Username)
_ = s.Add("msgAccount", msg.Account)
_ = s.Add("msgChannel", msg.Channel)
@@ -631,6 +635,7 @@ func (gw *Gateway) modifyOutMessageTengo(origmsg *config.Message, msg *config.Me
_ = s.Add("outEvent", msg.Event)
_ = s.Add("msgText", msg.Text)
_ = s.Add("msgUsername", msg.Username)
_ = s.Add("msgUserID", msg.UserID)
_ = s.Add("msgDrop", drop)
c, err := s.Compile()
if err != nil {

View File

@@ -160,7 +160,7 @@ func (r *Router) handleReceive() {
// For some bridges we always add/update the message ID.
// This is necessary as msgIDs will change if a bridge returns
// a different ID in response to edits.
if !exists || msg.Protocol == "discord" {
if !exists {
gw.Messages.Add(msg.Protocol+" "+msg.ID, msgIDs)
}
}

52
go.mod
View File

@@ -3,54 +3,56 @@ module github.com/42wim/matterbridge
require (
github.com/42wim/go-gitter v0.0.0-20170828205020-017310c2d557
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
github.com/Jeffail/gabs v1.1.1 // indirect
github.com/Jeffail/gabs v1.4.0 // indirect
github.com/Philipp15b/go-steam v1.0.1-0.20200727090957-6ae9b3c0a560
github.com/Rhymen/go-whatsapp v0.1.2-0.20201122130733-6e5488ac98df
github.com/d5/tengo/v2 v2.6.2
github.com/Rhymen/go-whatsapp v0.1.2-0.20210615184944-2b8a3e9b8aa2
github.com/SevereCloud/vksdk/v2 v2.10.0
github.com/d5/tengo/v2 v2.7.0
github.com/davecgh/go-spew v1.1.1
github.com/fsnotify/fsnotify v1.4.9
github.com/go-telegram-bot-api/telegram-bot-api v1.0.1-0.20200524105306-7434b0456e81
github.com/gomarkdown/markdown v0.0.0-20201113031856-722100d81a8e
github.com/google/gops v0.3.13
github.com/gomarkdown/markdown v0.0.0-20210514010506-3b9f47219fe7
github.com/google/gops v0.3.18
github.com/gopackage/ddp v0.0.0-20170117053602-652027933df4 // indirect
github.com/gorilla/schema v1.2.0
github.com/gorilla/websocket v1.4.2
github.com/hashicorp/golang-lru v0.5.4
github.com/jpillora/backoff v1.0.0
github.com/keybase/go-keybase-chat-bot v0.0.0-20200505163032-5cacf52379da
github.com/labstack/echo/v4 v4.1.17
github.com/lrstanley/girc v0.0.0-20190801035559-4fc93959e1a7
github.com/matrix-org/gomatrix v0.0.0-20200827122206-7dd5e2a05bcd
github.com/matterbridge/Rocket.Chat.Go.SDK v0.0.0-20200411204219-d5c18ce75048
github.com/matterbridge/discordgo v0.22.1
github.com/matterbridge/emoji v2.1.1-0.20191117213217-af507f6b02db+incompatible
github.com/kyokomi/emoji/v2 v2.2.8
github.com/labstack/echo/v4 v4.3.0
github.com/lrstanley/girc v0.0.0-20210611213246-771323f1624b
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16
github.com/matterbridge/Rocket.Chat.Go.SDK v0.0.0-20210403163225-761e8622445d
github.com/matterbridge/discordgo v0.21.2-0.20210201201054-fb39a175b4f7
github.com/matterbridge/go-xmpp v0.0.0-20200418225040-c8a3a57b4050
github.com/matterbridge/gozulipbot v0.0.0-20200820220548-be5824faa913
github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba
github.com/mattermost/mattermost-server/v5 v5.29.0
github.com/mattn/godown v0.0.0-20201027140031-2c7783b24de7
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mattermost/mattermost-server/v5 v5.30.1
github.com/mattn/godown v0.0.1
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/missdeer/golib v1.0.4
github.com/mreiferson/go-httpclient v0.0.0-20160630210159-31f0106b4474 // indirect
github.com/mreiferson/go-httpclient v0.0.0-20201222173833-5e475fde3a4d // indirect
github.com/mrexodia/wray v0.0.0-20160318003008-78a2c1f284ff // indirect
github.com/nelsonken/gomf v0.0.0-20180504123937-a9dd2f9deae9
github.com/paulrosania/go-charset v0.0.0-20190326053356-55c9d7a5834c
github.com/rs/xid v1.2.1
github.com/russross/blackfriday v1.5.2
github.com/rs/xid v1.3.0
github.com/russross/blackfriday v1.6.0
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca
github.com/shazow/ssh-chat v1.10.1
github.com/sirupsen/logrus v1.7.0
github.com/slack-go/slack v0.7.2
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1
github.com/sirupsen/logrus v1.8.1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/slack-go/slack v0.9.1
github.com/spf13/viper v1.8.0
github.com/stretchr/testify v1.7.0
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50
github.com/writeas/go-strip-markdown v2.0.1+incompatible
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
github.com/yaegashi/msgraph.go v0.1.4
github.com/zfjagann/golang-ring v0.0.0-20190304061218-d34796e0a6c2
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58
gomod.garykim.dev/nc-talk v0.1.5
github.com/zfjagann/golang-ring v0.0.0-20210116075443-7c86fdb43134
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9
golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1
gomod.garykim.dev/nc-talk v0.2.2
gopkg.in/olahol/melody.v1 v1.0.0-20170518105555-d52139073376
layeh.com/gumble v0.0.0-20200818122324-146f9205029b
)

498
go.sum

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

View File

@@ -16,7 +16,7 @@ import (
)
var (
version = "1.20.1-dev"
version = "1.22.3"
githash string
flagConfig = flag.String("conf", "matterbridge.toml", "config file")

View File

@@ -9,12 +9,12 @@
[irc]
#You can configure multiple servers "[irc.name]" or "[irc.name2]"
#In this example we use [irc.freenode]
#In this example we use [irc.libera]
#REQUIRED
[irc.freenode]
[irc.libera]
#irc server to connect to.
#REQUIRED
Server="irc.freenode.net:6667"
Server="irc.libera.chat:6667"
#Password for irc server (if necessary)
#OPTIONAL (default "")
@@ -24,7 +24,7 @@ Password=""
#OPTIONAL (default false)
UseTLS=false
#Enable SASL (PLAIN) authentication. (freenode requires this from eg AWS hosts)
#Enable SASL (PLAIN) authentication. (libera requires this from eg AWS hosts)
#It uses NickServNick and NickServPassword as login and password
#OPTIONAL (default false)
UseSASL=false
@@ -55,7 +55,7 @@ Charset=""
#REQUIRED
Nick="matterbot"
#If you registered your bot with a service like Nickserv on freenode.
#If you registered your bot with a service like Nickserv on libera.
#Also being used when UseSASL=true
#
#Note: if you want do to quakenet auth, set NickServNick="Q@CServe.quakenet.org"
@@ -76,20 +76,24 @@ MessageDelay=1300
#Maximum amount of messages to hold in queue. If queue is full
#messages will be dropped.
#<message clipped> will be add to the message that fills the queue.
#<clipped message> will be add to the message that fills the queue.
#OPTIONAL (default 30)
MessageQueue=30
#Maximum length of message sent to irc server. If it exceeds
#<message clipped> will be add to the message.
#<clipped message> will be add to the message.
#OPTIONAL (default 400)
MessageLength=400
#Split messages on MessageLength instead of showing the <message clipped>
#Split messages on MessageLength instead of showing the <clipped message>
#WARNING: this could lead to flooding
#OPTIONAL (default false)
MessageSplit=false
#Message to show when a message is too big
#Default "<clipped message>"
MessageClipped="<clipped message>"
#Delay in seconds to rejoin a channel when kicked
#OPTIONAL (default 0)
RejoinDelay=0
@@ -193,6 +197,19 @@ ShowTopicChange=false
#OPTIONAL (default 0)
JoinDelay=0
#Use the optional RELAYMSG extension for username spoofing on IRC.
#This requires an IRCd that supports the draft/relaymsg specification: currently this includes
#Oragono 2.4.0+ and InspIRCd 3 with the m_relaymsg contrib module.
#See https://github.com/42wim/matterbridge/issues/667#issuecomment-634214165 for more details.
#Spoofed nicks will use the configured RemoteNickFormat, replacing reserved IRC characters
#(!+%@&#$:'"?*,.) with a hyphen (-).
#On most configurations, the RemoteNickFormat must include a separator character such as "/".
#You should make sure that the settings here match your IRCd.
#This option overrides ColorNicks.
#OPTIONAL (default false)
UseRelayMsg=false
#RemoteNickFormat="{NICK}/{PROTOCOL}"
###################################################################
#XMPP section
###################################################################
@@ -297,6 +314,11 @@ StripNick=false
#OPTIONAL (default false)
ShowTopicChange=false
#Enable sending messages using a webhook instead of regular MUC messages.
#Only works with a prosody server using mod_slack_webhook. Does not support editing.
#OPTIONAL (default "")
WebhookURL="https://yourdomain/prosody/msg/someid"
###################################################################
#mattermost section
###################################################################
@@ -808,6 +830,10 @@ PreserveThreading=false
#OPTIONAL (default false)
ShowUserTyping=false
#Message to show when a message is too big
#Default "<clipped message>"
MessageClipped="<clipped message>"
###################################################################
#discord section
###################################################################
@@ -830,6 +856,14 @@ Server="yourservername"
## All settings below can be reloaded by editing the file.
## They are also all optional.
# AllowMention controls which mentions are allowed. If not specified, all mentions are allowed.
# Note that even when a mention is not allowed, it will still be displayed nicely and be clickable. It just prevents the ping/notification.
#
# "everyone" allows @everyone and @here mentions
# "roles" allows @role mentions
# "users" allows @user mentions
AllowMention=["everyone", "roles", "users"]
# ShowEmbeds shows the title, description and URL of embedded messages (sent by other bots)
ShowEmbeds=false
@@ -846,10 +880,11 @@ UseUserName=false
# UseDiscriminator appends the `#xxxx` discriminator when used with UseUserName
UseDiscriminator=false
# WebhookURL sends messages in the style of puppets.
# This only works if you have one discord channel, if you have multiple discord channels you'll have to specify it in the gateway config
# Example: "https://discordapp.com/api/webhooks/1234/abcd_xyzw"
WebhookURL=""
# AutoWebhooks automatically configures message sending in the style of puppets.
# This is an easier alternative to manually configuring "WebhookURL" for each gateway,
# as turning this on will automatically load or create webhooks for each channel.
# This feature requires the "Manage Webhooks" permission (either globally or as per-channel).
AutoWebhooks=false
# EditDisable disables sending of edits to other bridges
EditDisable=false
@@ -934,6 +969,10 @@ ShowTopicChange=false
# Supported from the following bridges: slack
SyncTopic=false
#Message to show when a message is too big
#Default "<clipped message>"
MessageClipped="<clipped message>"
###################################################################
#telegram section
###################################################################
@@ -992,6 +1031,13 @@ QuoteFormat="{MESSAGE} (re @{QUOTENICK}: {QUOTEMESSAGE})"
#OPTIONAL (default false)
MediaConvertWebPToPNG=false
#Convert Tgs (Telegram animated sticker) images to PNG before upload.
#This is useful when your bridge also contains platforms that do not support animated WebP files, like Discord.
#This requires the external dependency `lottie`, which can be installed like this:
#`pip install lottie cairosvg`
#https://github.com/42wim/matterbridge/issues/874
#MediaConvertTgs="png"
#Disable sending of edits to other bridges
#OPTIONAL (default false)
EditDisable=false
@@ -1211,12 +1257,16 @@ ShowTopicChange=false
#REQUIRED
Server="https://matrix.org"
#login/pass of your bot.
#Authentication for your bot.
#You can use either login/password OR mxid/token. The latter will be preferred if found.
#Use a dedicated user for this and not your own!
#Messages sent from this user will not be relayed to avoid loops.
#REQUIRED
Login="yourlogin"
Password="yourpass"
#OR
MxID="@yourlogin:domain.tld"
Token="tokenforthebotuser"
#Whether to send the homeserver suffix. eg ":matrix.org" in @username:matrix.org
#to other bridges, or only send "username".(true only sends username)
@@ -1397,9 +1447,7 @@ StripNick=false
ShowTopicChange=false
###################################################################
#
# NCTalk (Nextcloud Talk)
#
###################################################################
[nctalk.bridge]
@@ -1422,9 +1470,7 @@ Password = "talkuserpass"
GuestSuffix = " (Guest)"
###################################################################
#
# Mumble
#
###################################################################
[mumble.bridge]
@@ -1435,7 +1481,7 @@ Server = "mumble.yourdomain.me:64738"
# Nickname to log in as
Nick = "matterbridge"
# Some servers require a password
# Some servers require a password
# OPTIONAL (default empty)
Password = "serverpasswordhere"
@@ -1467,10 +1513,25 @@ TLSCACertificate=mumble-ca.crt
# OPTIONAL (default false)
SkipTLSVerify=false
#Message to show when a message is too big
#Default "<clipped message>"
MessageClipped="<clipped message>"
###################################################################
#VK
###################################################################
#
[vk.myvk]
#Group access token
#See https://vk.com/dev/bots_docs
Token="Yourtokenhere"
#Group ID
#For example in URL https://vk.com/public168963511 group ID is 168963511
GroupID=123456789
###################################################################
# WhatsApp
#
###################################################################
[whatsapp.bridge]
@@ -1497,9 +1558,7 @@ Label="Organization"
###################################################################
#
# zulip
#
###################################################################
[zulip]
@@ -1632,7 +1691,8 @@ RemoteNickFormat="{NICK}"
## Settings below can be reloaded by editing the file
#RemoteNickFormat defines how remote users appear on this bridge
#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username.
#The string "{NICK}" (case sensitive) will be replaced by the actual nick.
#The string "{USERID}" (case sensitive) will be replaced by the user ID.
#The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge
#The string "{LABEL}" (case sensitive) will be replaced by label= field of the sending bridge
#The string "{PROTOCOL}" (case sensitive) will be replaced by the protocol used by the bridge
@@ -1707,7 +1767,7 @@ LogFile="/var/log/matterbridge.log"
#This script will receive every incoming message and can be used to modify the Username and the Text of that message.
#The script will have the following global variables:
#to modify: msgUsername and msgText
#to read: msgChannel and msgAccount
#to read: msgUserID, msgChannel, msgAccount
#
#The script is reloaded on every message, so you can modify the script on the fly.
#
@@ -1731,6 +1791,7 @@ InMessage="example.tengo"
#read-only:
#inAccount, inProtocol, inChannel, inGateway, inEvent
#outAccount, outProtocol, outChannel, outGateway, outEvent
#msgUserID
#
#read-write:
#msgText, msgUsername, msgDrop
@@ -1748,7 +1809,7 @@ OutMessage="example.tengo"
#RemoteNickFormat allows you to specify the location of a tengo (https://github.com/d5/tengo/) script.
#The script will have the following global variables:
#to modify: result
#to read: channel, bridge, gateway, protocol, nick
#to read: channel, bridge, gateway, protocol, nick, msgUserID
#
#The result will be set in {TENGO} in the RemoteNickFormat key of every bridge where {TENGO} is specified
#
@@ -1786,7 +1847,7 @@ enable=true
# account specified above
# REQUIRED
account="irc.freenode"
account="irc.libera"
# The channel key in each gateway is mapped to a similar group chat ID on the chat platform
# To find the group chat ID for different platforms, refer to the table below
@@ -1814,7 +1875,7 @@ enable=true
# rocketchat | channel | #channel | # is required for private channels too
# -------------------------------------------------------------------------------------------------------------------------------------
# slack | channel name | general | Do not include the # symbol
# | channel id | ID:C123456 | The underlying ID of a channel. This doesn't work with
# | channel id | ID:C123456 | The underlying ID of a channel. This doesn't work with webhooks.
# -------------------------------------------------------------------------------------------------------------------------------------
# steam | chatid | example needed | The number in the URL when you click "enter chat room" in the browser
# -------------------------------------------------------------------------------------------------------------------------------------
@@ -1822,6 +1883,8 @@ enable=true
# -------------------------------------------------------------------------------------------------------------------------------------
# telegram | chatid | -123456789 | A large negative number. see https://www.linkedin.com/pulse/telegram-bots-beginners-marco-frau
# -------------------------------------------------------------------------------------------------------------------------------------
# vk | peerid | 2000000002 | A number that starts form 2000000000. Use --debug and send any message in chat to get PeerID in the logs
# -------------------------------------------------------------------------------------------------------------------------------------
# whatsapp | group JID | 48111222333-123455678999@g.us | A unique group JID. If you specify an empty string, bridge will list all the possibilities
# | "Group Name" | "Family Chat" | if you specify a group name, the bridge will find hint the JID to specify. Names can change over time and are not stable.
# -------------------------------------------------------------------------------------------------------------------------------------
@@ -1842,7 +1905,7 @@ enable=true
#[[gateway.out]] specifies the account and channels we will sent messages to.
[[gateway.out]]
account="irc.freenode"
account="irc.libera"
channel="#testing"
#OPTIONAL - only used for IRC and XMPP protocols at the moment
@@ -1861,13 +1924,16 @@ enable=true
#OPTIONAL - your irc / xmpp channel key
key="yourkey"
# Discord specific gateway options
[[gateway.inout]]
account="discord.game"
channel="mygreatgame"
#OPTIONAL - webhookurl only works for discord (it needs a different URL for each cahnnel)
[gateway.inout.options]
webhookurl="https://discordapp.com/api/webhooks/123456789123456789/C9WPqExYWONPDZabcdef-def1434FGFjstasJX9pYht73y"
# WebhookURL sends messages in the style of "puppets". You must configure a webhook URL for each channel you want to bridge.
# If you have more than one channel and don't wnat to configure each channel manually, see the "AutoWebhooks" option in the gateway config.
# Example: "https://discord.com/api/webhooks/1234/abcd_xyzw"
WebhookURL=""
[[gateway.inout]]
account="zulip.streamchat"

View File

@@ -1,21 +1,18 @@
FROM alpine AS builder
COPY . /go/src/github.com/42wim/matterbridge
COPY . /go/src/matterbridge
RUN apk add \
go \
git \
gcc \
musl-dev \
&& cd /go/src/github.com/42wim/matterbridge \
&& export GOPATH=/go \
&& go get \
&& go build -x -ldflags "-X main.githash=$(git log --pretty=format:'%h' -n 1)" -o /bin/matterbridge
&& cd /go/src/matterbridge \
&& go build -mod vendor -ldflags "-X main.githash=$(git log --pretty=format:'%h' -n 1)" -o /bin/matterbridge
FROM alpine
RUN apk --no-cache add \
ca-certificates \
cairo \
libjpeg-turbo \
libwebp-dev \
mailcap \
py3-webencodings \
python3 \

View File

@@ -7,21 +7,17 @@ It does nothing spectacular except for being fabulous.
https://godoc.org/github.com/Jeffail/gabs
## How to install:
## Install
``` bash
go get github.com/Jeffail/gabs
```
## How to use
## Use
### Parsing and searching JSON
``` go
...
import "github.com/Jeffail/gabs"
jsonParsed, err := gabs.ParseJSON([]byte(`{
"outter":{
"inner":{
@@ -29,7 +25,10 @@ jsonParsed, err := gabs.ParseJSON([]byte(`{
"value2":22
},
"alsoInner":{
"value1":20
"value1":20,
"array1":[
30, 40
]
}
}
}`))
@@ -43,26 +42,26 @@ value, ok = jsonParsed.Path("outter.inner.value1").Data().(float64)
value, ok = jsonParsed.Search("outter", "inner", "value1").Data().(float64)
// value == 10.0, ok == true
gObj, err := jsonParsed.JSONPointer("/outter/alsoInner/array1/1")
if err != nil {
panic(err)
}
value, ok = gObj.Data().(float64)
// value == 40.0, ok == true
value, ok = jsonParsed.Path("does.not.exist").Data().(float64)
// value == 0.0, ok == false
exists := jsonParsed.Exists("outter", "inner", "value1")
// exists == true
exists := jsonParsed.Exists("does", "not", "exist")
// exists == false
exists := jsonParsed.ExistsP("does.not.exist")
// exists == false
...
```
### Iterating objects
``` go
...
jsonParsed, _ := gabs.ParseJSON([]byte(`{"object":{ "first": 1, "second": 2, "third": 3 }}`))
// S is shorthand for Search
@@ -70,24 +69,25 @@ children, _ := jsonParsed.S("object").ChildrenMap()
for key, child := range children {
fmt.Printf("key: %v, value: %v\n", key, child.Data().(string))
}
...
```
### Iterating arrays
``` go
...
jsonParsed, _ := gabs.ParseJSON([]byte(`{"array":[ "first", "second", "third" ]}`))
jsonParsed, err := gabs.ParseJSON([]byte(`{"array":[ "first", "second", "third" ]}`))
if err != nil {
panic(err)
}
// S is shorthand for Search
children, _ := jsonParsed.S("array").Children()
children, err := jsonParsed.S("array").Children()
if err != nil {
panic(err)
}
for _, child := range children {
fmt.Println(child.Data().(string))
}
...
```
Will print:
@@ -108,12 +108,11 @@ objects within the array, this returns a JSON array containing the results for
each element.
``` go
...
jsonParsed, _ := gabs.ParseJSON([]byte(`{"array":[ {"value":1}, {"value":2}, {"value":3} ]}`))
jsonParsed, err := gabs.ParseJSON([]byte(`{"array":[ {"value":1}, {"value":2}, {"value":3} ]}`))
if err != nil {
panic(err)
}
fmt.Println(jsonParsed.Path("array.value").String())
...
```
Will print:
@@ -125,8 +124,6 @@ Will print:
### Generating JSON
``` go
...
jsonObj := gabs.New()
// or gabs.Consume(jsonObject) to work on an existing map[string]interface{}
@@ -135,8 +132,6 @@ jsonObj.SetP(20, "outter.inner.value2")
jsonObj.Set(30, "outter", "inner2", "value3")
fmt.Println(jsonObj.String())
...
```
Will print:
@@ -148,11 +143,7 @@ Will print:
To pretty-print:
``` go
...
fmt.Println(jsonObj.StringIndent("", " "))
...
```
Will print:
@@ -174,8 +165,6 @@ Will print:
### Generating Arrays
``` go
...
jsonObj := gabs.New()
jsonObj.Array("foo", "array")
@@ -186,8 +175,6 @@ jsonObj.ArrayAppend(20, "foo", "array")
jsonObj.ArrayAppend(30, "foo", "array")
fmt.Println(jsonObj.String())
...
```
Will print:
@@ -199,8 +186,6 @@ Will print:
Working with arrays by index:
``` go
...
jsonObj := gabs.New()
// Create an array with the length of 3
@@ -217,8 +202,6 @@ jsonObj.S("foo").Index(2).SetIndex(2, 1)
jsonObj.S("foo").Index(2).SetIndex(3, 2)
fmt.Println(jsonObj.String())
...
```
Will print:
@@ -232,8 +215,6 @@ Will print:
This is the easiest part:
``` go
...
jsonParsedObj, _ := gabs.ParseJSON([]byte(`{
"outter":{
"values":{
@@ -246,15 +227,11 @@ jsonParsedObj, _ := gabs.ParseJSON([]byte(`{
jsonOutput := jsonParsedObj.String()
// Becomes `{"outter":{"values":{"first":10,"second":11}},"outter2":"hello world"}`
...
```
And to serialize a specific segment is as simple as:
``` go
...
jsonParsedObj := gabs.ParseJSON([]byte(`{
"outter":{
"values":{
@@ -267,8 +244,6 @@ jsonParsedObj := gabs.ParseJSON([]byte(`{
jsonOutput := jsonParsedObj.Search("outter").String()
// Becomes `{"values":{"first":10,"second":11}}`
...
```
### Merge two containers

View File

@@ -20,58 +20,85 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Package gabs implements a simplified wrapper around creating and parsing JSON.
// Package gabs implements a simplified wrapper around creating and parsing
// unknown or dynamic JSON.
package gabs
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"strconv"
"strings"
)
//--------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
var (
// ErrOutOfBounds - Index out of bounds.
// ErrOutOfBounds indicates an index was out of bounds.
ErrOutOfBounds = errors.New("out of bounds")
// ErrNotObjOrArray - The target is not an object or array type.
// ErrNotObjOrArray is returned when a target is not an object or array type
// but needs to be for the intended operation.
ErrNotObjOrArray = errors.New("not an object or array")
// ErrNotObj - The target is not an object type.
// ErrNotObj is returned when a target is not an object but needs to be for
// the intended operation.
ErrNotObj = errors.New("not an object")
// ErrNotArray - The target is not an array type.
// ErrNotArray is returned when a target is not an array but needs to be for
// the intended operation.
ErrNotArray = errors.New("not an array")
// ErrPathCollision - Creating a path failed because an element collided with an existing value.
// ErrPathCollision is returned when creating a path failed because an
// element collided with an existing value.
ErrPathCollision = errors.New("encountered value collision whilst building path")
// ErrInvalidInputObj - The input value was not a map[string]interface{}.
// ErrInvalidInputObj is returned when the input value was not a
// map[string]interface{}.
ErrInvalidInputObj = errors.New("invalid input object")
// ErrInvalidInputText - The input data could not be parsed.
// ErrInvalidInputText is returned when the input data could not be parsed.
ErrInvalidInputText = errors.New("input text could not be parsed")
// ErrInvalidPath - The filepath was not valid.
// ErrInvalidPath is returned when the filepath was not valid.
ErrInvalidPath = errors.New("invalid file path")
// ErrInvalidBuffer - The input buffer contained an invalid JSON string
// ErrInvalidBuffer is returned when the input buffer contained an invalid
// JSON string.
ErrInvalidBuffer = errors.New("input buffer contained invalid JSON")
)
//--------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Container - an internal structure that holds a reference to the core interface map of the parsed
// json. Use this container to move context.
func resolveJSONPointerHierarchy(path string) ([]string, error) {
if len(path) < 1 {
return nil, errors.New("failed to resolve JSON pointer: path must not be empty")
}
if path[0] != '/' {
return nil, errors.New("failed to resolve JSON pointer: path must begin with '/'")
}
hierarchy := strings.Split(path, "/")[1:]
for i, v := range hierarchy {
v = strings.Replace(v, "~1", "/", -1)
v = strings.Replace(v, "~0", "~", -1)
hierarchy[i] = v
}
return hierarchy, nil
}
//------------------------------------------------------------------------------
// Container references a specific element within a JSON structure.
type Container struct {
object interface{}
}
// Data - Return the contained data as an interface{}.
// Data returns the underlying interface{} of the target element in the JSON
// structure.
func (g *Container) Data() interface{} {
if g == nil {
return nil
@@ -79,17 +106,18 @@ func (g *Container) Data() interface{} {
return g.object
}
//--------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Path - Search for a value using dot notation.
// Path searches the JSON structure following a path in dot notation.
func (g *Container) Path(path string) *Container {
return g.Search(strings.Split(path, ".")...)
}
// Search - Attempt to find and return an object within the JSON structure by specifying the
// hierarchy of field names to locate the target. If the search encounters an array and has not
// reached the end target then it will iterate each object of the array for the target and return
// all of the results in a JSON array.
// Search attempts to find and return an object within the JSON structure by
// following a provided hierarchy of field names to locate the target. If the
// search encounters an array and has not reached the end target then it will
// iterate each object of the array for the target and return all of the results
// in a JSON array.
func (g *Container) Search(hierarchy ...string) *Container {
var object interface{}
@@ -120,22 +148,55 @@ func (g *Container) Search(hierarchy ...string) *Container {
return &Container{object}
}
// S - Shorthand method, does the same thing as Search.
// JSONPointer parses a JSON pointer path (https://tools.ietf.org/html/rfc6901)
// and either returns a *gabs.Container containing the result or an error if the
// referenced item could not be found.
func (g *Container) JSONPointer(path string) (*Container, error) {
hierarchy, err := resolveJSONPointerHierarchy(path)
if err != nil {
return nil, err
}
object := g.Data()
for target := 0; target < len(hierarchy); target++ {
pathSeg := hierarchy[target]
if mmap, ok := object.(map[string]interface{}); ok {
object, ok = mmap[pathSeg]
if !ok {
return nil, fmt.Errorf("failed to resolve JSON pointer: index '%v' value '%v' was not found", target, pathSeg)
}
} else if marray, ok := object.([]interface{}); ok {
index, err := strconv.Atoi(pathSeg)
if err != nil {
return nil, fmt.Errorf("failed to resolve JSON pointer: could not parse index '%v' value '%v' into array index: %v", target, pathSeg, err)
}
if len(marray) <= index {
return nil, fmt.Errorf("failed to resolve JSON pointer: index '%v' value '%v' exceeded target array size of '%v'", target, pathSeg, len(marray))
}
object = marray[index]
} else {
return &Container{nil}, fmt.Errorf("failed to resolve JSON pointer: index '%v' field '%v' was not found", target, pathSeg)
}
}
return &Container{object}, nil
}
// S is a shorthand alias for Search.
func (g *Container) S(hierarchy ...string) *Container {
return g.Search(hierarchy...)
}
// Exists - Checks whether a path exists.
// Exists checks whether a path exists.
func (g *Container) Exists(hierarchy ...string) bool {
return g.Search(hierarchy...) != nil
}
// ExistsP - Checks whether a dot notation path exists.
// ExistsP checks whether a dot notation path exists.
func (g *Container) ExistsP(path string) bool {
return g.Exists(strings.Split(path, ".")...)
}
// Index - Attempt to find and return an object within a JSON array by index.
// Index attempts to find and return an element within a JSON array by an index.
func (g *Container) Index(index int) *Container {
if array, ok := g.Data().([]interface{}); ok {
if index >= len(array) {
@@ -146,9 +207,9 @@ func (g *Container) Index(index int) *Container {
return &Container{nil}
}
// Children - Return a slice of all the children of the array. This also works for objects, however,
// the children returned for an object will NOT be in order and you lose the names of the returned
// objects this way.
// Children returns a slice of all children of an array element. This also works
// for objects, however, the children returned for an object will be in a random
// order and you lose the names of the returned objects this way.
func (g *Container) Children() ([]*Container, error) {
if array, ok := g.Data().([]interface{}); ok {
children := make([]*Container, len(array))
@@ -167,7 +228,7 @@ func (g *Container) Children() ([]*Container, error) {
return nil, ErrNotObjOrArray
}
// ChildrenMap - Return a map of all the children of an object.
// ChildrenMap returns a map of all the children of an object element.
func (g *Container) ChildrenMap() (map[string]*Container, error) {
if mmap, ok := g.Data().(map[string]interface{}); ok {
children := map[string]*Container{}
@@ -179,11 +240,11 @@ func (g *Container) ChildrenMap() (map[string]*Container, error) {
return nil, ErrNotObj
}
//--------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Set - Set the value of a field at a JSON path, any parts of the path that do not exist will be
// constructed, and if a collision occurs with a non object type whilst iterating the path an error
// is returned.
// Set the value of a field at a JSON path, any parts of the path that do not
// exist will be constructed, and if a collision occurs with a non object type
// whilst iterating the path an error is returned.
func (g *Container) Set(value interface{}, path ...string) (*Container, error) {
if len(path) == 0 {
g.object = value
@@ -209,12 +270,14 @@ func (g *Container) Set(value interface{}, path ...string) (*Container, error) {
return &Container{object}, nil
}
// SetP - Does the same as Set, but using a dot notation JSON path.
// SetP sets the value of a field at a JSON path using dot notation, any parts
// of the path that do not exist will be constructed, and if a collision occurs
// with a non object type whilst iterating the path an error is returned.
func (g *Container) SetP(value interface{}, path string) (*Container, error) {
return g.Set(value, strings.Split(path, ".")...)
}
// SetIndex - Set a value of an array element based on the index.
// SetIndex attempts to set a value of an array element based on an index.
func (g *Container) SetIndex(value interface{}, index int) (*Container, error) {
if array, ok := g.Data().([]interface{}); ok {
if index >= len(array) {
@@ -226,60 +289,112 @@ func (g *Container) SetIndex(value interface{}, index int) (*Container, error) {
return &Container{nil}, ErrNotArray
}
// Object - Create a new JSON object at a path. Returns an error if the path contains a collision
// with a non object type.
// SetJSONPointer parses a JSON pointer path
// (https://tools.ietf.org/html/rfc6901) and sets the leaf to a value. Returns
// an error if the pointer could not be resolved due to missing fields.
func (g *Container) SetJSONPointer(value interface{}, path string) error {
hierarchy, err := resolveJSONPointerHierarchy(path)
if err != nil {
return err
}
if len(hierarchy) == 0 {
g.object = value
return nil
}
object := g.object
for target := 0; target < len(hierarchy); target++ {
pathSeg := hierarchy[target]
if mmap, ok := object.(map[string]interface{}); ok {
if target == len(hierarchy)-1 {
object = value
mmap[pathSeg] = object
} else if object = mmap[pathSeg]; object == nil {
return fmt.Errorf("failed to resolve JSON pointer: index '%v' value '%v' was not found", target, pathSeg)
}
} else if marray, ok := object.([]interface{}); ok {
index, err := strconv.Atoi(pathSeg)
if err != nil {
return fmt.Errorf("failed to resolve JSON pointer: could not parse index '%v' value '%v' into array index: %v", target, pathSeg, err)
}
if len(marray) <= index {
return fmt.Errorf("failed to resolve JSON pointer: index '%v' value '%v' exceeded target array size of '%v'", target, pathSeg, len(marray))
}
if target == len(hierarchy)-1 {
object = value
marray[index] = object
} else if object = marray[index]; object == nil {
return fmt.Errorf("failed to resolve JSON pointer: index '%v' value '%v' was not found", target, pathSeg)
}
} else {
return fmt.Errorf("failed to resolve JSON pointer: index '%v' value '%v' was not found", target, pathSeg)
}
}
return nil
}
// Object creates a new JSON object at a target path. Returns an error if the
// path contains a collision with a non object type.
func (g *Container) Object(path ...string) (*Container, error) {
return g.Set(map[string]interface{}{}, path...)
}
// ObjectP - Does the same as Object, but using a dot notation JSON path.
// ObjectP creates a new JSON object at a target path using dot notation.
// Returns an error if the path contains a collision with a non object type.
func (g *Container) ObjectP(path string) (*Container, error) {
return g.Object(strings.Split(path, ".")...)
}
// ObjectI - Create a new JSON object at an array index. Returns an error if the object is not an
// array or the index is out of bounds.
// ObjectI creates a new JSON object at an array index. Returns an error if the
// object is not an array or the index is out of bounds.
func (g *Container) ObjectI(index int) (*Container, error) {
return g.SetIndex(map[string]interface{}{}, index)
}
// Array - Create a new JSON array at a path. Returns an error if the path contains a collision with
// a non object type.
// Array creates a new JSON array at a path. Returns an error if the path
// contains a collision with a non object type.
func (g *Container) Array(path ...string) (*Container, error) {
return g.Set([]interface{}{}, path...)
}
// ArrayP - Does the same as Array, but using a dot notation JSON path.
// ArrayP creates a new JSON array at a path using dot notation. Returns an
// error if the path contains a collision with a non object type.
func (g *Container) ArrayP(path string) (*Container, error) {
return g.Array(strings.Split(path, ".")...)
}
// ArrayI - Create a new JSON array at an array index. Returns an error if the object is not an
// array or the index is out of bounds.
// ArrayI creates a new JSON array within an array at an index. Returns an error
// if the element is not an array or the index is out of bounds.
func (g *Container) ArrayI(index int) (*Container, error) {
return g.SetIndex([]interface{}{}, index)
}
// ArrayOfSize - Create a new JSON array of a particular size at a path. Returns an error if the
// path contains a collision with a non object type.
// ArrayOfSize creates a new JSON array of a particular size at a path. Returns
// an error if the path contains a collision with a non object type.
func (g *Container) ArrayOfSize(size int, path ...string) (*Container, error) {
a := make([]interface{}, size)
return g.Set(a, path...)
}
// ArrayOfSizeP - Does the same as ArrayOfSize, but using a dot notation JSON path.
// ArrayOfSizeP creates a new JSON array of a particular size at a path using
// dot notation. Returns an error if the path contains a collision with a non
// object type.
func (g *Container) ArrayOfSizeP(size int, path string) (*Container, error) {
return g.ArrayOfSize(size, strings.Split(path, ".")...)
}
// ArrayOfSizeI - Create a new JSON array of a particular size at an array index. Returns an error
// if the object is not an array or the index is out of bounds.
// ArrayOfSizeI create a new JSON array of a particular size within an array at
// an index. Returns an error if the element is not an array or the index is out
// of bounds.
func (g *Container) ArrayOfSizeI(size, index int) (*Container, error) {
a := make([]interface{}, size)
return g.SetIndex(a, index)
}
// Delete - Delete an element at a JSON path, an error is returned if the element does not exist.
// Delete an element at a path, an error is returned if the element does not
// exist.
func (g *Container) Delete(path ...string) error {
var object interface{}
@@ -304,45 +419,40 @@ func (g *Container) Delete(path ...string) error {
return nil
}
// DeleteP - Does the same as Delete, but using a dot notation JSON path.
// DeleteP deletes an element at a path using dot notation, an error is returned
// if the element does not exist.
func (g *Container) DeleteP(path string) error {
return g.Delete(strings.Split(path, ".")...)
}
// Merge - Merges two gabs-containers
func (g *Container) Merge(toMerge *Container) error {
// MergeFn merges two objects using a provided function to resolve collisions.
//
// The collision function receives two interface{} arguments, destination (the
// original object) and source (the object being merged into the destination).
// Which ever value is returned becomes the new value in the destination object
// at the location of the collision.
func (g *Container) MergeFn(source *Container, collisionFn func(destination, source interface{}) interface{}) error {
var recursiveFnc func(map[string]interface{}, []string) error
recursiveFnc = func(mmap map[string]interface{}, path []string) error {
for key, value := range mmap {
newPath := append(path, key)
if g.Exists(newPath...) {
target := g.Search(newPath...)
existingData := g.Search(newPath...).Data()
switch t := value.(type) {
case map[string]interface{}:
switch targetV := target.Data().(type) {
switch existingVal := existingData.(type) {
case map[string]interface{}:
if err := recursiveFnc(t, newPath); err != nil {
return err
}
case []interface{}:
g.Set(append(targetV, t), newPath...)
default:
newSlice := append([]interface{}{}, targetV)
g.Set(append(newSlice, t), newPath...)
}
case []interface{}:
for _, valueOfSlice := range t {
if err := g.ArrayAppend(valueOfSlice, newPath...); err != nil {
if _, err := g.Set(collisionFn(existingVal, t), newPath...); err != nil {
return err
}
}
default:
switch targetV := target.Data().(type) {
case []interface{}:
g.Set(append(targetV, t), newPath...)
default:
newSlice := append([]interface{}{}, targetV)
g.Set(append(newSlice, t), newPath...)
if _, err := g.Set(collisionFn(existingData, t), newPath...); err != nil {
return err
}
}
} else {
@@ -354,21 +464,48 @@ func (g *Container) Merge(toMerge *Container) error {
}
return nil
}
if mmap, ok := toMerge.Data().(map[string]interface{}); ok {
if mmap, ok := source.Data().(map[string]interface{}); ok {
return recursiveFnc(mmap, []string{})
}
return nil
}
//--------------------------------------------------------------------------------------------------
// Merge a source object into an existing destination object. When a collision
// is found within the merged structures (both a source and destination object
// contain the same non-object keys) the result will be an array containing both
// values, where values that are already arrays will be expanded into the
// resulting array.
//
// It is possible to merge structures will different collision behaviours with
// MergeFn.
func (g *Container) Merge(source *Container) error {
return g.MergeFn(source, func(dest, source interface{}) interface{} {
destArr, destIsArray := dest.([]interface{})
sourceArr, sourceIsArray := source.([]interface{})
if destIsArray {
if sourceIsArray {
return append(destArr, sourceArr...)
}
return append(destArr, source)
}
if sourceIsArray {
return append(append([]interface{}{}, dest), sourceArr...)
}
return []interface{}{dest, source}
})
}
//------------------------------------------------------------------------------
/*
Array modification/search - Keeping these options simple right now, no need for anything more
complicated since you can just cast to []interface{}, modify and then reassign with Set.
Array modification/search - Keeping these options simple right now, no need for
anything more complicated since you can just cast to []interface{}, modify and
then reassign with Set.
*/
// ArrayAppend - Append a value onto a JSON array. If the target is not a JSON array then it will be
// converted into one, with its contents as the first element of the array.
// ArrayAppend attempts to append a value onto a JSON array at a path. If the
// target is not a JSON array then it will be converted into one, with its
// original contents set to the first element of the array.
func (g *Container) ArrayAppend(value interface{}, path ...string) error {
if array, ok := g.Search(path...).Data().([]interface{}); ok {
array = append(array, value)
@@ -386,12 +523,15 @@ func (g *Container) ArrayAppend(value interface{}, path ...string) error {
return err
}
// ArrayAppendP - Append a value onto a JSON array using a dot notation JSON path.
// ArrayAppendP attempts to append a value onto a JSON array at a path using dot
// notation. If the target is not a JSON array then it will be converted into
// one, with its original contents set to the first element of the array.
func (g *Container) ArrayAppendP(value interface{}, path string) error {
return g.ArrayAppend(value, strings.Split(path, ".")...)
}
// ArrayRemove - Remove an element from a JSON array.
// ArrayRemove attempts to remove an element identified by an index from a JSON
// array at a path.
func (g *Container) ArrayRemove(index int, path ...string) error {
if index < 0 {
return ErrOutOfBounds
@@ -409,12 +549,14 @@ func (g *Container) ArrayRemove(index int, path ...string) error {
return err
}
// ArrayRemoveP - Remove an element from a JSON array using a dot notation JSON path.
// ArrayRemoveP attempts to remove an element identified by an index from a JSON
// array at a path using dot notation.
func (g *Container) ArrayRemoveP(index int, path string) error {
return g.ArrayRemove(index, strings.Split(path, ".")...)
}
// ArrayElement - Access an element from a JSON array.
// ArrayElement attempts to access an element by an index from a JSON array at a
// path.
func (g *Container) ArrayElement(index int, path ...string) (*Container, error) {
if index < 0 {
return &Container{nil}, ErrOutOfBounds
@@ -429,12 +571,13 @@ func (g *Container) ArrayElement(index int, path ...string) (*Container, error)
return &Container{nil}, ErrOutOfBounds
}
// ArrayElementP - Access an element from a JSON array using a dot notation JSON path.
// ArrayElementP attempts to access an element by an index from a JSON array at
// a path using dot notation.
func (g *Container) ArrayElementP(index int, path string) (*Container, error) {
return g.ArrayElement(index, strings.Split(path, ".")...)
}
// ArrayCount - Count the number of elements in a JSON array.
// ArrayCount counts the number of elements in a JSON array at a path.
func (g *Container) ArrayCount(path ...string) (int, error) {
if array, ok := g.Search(path...).Data().([]interface{}); ok {
return len(array), nil
@@ -442,14 +585,15 @@ func (g *Container) ArrayCount(path ...string) (int, error) {
return 0, ErrNotArray
}
// ArrayCountP - Count the number of elements in a JSON array using a dot notation JSON path.
// ArrayCountP counts the number of elements in a JSON array at a path using dot
// notation.
func (g *Container) ArrayCountP(path string) (int, error) {
return g.ArrayCount(strings.Split(path, ".")...)
}
//--------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Bytes - Converts the contained object back to a JSON []byte blob.
// Bytes marshals an element to a JSON []byte blob.
func (g *Container) Bytes() []byte {
if g.Data() != nil {
if bytes, err := json.Marshal(g.object); err == nil {
@@ -459,7 +603,8 @@ func (g *Container) Bytes() []byte {
return []byte("{}")
}
// BytesIndent - Converts the contained object to a JSON []byte blob formatted with prefix, indent.
// BytesIndent marshals an element to a JSON []byte blob formatted with a prefix
// and indent string.
func (g *Container) BytesIndent(prefix string, indent string) []byte {
if g.object != nil {
if bytes, err := json.MarshalIndent(g.object, prefix, indent); err == nil {
@@ -469,12 +614,13 @@ func (g *Container) BytesIndent(prefix string, indent string) []byte {
return []byte("{}")
}
// String - Converts the contained object to a JSON formatted string.
// String marshals an element to a JSON formatted string.
func (g *Container) String() string {
return string(g.Bytes())
}
// StringIndent - Converts the contained object back to a JSON formatted string with prefix, indent.
// StringIndent marshals an element to a JSON string formatted with a prefix and
// indent string.
func (g *Container) StringIndent(prefix string, indent string) string {
return string(g.BytesIndent(prefix, indent))
}
@@ -496,10 +642,9 @@ func EncodeOptIndent(prefix string, indent string) EncodeOpt {
}
}
// EncodeJSON - Encodes the contained object back to a JSON formatted []byte
// using a variant list of modifier functions for the encoder being used.
// Functions for modifying the output are prefixed with EncodeOpt, e.g.
// EncodeOptHTMLEscape.
// EncodeJSON marshals an element to a JSON formatted []byte using a variant
// list of modifier functions for the encoder being used. Functions for
// modifying the output are prefixed with EncodeOpt, e.g. EncodeOptHTMLEscape.
func (g *Container) EncodeJSON(encodeOpts ...EncodeOpt) []byte {
var b bytes.Buffer
encoder := json.NewEncoder(&b)
@@ -517,17 +662,18 @@ func (g *Container) EncodeJSON(encodeOpts ...EncodeOpt) []byte {
return result
}
// New - Create a new gabs JSON object.
// New creates a new gabs JSON object.
func New() *Container {
return &Container{map[string]interface{}{}}
}
// Consume - Gobble up an already converted JSON object, or a fresh map[string]interface{} object.
// Consume an already unmarshalled JSON object (or a new map[string]interface{})
// into a *Container.
func Consume(root interface{}) (*Container, error) {
return &Container{root}, nil
}
// ParseJSON - Convert a string into a representation of the parsed JSON.
// ParseJSON unmarshals a JSON byte slice into a *Container.
func ParseJSON(sample []byte) (*Container, error) {
var gabs Container
@@ -538,7 +684,7 @@ func ParseJSON(sample []byte) (*Container, error) {
return &gabs, nil
}
// ParseJSONDecoder - Convert a json.Decoder into a representation of the parsed JSON.
// ParseJSONDecoder applies a json.Decoder to a *Container.
func ParseJSONDecoder(decoder *json.Decoder) (*Container, error) {
var gabs Container
@@ -549,7 +695,7 @@ func ParseJSONDecoder(decoder *json.Decoder) (*Container, error) {
return &gabs, nil
}
// ParseJSONFile - Read a file and convert into a representation of the parsed JSON.
// ParseJSONFile reads a file and unmarshals the contents into a *Container.
func ParseJSONFile(path string) (*Container, error) {
if len(path) > 0 {
cBytes, err := ioutil.ReadFile(path)
@@ -567,7 +713,7 @@ func ParseJSONFile(path string) (*Container, error) {
return nil, ErrInvalidPath
}
// ParseJSONBuffer - Read the contents of a buffer into a representation of the parsed JSON.
// ParseJSONBuffer reads a buffer and unmarshals the contents into a *Container.
func ParseJSONBuffer(buffer io.Reader) (*Container, error) {
var gabs Container
jsonDecoder := json.NewDecoder(buffer)
@@ -578,4 +724,4 @@ func ParseJSONBuffer(buffer io.Reader) (*Container, error) {
return &gabs, nil
}
//--------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------

1
vendor/github.com/Jeffail/gabs/go.mod generated vendored Normal file
View File

@@ -0,0 +1 @@
module github.com/Jeffail/gabs

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,12 @@
syntax = "proto2";
package proto;
message PaymentMoney {
optional int64 value = 1;
optional uint32 offset = 2;
optional string currencyCode = 3;
}
message HydratedQuickReplyButton {
optional string displayText = 1;
optional string id = 2;
@@ -69,18 +75,46 @@ message InteractiveAnnotation {
}
}
message DeviceListMetadata {
optional bytes senderKeyHash = 1;
optional uint64 senderTimestamp = 2;
optional bytes recipientKeyHash = 8;
optional uint64 recipientTimestamp = 9;
}
message MessageContextInfo {
optional DeviceListMetadata deviceListMetadata = 1;
}
message AdReplyInfo {
optional string advertiserName = 1;
enum AD_REPLY_INFO_MEDIATYPE {
enum AdReplyInfoMediaType {
NONE = 0;
IMAGE = 1;
VIDEO = 2;
}
optional AD_REPLY_INFO_MEDIATYPE mediaType = 2;
optional AdReplyInfoMediaType mediaType = 2;
optional bytes jpegThumbnail = 16;
optional string caption = 17;
}
message ExternalAdReplyInfo {
optional string title = 1;
optional string body = 2;
enum ExternalAdReplyInfoMediaType {
NONE = 0;
IMAGE = 1;
VIDEO = 2;
}
optional ExternalAdReplyInfoMediaType mediaType = 3;
optional string thumbnailUrl = 4;
optional string mediaUrl = 5;
optional bytes thumbnail = 6;
optional string sourceType = 7;
optional string sourceId = 8;
optional string sourceUrl = 9;
}
message ContextInfo {
optional string stanzaId = 1;
optional string participant = 2;
@@ -96,6 +130,8 @@ message ContextInfo {
optional MessageKey placeholderKey = 24;
optional uint32 expiration = 25;
optional int64 ephemeralSettingTimestamp = 26;
optional bytes ephemeralSharedSecret = 27;
optional ExternalAdReplyInfo externalAdReply = 28;
}
message SenderKeyDistributionMessage {
@@ -125,6 +161,27 @@ message ImageMessage {
repeated uint32 scanLengths = 22;
optional bytes midQualityFileSha256 = 23;
optional bytes midQualityFileEncSha256 = 24;
optional bool viewOnce = 25;
optional string thumbnailDirectPath = 26;
optional bytes thumbnailSha256 = 27;
optional bytes thumbnailEncSha256 = 28;
}
message InvoiceMessage {
optional string note = 1;
optional string token = 2;
enum InvoiceMessageAttachmentType {
IMAGE = 0;
PDF = 1;
}
optional InvoiceMessageAttachmentType attachmentType = 3;
optional string attachmentMimetype = 4;
optional bytes attachmentMediaKey = 5;
optional int64 attachmentMediaKeyTimestamp = 6;
optional bytes attachmentFileSha256 = 7;
optional bytes attachmentFileEncSha256 = 8;
optional string attachmentDirectPath = 9;
optional bytes attachmentJpegThumbnail = 10;
}
message ContactMessage {
@@ -156,7 +213,7 @@ message ExtendedTextMessage {
optional string title = 6;
optional fixed32 textArgb = 7;
optional fixed32 backgroundArgb = 8;
enum EXTENDED_TEXT_MESSAGE_FONTTYPE {
enum ExtendedTextMessageFontType {
SANS_SERIF = 0;
SERIF = 1;
NORICAN_REGULAR = 2;
@@ -164,12 +221,12 @@ message ExtendedTextMessage {
BEBASNEUE_REGULAR = 4;
OSWALD_HEAVY = 5;
}
optional EXTENDED_TEXT_MESSAGE_FONTTYPE font = 9;
enum EXTENDED_TEXT_MESSAGE_PREVIEWTYPE {
optional ExtendedTextMessageFontType font = 9;
enum ExtendedTextMessagePreviewType {
NONE = 0;
VIDEO = 1;
}
optional EXTENDED_TEXT_MESSAGE_PREVIEWTYPE previewType = 10;
optional ExtendedTextMessagePreviewType previewType = 10;
optional bytes jpegThumbnail = 16;
optional ContextInfo contextInfo = 17;
optional bool doNotPlayInline = 18;
@@ -187,8 +244,14 @@ message DocumentMessage {
optional bytes fileEncSha256 = 9;
optional string directPath = 10;
optional int64 mediaKeyTimestamp = 11;
optional bool contactVcard = 12;
optional string thumbnailDirectPath = 13;
optional bytes thumbnailSha256 = 14;
optional bytes thumbnailEncSha256 = 15;
optional bytes jpegThumbnail = 16;
optional ContextInfo contextInfo = 17;
optional uint32 thumbnailHeight = 18;
optional uint32 thumbnailWidth = 19;
}
message AudioMessage {
@@ -224,12 +287,16 @@ message VideoMessage {
optional bytes jpegThumbnail = 16;
optional ContextInfo contextInfo = 17;
optional bytes streamingSidecar = 18;
enum VIDEO_MESSAGE_ATTRIBUTION {
enum VideoMessageAttribution {
NONE = 0;
GIPHY = 1;
TENOR = 2;
}
optional VIDEO_MESSAGE_ATTRIBUTION gifAttribution = 19;
optional VideoMessageAttribution gifAttribution = 19;
optional bool viewOnce = 20;
optional string thumbnailDirectPath = 21;
optional bytes thumbnailSha256 = 22;
optional bytes thumbnailEncSha256 = 23;
}
message Call {
@@ -243,16 +310,25 @@ message Chat {
message ProtocolMessage {
optional MessageKey key = 1;
enum PROTOCOL_MESSAGE_TYPE {
enum ProtocolMessageType {
REVOKE = 0;
EPHEMERAL_SETTING = 3;
EPHEMERAL_SYNC_RESPONSE = 4;
HISTORY_SYNC_NOTIFICATION = 5;
APP_STATE_SYNC_KEY_SHARE = 6;
APP_STATE_SYNC_KEY_REQUEST = 7;
MSG_FANOUT_BACKFILL_REQUEST = 8;
INITIAL_SECURITY_NOTIFICATION_SETTING_SYNC = 9;
APP_STATE_FATAL_EXCEPTION_NOTIFICATION = 10;
}
optional PROTOCOL_MESSAGE_TYPE type = 2;
optional ProtocolMessageType type = 2;
optional uint32 ephemeralExpiration = 4;
optional int64 ephemeralSettingTimestamp = 5;
optional HistorySyncNotification historySyncNotification = 6;
optional AppStateSyncKeyShare appStateSyncKeyShare = 7;
optional AppStateSyncKeyRequest appStateSyncKeyRequest = 8;
optional InitialSecurityNotificationSettingSync initialSecurityNotificationSettingSync = 9;
optional AppStateFatalExceptionNotification appStateFatalExceptionNotification = 10;
}
message HistorySyncNotification {
@@ -261,14 +337,54 @@ message HistorySyncNotification {
optional bytes mediaKey = 3;
optional bytes fileEncSha256 = 4;
optional string directPath = 5;
enum HISTORY_SYNC_NOTIFICATION_HISTORYSYNCTYPE {
enum HistorySyncNotificationHistorySyncType {
INITIAL_BOOTSTRAP = 0;
INITIAL_STATUS_V3 = 1;
FULL = 2;
RECENT = 3;
PUSH_NAME = 4;
}
optional HISTORY_SYNC_NOTIFICATION_HISTORYSYNCTYPE syncType = 6;
optional HistorySyncNotificationHistorySyncType syncType = 6;
optional uint32 chunkOrder = 7;
optional string originalMessageId = 8;
}
message AppStateSyncKey {
optional AppStateSyncKeyId keyId = 1;
optional AppStateSyncKeyData keyData = 2;
}
message AppStateSyncKeyId {
optional bytes keyId = 1;
}
message AppStateSyncKeyFingerprint {
optional uint32 rawId = 1;
optional uint32 currentIndex = 2;
repeated uint32 deviceIndexes = 3 [packed=true];
}
message AppStateSyncKeyData {
optional bytes keyData = 1;
optional AppStateSyncKeyFingerprint fingerprint = 2;
optional int64 timestamp = 3;
}
message AppStateSyncKeyShare {
repeated AppStateSyncKey keys = 1;
}
message AppStateSyncKeyRequest {
repeated AppStateSyncKeyId keyIds = 1;
}
message AppStateFatalExceptionNotification {
repeated string collectionNames = 1;
optional int64 timestamp = 2;
}
message InitialSecurityNotificationSettingSync {
optional bool securityNotificationEnabled = 1;
}
message ContactsArrayMessage {
@@ -283,7 +399,7 @@ message HSMCurrency {
}
message HSMDateTimeComponent {
enum HSM_DATE_TIME_COMPONENT_DAYOFWEEKTYPE {
enum HSMDateTimeComponentDayOfWeekType {
MONDAY = 1;
TUESDAY = 2;
WEDNESDAY = 3;
@@ -292,17 +408,17 @@ message HSMDateTimeComponent {
SATURDAY = 6;
SUNDAY = 7;
}
optional HSM_DATE_TIME_COMPONENT_DAYOFWEEKTYPE dayOfWeek = 1;
optional HSMDateTimeComponentDayOfWeekType dayOfWeek = 1;
optional uint32 year = 2;
optional uint32 month = 3;
optional uint32 dayOfMonth = 4;
optional uint32 hour = 5;
optional uint32 minute = 6;
enum HSM_DATE_TIME_COMPONENT_CALENDARTYPE {
enum HSMDateTimeComponentCalendarType {
GREGORIAN = 1;
SOLAR_HIJRI = 2;
}
optional HSM_DATE_TIME_COMPONENT_CALENDARTYPE calendar = 7;
optional HSMDateTimeComponentCalendarType calendar = 7;
}
message HSMDateTimeUnixEpoch {
@@ -347,6 +463,7 @@ message RequestPaymentMessage {
optional uint64 amount1000 = 2;
optional string requestFrom = 3;
optional int64 expiryTimestamp = 5;
optional PaymentMoney amount = 6;
}
message DeclinePaymentRequestMessage {
@@ -457,6 +574,66 @@ message ProductMessage {
optional ContextInfo contextInfo = 17;
}
message OrderMessage {
optional string orderId = 1;
optional bytes thumbnail = 2;
optional int32 itemCount = 3;
enum OrderMessageOrderStatus {
INQUIRY = 1;
}
optional OrderMessageOrderStatus status = 4;
enum OrderMessageOrderSurface {
CATALOG = 1;
}
optional OrderMessageOrderSurface surface = 5;
optional string message = 6;
optional string orderTitle = 7;
optional string sellerJid = 8;
optional string token = 9;
optional int64 totalAmount1000 = 10;
optional string totalCurrencyCode = 11;
optional ContextInfo contextInfo = 17;
}
message Row {
optional string title = 1;
optional string description = 2;
optional string rowId = 3;
}
message Section {
optional string title = 1;
repeated Row rows = 2;
}
message ListMessage {
optional string title = 1;
optional string description = 2;
optional string buttonText = 3;
enum ListMessageListType {
UNKNOWN = 0;
SINGLE_SELECT = 1;
}
optional ListMessageListType listType = 4;
repeated Section sections = 5;
}
message SingleSelectReply {
optional string selectedRowId = 1;
}
message ListResponseMessage {
optional string title = 1;
enum ListResponseMessageListType {
UNKNOWN = 0;
SINGLE_SELECT = 1;
}
optional ListResponseMessageListType listType = 2;
optional SingleSelectReply singleSelectReply = 3;
optional ContextInfo contextInfo = 4;
optional string description = 5;
}
message GroupInviteMessage {
optional string groupJid = 1;
optional string inviteCode = 2;
@@ -467,13 +644,72 @@ message GroupInviteMessage {
optional ContextInfo contextInfo = 7;
}
message EphemeralSetting {
optional string chatJid = 1;
optional uint32 ephemeralExpiration = 2;
optional int64 ephemeralSettingTimestamp = 3;
}
message DeviceSentMessage {
optional string destinationJid = 1;
optional Message message = 2;
optional string phash = 3;
repeated EphemeralSetting broadcastEphemeralSettings = 4;
}
message DeviceSyncMessage {
optional bytes serializedXmlBytes = 1;
message FutureProofMessage {
optional Message message = 1;
}
message ButtonText {
optional string displayText = 1;
}
message Button {
optional string buttonId = 1;
optional ButtonText buttonText = 2;
enum ButtonType {
UNKNOWN = 0;
RESPONSE = 1;
}
optional ButtonType type = 3;
}
message ButtonsMessage {
optional string contentText = 6;
optional string footerText = 7;
optional ContextInfo contextInfo = 8;
repeated Button buttons = 9;
enum ButtonsMessageHeaderType {
UNKNOWN = 0;
EMPTY = 1;
TEXT = 2;
DOCUMENT = 3;
IMAGE = 4;
VIDEO = 5;
LOCATION = 6;
}
optional ButtonsMessageHeaderType headerType = 10;
oneof header {
string text = 1;
DocumentMessage documentMessage = 2;
ImageMessage imageMessage = 3;
VideoMessage videoMessage = 4;
LocationMessage locationMessage = 5;
}
}
message ButtonsResponseMessage {
optional string selectedButtonId = 1;
optional ContextInfo contextInfo = 3;
enum ButtonsResponseMessageType {
UNKNOWN = 0;
DISPLAY_TEXT = 1;
}
optional ButtonsResponseMessageType type = 4;
oneof response {
string selectedDisplayText = 2;
}
}
message Message {
@@ -503,7 +739,15 @@ message Message {
optional TemplateButtonReplyMessage templateButtonReplyMessage = 29;
optional ProductMessage productMessage = 30;
optional DeviceSentMessage deviceSentMessage = 31;
optional DeviceSyncMessage deviceSyncMessage = 32;
optional MessageContextInfo messageContextInfo = 35;
optional ListMessage listMessage = 36;
optional FutureProofMessage viewOnceMessage = 37;
optional OrderMessage orderMessage = 38;
optional ListResponseMessage listResponseMessage = 39;
optional FutureProofMessage ephemeralMessage = 40;
optional InvoiceMessage invoiceMessage = 41;
optional ButtonsMessage buttonsMessage = 42;
optional ButtonsResponseMessage buttonsResponseMessage = 43;
}
message MessageKey {
@@ -514,51 +758,52 @@ message MessageKey {
}
message WebFeatures {
enum WEB_FEATURES_FLAG {
enum WebFeaturesFlag {
NOT_STARTED = 0;
FORCE_UPGRADE = 1;
DEVELOPMENT = 2;
PRODUCTION = 3;
}
optional WEB_FEATURES_FLAG labelsDisplay = 1;
optional WEB_FEATURES_FLAG voipIndividualOutgoing = 2;
optional WEB_FEATURES_FLAG groupsV3 = 3;
optional WEB_FEATURES_FLAG groupsV3Create = 4;
optional WEB_FEATURES_FLAG changeNumberV2 = 5;
optional WEB_FEATURES_FLAG queryStatusV3Thumbnail = 6;
optional WEB_FEATURES_FLAG liveLocations = 7;
optional WEB_FEATURES_FLAG queryVname = 8;
optional WEB_FEATURES_FLAG voipIndividualIncoming = 9;
optional WEB_FEATURES_FLAG quickRepliesQuery = 10;
optional WEB_FEATURES_FLAG payments = 11;
optional WEB_FEATURES_FLAG stickerPackQuery = 12;
optional WEB_FEATURES_FLAG liveLocationsFinal = 13;
optional WEB_FEATURES_FLAG labelsEdit = 14;
optional WEB_FEATURES_FLAG mediaUpload = 15;
optional WEB_FEATURES_FLAG mediaUploadRichQuickReplies = 18;
optional WEB_FEATURES_FLAG vnameV2 = 19;
optional WEB_FEATURES_FLAG videoPlaybackUrl = 20;
optional WEB_FEATURES_FLAG statusRanking = 21;
optional WEB_FEATURES_FLAG voipIndividualVideo = 22;
optional WEB_FEATURES_FLAG thirdPartyStickers = 23;
optional WEB_FEATURES_FLAG frequentlyForwardedSetting = 24;
optional WEB_FEATURES_FLAG groupsV4JoinPermission = 25;
optional WEB_FEATURES_FLAG recentStickers = 26;
optional WEB_FEATURES_FLAG catalog = 27;
optional WEB_FEATURES_FLAG starredStickers = 28;
optional WEB_FEATURES_FLAG voipGroupCall = 29;
optional WEB_FEATURES_FLAG templateMessage = 30;
optional WEB_FEATURES_FLAG templateMessageInteractivity = 31;
optional WEB_FEATURES_FLAG ephemeralMessages = 32;
optional WEB_FEATURES_FLAG e2ENotificationSync = 33;
optional WEB_FEATURES_FLAG recentStickersV2 = 34;
}
message TabletNotificationsInfo {
optional uint64 timestamp = 2;
optional uint32 unreadChats = 3;
optional uint32 notifyMessageCount = 4;
repeated NotificationMessageInfo notifyMessage = 5;
optional WebFeaturesFlag labelsDisplay = 1;
optional WebFeaturesFlag voipIndividualOutgoing = 2;
optional WebFeaturesFlag groupsV3 = 3;
optional WebFeaturesFlag groupsV3Create = 4;
optional WebFeaturesFlag changeNumberV2 = 5;
optional WebFeaturesFlag queryStatusV3Thumbnail = 6;
optional WebFeaturesFlag liveLocations = 7;
optional WebFeaturesFlag queryVname = 8;
optional WebFeaturesFlag voipIndividualIncoming = 9;
optional WebFeaturesFlag quickRepliesQuery = 10;
optional WebFeaturesFlag payments = 11;
optional WebFeaturesFlag stickerPackQuery = 12;
optional WebFeaturesFlag liveLocationsFinal = 13;
optional WebFeaturesFlag labelsEdit = 14;
optional WebFeaturesFlag mediaUpload = 15;
optional WebFeaturesFlag mediaUploadRichQuickReplies = 18;
optional WebFeaturesFlag vnameV2 = 19;
optional WebFeaturesFlag videoPlaybackUrl = 20;
optional WebFeaturesFlag statusRanking = 21;
optional WebFeaturesFlag voipIndividualVideo = 22;
optional WebFeaturesFlag thirdPartyStickers = 23;
optional WebFeaturesFlag frequentlyForwardedSetting = 24;
optional WebFeaturesFlag groupsV4JoinPermission = 25;
optional WebFeaturesFlag recentStickers = 26;
optional WebFeaturesFlag catalog = 27;
optional WebFeaturesFlag starredStickers = 28;
optional WebFeaturesFlag voipGroupCall = 29;
optional WebFeaturesFlag templateMessage = 30;
optional WebFeaturesFlag templateMessageInteractivity = 31;
optional WebFeaturesFlag ephemeralMessages = 32;
optional WebFeaturesFlag e2ENotificationSync = 33;
optional WebFeaturesFlag recentStickersV2 = 34;
optional WebFeaturesFlag syncdRelease1 = 35;
optional WebFeaturesFlag recentStickersV3 = 36;
optional WebFeaturesFlag userNotice = 37;
optional WebFeaturesFlag syncdRelease11 = 38;
optional WebFeaturesFlag support = 39;
optional WebFeaturesFlag groupUiiCleanup = 40;
optional WebFeaturesFlag groupDogfoodingInternalOnly = 41;
optional WebFeaturesFlag settingsSync = 42;
}
message NotificationMessageInfo {
@@ -576,14 +821,14 @@ message WebNotificationsInfo {
}
message PaymentInfo {
enum PAYMENT_INFO_CURRENCY {
enum PaymentInfoCurrency {
UNKNOWN_CURRENCY = 0;
INR = 1;
}
optional PAYMENT_INFO_CURRENCY currencyDeprecated = 1;
optional PaymentInfoCurrency currencyDeprecated = 1;
optional uint64 amount1000 = 2;
optional string receiverJid = 3;
enum PAYMENT_INFO_STATUS {
enum PaymentInfoStatus {
UNKNOWN_STATUS = 0;
PROCESSING = 1;
SENT = 2;
@@ -597,13 +842,13 @@ message PaymentInfo {
WAITING_FOR_PAYER = 10;
WAITING = 11;
}
optional PAYMENT_INFO_STATUS status = 4;
optional PaymentInfoStatus status = 4;
optional uint64 transactionTimestamp = 5;
optional MessageKey requestMessageKey = 6;
optional uint64 expiryTimestamp = 7;
optional bool futureproofed = 8;
optional string currency = 9;
enum PAYMENT_INFO_TXNSTATUS {
enum PaymentInfoTxnStatus {
UNKNOWN = 0;
PENDING_SETUP = 1;
PENDING_RECEIVER_SETUP = 2;
@@ -633,14 +878,17 @@ message PaymentInfo {
COLLECT_CANCELED = 26;
COLLECT_CANCELLING = 27;
}
optional PAYMENT_INFO_TXNSTATUS txnStatus = 10;
optional PaymentInfoTxnStatus txnStatus = 10;
optional bool useNoviFiatFormat = 11;
optional PaymentMoney primaryAmount = 12;
optional PaymentMoney exchangeAmount = 13;
}
message WebMessageInfo {
required MessageKey key = 1;
optional Message message = 2;
optional uint64 messageTimestamp = 3;
enum WEB_MESSAGE_INFO_STATUS {
enum WebMessageInfoStatus {
ERROR = 0;
PENDING = 1;
SERVER_ACK = 2;
@@ -648,7 +896,7 @@ message WebMessageInfo {
READ = 4;
PLAYED = 5;
}
optional WEB_MESSAGE_INFO_STATUS status = 4;
optional WebMessageInfoStatus status = 4;
optional string participant = 5;
optional bool ignore = 16;
optional bool starred = 17;
@@ -658,7 +906,7 @@ message WebMessageInfo {
optional bool multicast = 21;
optional bool urlText = 22;
optional bool urlNumber = 23;
enum WEB_MESSAGE_INFO_STUBTYPE {
enum WebMessageInfoStubType {
UNKNOWN = 0;
REVOKE = 1;
CIPHERTEXT = 2;
@@ -732,8 +980,54 @@ message WebMessageInfo {
GROUP_V4_ADD_INVITE_SENT = 70;
GROUP_PARTICIPANT_ADD_REQUEST_JOIN = 71;
CHANGE_EPHEMERAL_SETTING = 72;
E2E_DEVICE_CHANGED = 73;
VIEWED_ONCE = 74;
E2E_ENCRYPTED_NOW = 75;
BLUE_MSG_BSP_FB_TO_BSP_PREMISE = 76;
BLUE_MSG_BSP_FB_TO_SELF_FB = 77;
BLUE_MSG_BSP_FB_TO_SELF_PREMISE = 78;
BLUE_MSG_BSP_FB_UNVERIFIED = 79;
BLUE_MSG_BSP_FB_UNVERIFIED_TO_SELF_PREMISE_VERIFIED = 80;
BLUE_MSG_BSP_FB_VERIFIED = 81;
BLUE_MSG_BSP_FB_VERIFIED_TO_SELF_PREMISE_UNVERIFIED = 82;
BLUE_MSG_BSP_PREMISE_TO_SELF_PREMISE = 83;
BLUE_MSG_BSP_PREMISE_UNVERIFIED = 84;
BLUE_MSG_BSP_PREMISE_UNVERIFIED_TO_SELF_PREMISE_VERIFIED = 85;
BLUE_MSG_BSP_PREMISE_VERIFIED = 86;
BLUE_MSG_BSP_PREMISE_VERIFIED_TO_SELF_PREMISE_UNVERIFIED = 87;
BLUE_MSG_CONSUMER_TO_BSP_FB_UNVERIFIED = 88;
BLUE_MSG_CONSUMER_TO_BSP_PREMISE_UNVERIFIED = 89;
BLUE_MSG_CONSUMER_TO_SELF_FB_UNVERIFIED = 90;
BLUE_MSG_CONSUMER_TO_SELF_PREMISE_UNVERIFIED = 91;
BLUE_MSG_SELF_FB_TO_BSP_PREMISE = 92;
BLUE_MSG_SELF_FB_TO_SELF_PREMISE = 93;
BLUE_MSG_SELF_FB_UNVERIFIED = 94;
BLUE_MSG_SELF_FB_UNVERIFIED_TO_SELF_PREMISE_VERIFIED = 95;
BLUE_MSG_SELF_FB_VERIFIED = 96;
BLUE_MSG_SELF_FB_VERIFIED_TO_SELF_PREMISE_UNVERIFIED = 97;
BLUE_MSG_SELF_PREMISE_TO_BSP_PREMISE = 98;
BLUE_MSG_SELF_PREMISE_UNVERIFIED = 99;
BLUE_MSG_SELF_PREMISE_VERIFIED = 100;
BLUE_MSG_TO_BSP_FB = 101;
BLUE_MSG_TO_CONSUMER = 102;
BLUE_MSG_TO_SELF_FB = 103;
BLUE_MSG_UNVERIFIED_TO_BSP_FB_VERIFIED = 104;
BLUE_MSG_UNVERIFIED_TO_BSP_PREMISE_VERIFIED = 105;
BLUE_MSG_UNVERIFIED_TO_SELF_FB_VERIFIED = 106;
BLUE_MSG_UNVERIFIED_TO_VERIFIED = 107;
BLUE_MSG_VERIFIED_TO_BSP_FB_UNVERIFIED = 108;
BLUE_MSG_VERIFIED_TO_BSP_PREMISE_UNVERIFIED = 109;
BLUE_MSG_VERIFIED_TO_SELF_FB_UNVERIFIED = 110;
BLUE_MSG_VERIFIED_TO_UNVERIFIED = 111;
BLUE_MSG_BSP_FB_UNVERIFIED_TO_BSP_PREMISE_VERIFIED = 112;
BLUE_MSG_BSP_FB_UNVERIFIED_TO_SELF_FB_VERIFIED = 113;
BLUE_MSG_BSP_FB_VERIFIED_TO_BSP_PREMISE_UNVERIFIED = 114;
BLUE_MSG_BSP_FB_VERIFIED_TO_SELF_FB_UNVERIFIED = 115;
BLUE_MSG_SELF_FB_UNVERIFIED_TO_BSP_PREMISE_VERIFIED = 116;
BLUE_MSG_SELF_FB_VERIFIED_TO_BSP_PREMISE_UNVERIFIED = 117;
E2E_IDENTITY_UNAVAILABLE = 118;
}
optional WEB_MESSAGE_INFO_STUBTYPE messageStubType = 24;
optional WebMessageInfoStubType messageStubType = 24;
optional bool clearMedia = 25;
repeated string messageStubParameters = 26;
optional uint32 duration = 27;
@@ -743,5 +1037,14 @@ message WebMessageInfo {
optional PaymentInfo quotedPaymentInfo = 31;
optional uint64 ephemeralStartTimestamp = 32;
optional uint32 ephemeralDuration = 33;
}
optional bool ephemeralOffToOn = 34;
optional bool ephemeralOutOfSync = 35;
enum WebMessageInfoBizPrivacyStatus {
E2EE = 0;
FB = 2;
BSP = 1;
BSP_AND_FB = 3;
}
optional WebMessageInfoBizPrivacyStatus bizPrivacyStatus = 36;
optional string verifiedBizName = 37;
}

View File

@@ -24,7 +24,10 @@ var SingleByteTokens = [...]string{"", "", "", "200", "400", "404", "500", "501"
"invite", "gif", "vcard", "frequent", "privacy", "blacklist", "whitelist",
"verify", "location", "document", "elapsed", "revoke_invite", "expiration",
"unsubscribe", "disable", "vname", "old_jid", "new_jid", "announcement",
"locked", "prop", "label", "color", "call", "offer", "call-id"}
"locked", "prop", "label", "color", "call", "offer", "call-id",
"quick_reply", "sticker", "pay_t", "accept", "reject", "sticker_pack",
"invalid", "canceled", "missed", "connected", "result", "audio",
"video", "recent"}
var doubleByteTokens = [...]string{}

View File

@@ -2,9 +2,11 @@ package whatsapp
import (
"fmt"
"github.com/Rhymen/go-whatsapp/binary"
"strconv"
"strings"
"time"
"github.com/Rhymen/go-whatsapp/binary"
)
type Presence string
@@ -241,3 +243,80 @@ func buildParticipantNodes(participants []string) []binary.Node {
}
return p
}
func (wac *Conn) BlockContact(jid string) (<-chan string, error) {
return wac.handleBlockContact("add", jid)
}
func (wac *Conn) UnblockContact(jid string) (<-chan string, error) {
return wac.handleBlockContact("remove", jid)
}
func (wac *Conn) handleBlockContact(action, jid string) (<-chan string, error) {
ts := time.Now().Unix()
tag := fmt.Sprintf("%d.--%d", ts, wac.msgCount)
netsplit := strings.Split(jid, "@")
cusjid := netsplit[0] + "@c.us"
n := binary.Node{
Description: "action",
Attributes: map[string]string{
"type": "set",
"epoch": strconv.Itoa(wac.msgCount),
},
Content: []interface{}{
binary.Node{
Description: "block",
Attributes: map[string]string{
"type": action,
},
Content: []binary.Node{
{
Description: "user",
Attributes: map[string]string{
"jid": cusjid,
},
Content: nil,
},
},
},
},
}
return wac.writeBinary(n, contact, ignore, tag)
}
// Search product details on order
func (wac *Conn) SearchProductDetails(id, orderId, token string) (<-chan string, error) {
data := []interface{}{"query", "order", map[string]string{
"id": id,
"orderId": orderId,
"imageHeight": strconv.Itoa(80),
"imageWidth": strconv.Itoa(80),
"token": token,
}}
return wac.writeJson(data)
}
// Order search and get product catalog reh
func (wac *Conn) SearchOrder(catalogWid, stanzaId string) (<-chan string, error) {
data := []interface{}{"query", "bizCatalog", map[string]string{
"catalogWid": catalogWid,
"limit": strconv.Itoa(10),
"height": strconv.Itoa(100),
"width": strconv.Itoa(100),
"stanza_id": stanzaId,
"type": "get_product_catalog_reh",
}}
return wac.writeJson(data)
}
// Company details for Whatsapp Business
func (wac *Conn) BusinessProfile(wid string) (<-chan string, error) {
query := map[string]string{
"wid": wid,
}
data := []interface{}{"query", "businessProfile", []map[string]string{query}}
return wac.writeJson(data)
}

View File

@@ -7,23 +7,21 @@ import (
)
var (
ErrAlreadyConnected = errors.New("already connected")
ErrAlreadyLoggedIn = errors.New("already logged in")
ErrInvalidSession = errors.New("invalid session")
ErrLoginInProgress = errors.New("login or restore already running")
ErrNotConnected = errors.New("not connected")
ErrInvalidWsData = errors.New("received invalid data")
ErrInvalidWsState = errors.New("can't handle binary data when not logged in")
ErrConnectionTimeout = errors.New("connection timed out")
ErrMissingMessageTag = errors.New("no messageTag specified or to short")
ErrInvalidHmac = errors.New("invalid hmac")
ErrInvalidServerResponse = errors.New("invalid response received from server")
ErrServerRespondedWith404 = errors.New("server responded with status 404")
ErrMediaDownloadFailedWith404 = errors.New("download failed with status code 404")
ErrMediaDownloadFailedWith410 = errors.New("download failed with status code 410")
ErrInvalidWebsocket = errors.New("invalid websocket")
ErrMessageTypeNotImplemented = errors.New("message type not implemented")
ErrOptionsNotProvided = errors.New("new conn options not provided")
ErrAlreadyConnected = errors.New("already connected")
ErrAlreadyLoggedIn = errors.New("already logged in")
ErrInvalidSession = errors.New("invalid session")
ErrLoginInProgress = errors.New("login or restore already running")
ErrNotConnected = errors.New("not connected")
ErrInvalidWsData = errors.New("received invalid data")
ErrInvalidWsState = errors.New("can't handle binary data when not logged in")
ErrConnectionTimeout = errors.New("connection timed out")
ErrMissingMessageTag = errors.New("no messageTag specified or to short")
ErrInvalidHmac = errors.New("invalid hmac")
ErrInvalidServerResponse = errors.New("invalid response received from server")
ErrServerRespondedWith404 = errors.New("server responded with status 404")
ErrInvalidWebsocket = errors.New("invalid websocket")
ErrMessageTypeNotImplemented = errors.New("message type not implemented")
ErrOptionsNotProvided = errors.New("new conn options not provided")
)
type ErrConnectionFailed struct {

View File

@@ -1,14 +1,11 @@
module github.com/Rhymen/go-whatsapp
require (
github.com/Rhymen/go-whatsapp/examples/echo v0.0.0-20190325075644-cc2581bbf24d // indirect
github.com/Rhymen/go-whatsapp/examples/restoreSession v0.0.0-20190325075644-cc2581bbf24d // indirect
github.com/Rhymen/go-whatsapp/examples/sendImage v0.0.0-20190325075644-cc2581bbf24d // indirect
github.com/Rhymen/go-whatsapp/examples/sendTextMessages v0.0.0-20190325075644-cc2581bbf24d // indirect
github.com/golang/protobuf v1.3.0
github.com/golang/protobuf v1.4.1
github.com/gorilla/websocket v1.4.1
github.com/pkg/errors v0.8.1
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
google.golang.org/protobuf v1.25.0
)
go 1.13

View File

@@ -1,37 +1,71 @@
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f h1:2dk3eOnYllh+wUOuDhOoC2vUVoJF/5z478ryJ+wzEII=
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk=
github.com/Rhymen/go-whatsapp v0.0.0/go.mod h1:rdQr95g2C1xcOfM7QGOhza58HeI3I+tZ/bbluv7VazA=
github.com/Rhymen/go-whatsapp/examples/echo v0.0.0-20190325075644-cc2581bbf24d h1:m3wkrunHupL9XzzM+JZu1pgoDV1d9LFtD0gedNTHVDU=
github.com/Rhymen/go-whatsapp/examples/echo v0.0.0-20190325075644-cc2581bbf24d/go.mod h1:zgCiQtBtZ4P4gFWvwl9aashsdwOcbb/EHOGRmSzM8ME=
github.com/Rhymen/go-whatsapp/examples/restoreSession v0.0.0-20190325075644-cc2581bbf24d h1:muQlzqfZxjptOBjPdv+UoxVMr8Y1rPx7VMGPJIAFc5w=
github.com/Rhymen/go-whatsapp/examples/restoreSession v0.0.0-20190325075644-cc2581bbf24d/go.mod h1:5sCUSpG616ZoSJhlt9iBNI/KXBqrVLcNUJqg7J9+8pU=
github.com/Rhymen/go-whatsapp/examples/sendImage v0.0.0-20190325075644-cc2581bbf24d h1:xP//3V77YvHd1cj2Z3ttuQWAvs5WmIwBbjKe/t0g/tM=
github.com/Rhymen/go-whatsapp/examples/sendImage v0.0.0-20190325075644-cc2581bbf24d/go.mod h1:RdiyhanVEGXTam+mZ3k6Y3VDCCvXYCwReOoxGozqhHw=
github.com/Rhymen/go-whatsapp/examples/sendTextMessages v0.0.0-20190325075644-cc2581bbf24d h1:IRmRE0SPMByczwE2dhnTcVojje3w2TCSKwFrboLUbDg=
github.com/Rhymen/go-whatsapp/examples/sendTextMessages v0.0.0-20190325075644-cc2581bbf24d/go.mod h1:suwzklatySS3Q0+NCxCDh5hYfgXdQUWU1DNcxwAxStM=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk=
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9 h1:lpEzuenPuO1XNTeikEmvqYFcU37GVLl8SRNblzyvGBE=
github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo=
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View File

@@ -97,6 +97,22 @@ type ContactMessageHandler interface {
HandleContactMessage(message ContactMessage)
}
/*
The ProductMessageHandler interface needs to be implemented to receive product messages dispatched by the dispatcher.
*/
type ProductMessageHandler interface {
Handler
HandleProductMessage(message ProductMessage)
}
/*
The OrderMessageHandler interface needs to be implemented to receive order messages dispatched by the dispatcher.
*/
type OrderMessageHandler interface {
Handler
HandleOrderMessage(message OrderMessage)
}
/*
The JsonMessageHandler interface needs to be implemented to receive json messages dispatched by the dispatcher.
These json messages contain status updates of every kind sent by WhatsAppWeb servers. WhatsAppWeb uses these messages
@@ -301,7 +317,7 @@ func (wac *Conn) handleWithCustomHandlers(message interface{}, handlers []Handle
}
}
}
case BatteryMessage:
for _, h := range handlers {
if x, ok := h.(BatteryMessageHandler); ok {
@@ -312,7 +328,7 @@ func (wac *Conn) handleWithCustomHandlers(message interface{}, handlers []Handle
}
}
}
case Contact:
for _, h := range handlers {
if x, ok := h.(NewContactHandler); ok {
@@ -324,6 +340,28 @@ func (wac *Conn) handleWithCustomHandlers(message interface{}, handlers []Handle
}
}
case ProductMessage:
for _, h := range handlers {
if x, ok := h.(ProductMessageHandler); ok {
if wac.shouldCallSynchronously(h) {
x.HandleProductMessage(m)
} else {
go x.HandleProductMessage(m)
}
}
}
case OrderMessage:
for _, h := range handlers {
if x, ok := h.(OrderMessageHandler); ok {
if wac.shouldCallSynchronously(h) {
x.HandleOrderMessage(m)
} else {
go x.HandleOrderMessage(m)
}
}
}
case *proto.WebMessageInfo:
for _, h := range handlers {
if x, ok := h.(RawMessageHandler); ok {

View File

@@ -10,6 +10,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
"time"
@@ -71,16 +72,10 @@ func downloadMedia(url string) (file []byte, mac []byte, err error) {
if err != nil {
return nil, nil, err
}
if resp.StatusCode != 200 {
if resp.StatusCode == 404 {
return nil, nil, ErrMediaDownloadFailedWith404
}
if resp.StatusCode == 410 {
return nil, nil, ErrMediaDownloadFailedWith410
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, nil, fmt.Errorf("download failed with status code %d", resp.StatusCode)
}
defer resp.Body.Close()
if resp.ContentLength <= 10 {
return nil, nil, fmt.Errorf("file to short")
}
@@ -101,8 +96,8 @@ type MediaConn struct {
Hosts []struct {
Hostname string `json:"hostname"`
IPs []struct {
IP4 string `json:"ip4"`
IP6 string `json:"ip6"`
IP4 net.IP `json:"ip4"`
IP6 net.IP `json:"ip6"`
} `json:"ips"`
} `json:"hosts"`
} `json:"media_conn"`
@@ -125,21 +120,17 @@ func (wac *Conn) queryMediaConn() (hostname, auth string, ttl int, err error) {
return "", "", 0, fmt.Errorf("query media conn timed out")
}
if resp.Status != 200 {
if resp.Status != http.StatusOK {
return "", "", 0, fmt.Errorf("query media conn responded with %d", resp.Status)
}
var host string
for _, h := range resp.MediaConn.Hosts {
if h.Hostname != "" {
host = h.Hostname
break
return h.Hostname, resp.MediaConn.Auth, resp.MediaConn.TTL, nil
}
}
if host == "" {
return "", "", 0, fmt.Errorf("query media conn responded with no host")
}
return host, resp.MediaConn.Auth, resp.MediaConn.TTL, nil
return "", "", 0, fmt.Errorf("query media conn responded with no host")
}
var mediaTypeMap = map[MediaType]string{
@@ -202,7 +193,7 @@ func (wac *Conn) Upload(reader io.Reader, appInfo MediaType) (downloadURL string
body := bytes.NewReader(append(enc, mac...))
req, err := http.NewRequest("POST", uploadURL.String(), body)
req, err := http.NewRequest(http.MethodPost, uploadURL.String(), body)
if err != nil {
return "", nil, nil, nil, 0, err
}
@@ -222,7 +213,9 @@ func (wac *Conn) Upload(reader io.Reader, appInfo MediaType) (downloadURL string
}
var jsonRes map[string]string
json.NewDecoder(res.Body).Decode(&jsonRes)
if err := json.NewDecoder(res.Body).Decode(&jsonRes); err != nil {
return "", nil, nil, nil, 0, err
}
return jsonRes["url"], mediaKey, fileEncSha256, fileSha256, fileLength, nil
}

View File

@@ -65,10 +65,15 @@ func (wac *Conn) Send(msg interface{}) (string, error) {
msgProto = GetLiveLocationProto(m)
case ContactMessage:
msgProto = getContactMessageProto(m)
case ProductMessage:
msgProto = getProductMessageProto(m)
case OrderMessage:
msgProto = getOrderMessageProto(m)
default:
return "ERROR", fmt.Errorf("cannot match type %T, use message types declared in the package", msg)
}
status := proto.WebMessageInfo_PENDING
msgProto.Status = &status
ch, err := wac.sendProto(msgProto)
if err != nil {
return "ERROR", fmt.Errorf("could not send proto: %v", err)
@@ -258,7 +263,7 @@ func getInfoProto(info *MessageInfo) *proto.WebMessageInfo {
}
info.FromMe = true
status := proto.WebMessageInfo_WEB_MESSAGE_INFO_STATUS(info.Status)
status := proto.WebMessageInfo_WebMessageInfoStatus(info.Status)
return &proto.WebMessageInfo{
Key: &proto.MessageKey{
@@ -802,6 +807,113 @@ func getContactMessageProto(msg ContactMessage) *proto.WebMessageInfo {
return p
}
/*
OrderMessage represents a order message.
*/
type OrderMessage struct {
Info MessageInfo
OrderId string
Thumbnail []byte
ItemCount int32
Status proto.OrderMessage_OrderMessageOrderStatus
Surface proto.OrderMessage_OrderMessageOrderSurface
Message string
OrderTitle string
SellerJid string
Token string
TotalAmount1000 int64
TotalCurrencyCode string
ContextInfo ContextInfo
}
func getOrderMessage(msg *proto.WebMessageInfo) OrderMessage {
order := msg.GetMessage().GetOrderMessage()
orderMessage := OrderMessage{
Info: getMessageInfo(msg),
OrderId: order.GetOrderId(),
Thumbnail: order.GetThumbnail(),
ItemCount: order.GetItemCount(),
Status: order.GetStatus(),
Surface: order.GetSurface(),
Message: order.GetMessage(),
OrderTitle: order.GetOrderTitle(),
SellerJid: order.GetSellerJid(),
Token: order.GetToken(),
TotalAmount1000: order.GetTotalAmount1000(),
TotalCurrencyCode: order.GetTotalCurrencyCode(),
ContextInfo: getMessageContext(order.GetContextInfo()),
}
return orderMessage
}
func getOrderMessageProto(msg OrderMessage) *proto.WebMessageInfo {
p := getInfoProto(&msg.Info)
contextInfo := getContextInfoProto(&msg.ContextInfo)
p.Message = &proto.Message{
OrderMessage: &proto.OrderMessage{
Thumbnail: msg.Thumbnail,
ItemCount: &msg.ItemCount,
Status: &msg.Status,
Surface: &msg.Surface,
Message: &msg.Message,
OrderTitle: &msg.OrderTitle,
SellerJid: &msg.SellerJid,
Token: &msg.Token,
TotalAmount1000: &msg.TotalAmount1000,
TotalCurrencyCode: &msg.TotalCurrencyCode,
ContextInfo: contextInfo,
},
}
return p
}
/*
ProductMessage represents a product message.
*/
type ProductMessage struct {
Info MessageInfo
Product *proto.ProductSnapshot
BusinessOwnerJid string
Catalog *proto.CatalogSnapshot
ContextInfo ContextInfo
}
func getProductMessage(msg *proto.WebMessageInfo) ProductMessage {
prod := msg.GetMessage().GetProductMessage()
productMessage := ProductMessage{
Info: getMessageInfo(msg),
Product: prod.GetProduct(),
BusinessOwnerJid: prod.GetBusinessOwnerJid(),
Catalog: prod.GetCatalog(),
ContextInfo: getMessageContext(prod.GetContextInfo()),
}
return productMessage
}
func getProductMessageProto(msg ProductMessage) *proto.WebMessageInfo {
p := getInfoProto(&msg.Info)
contextInfo := getContextInfoProto(&msg.ContextInfo)
p.Message = &proto.Message{
ProductMessage: &proto.ProductMessage{
Product: msg.Product,
BusinessOwnerJid: &msg.BusinessOwnerJid,
Catalog: msg.Catalog,
ContextInfo: contextInfo,
},
}
return p
}
func ParseProtoMessage(msg *proto.WebMessageInfo) interface{} {
switch {
@@ -836,6 +948,12 @@ func ParseProtoMessage(msg *proto.WebMessageInfo) interface{} {
case msg.GetMessage().GetContactMessage() != nil:
return getContactMessage(msg)
case msg.GetMessage().GetProductMessage() != nil:
return getProductMessage(msg)
case msg.GetMessage().GetOrderMessage() != nil:
return getOrderMessage(msg)
default:
//cannot match message
return ErrMessageTypeNotImplemented

View File

@@ -2,9 +2,10 @@ package whatsapp
import (
"fmt"
"github.com/Rhymen/go-whatsapp/binary"
"strconv"
"time"
"github.com/Rhymen/go-whatsapp/binary"
)
// Pictures must be JPG 640x640 and 96x96, respectively
@@ -41,3 +42,24 @@ func (wac *Conn) UploadProfilePic(image, preview []byte) (<-chan string, error)
}
return wac.writeBinary(n, profile, 136, tag)
}
func (wac *Conn) UpdateProfileName(name string) (<-chan string, error) {
tag := fmt.Sprintf("%d.--%d", time.Now().Unix(), wac.msgCount*19)
n := binary.Node{
Description: "action",
Attributes: map[string]string{
"type": "set",
"epoch": strconv.Itoa(wac.msgCount),
},
Content: []interface{}{
binary.Node{
Description: "profile",
Attributes: map[string]string{
"name": name,
},
Content: []binary.Node{},
},
},
}
return wac.writeBinary(n, profile, ignore, tag)
}

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
"github.com/Rhymen/go-whatsapp/binary"
@@ -82,10 +83,8 @@ func (wac *Conn) processReadData(msgType int, msg []byte) error {
// chan string to something like chan map[string]interface{}. The unmarshalling
// in several places, especially in session.go, would then be gone.
listener <- data[1]
wac.listener.Lock()
delete(wac.listener.m, data[0])
wac.listener.Unlock()
close(listener)
wac.removeListener(data[0])
} else if msgType == websocket.BinaryMessage {
wac.loginSessionLock.RLock()
sess := wac.session
@@ -111,16 +110,16 @@ func (wac *Conn) decryptBinaryMessage(msg []byte) (*binary.Node, error) {
var response struct {
Status int `json:"status"`
}
err := json.Unmarshal(msg, &response)
if err == nil {
if response.Status == 404 {
if err := json.Unmarshal(msg, &response); err == nil {
if response.Status == http.StatusNotFound {
return nil, ErrServerRespondedWith404
}
return nil, errors.New(fmt.Sprintf("server responded with %d", response.Status))
} else {
return nil, ErrInvalidServerResponse
}
return nil, ErrInvalidServerResponse
}
h2.Write([]byte(msg[32:]))
if !hmac.Equal(h2.Sum(nil), msg[:32]) {

View File

@@ -18,7 +18,7 @@ import (
)
//represents the WhatsAppWeb client version
var waVersion = []int{2, 2039, 9}
var waVersion = []int{2, 2121, 6}
/*
Session contains session individual information. To be able to resume the connection without scanning the qr code

View File

@@ -15,15 +15,30 @@ import (
"github.com/pkg/errors"
)
func (wac *Conn) addListener(ch chan string, messageTag string) {
wac.listener.Lock()
wac.listener.m[messageTag] = ch
wac.listener.Unlock()
}
func (wac *Conn) removeListener(answerMessageTag string) {
wac.listener.Lock()
delete(wac.listener.m, answerMessageTag)
wac.listener.Unlock()
}
//writeJson enqueues a json message into the writeChan
func (wac *Conn) writeJson(data []interface{}) (<-chan string, error) {
ch := make(chan string, 1)
wac.writerLock.Lock()
defer wac.writerLock.Unlock()
d, err := json.Marshal(data)
if err != nil {
return nil, err
close(ch)
return ch, err
}
ts := time.Now().Unix()
@@ -35,9 +50,13 @@ func (wac *Conn) writeJson(data []interface{}) (<-chan string, error) {
wac.timeTag = tss[len(tss)-3:]
}
ch, err := wac.write(websocket.TextMessage, messageTag, bytes)
wac.addListener(ch, messageTag)
err = wac.write(websocket.TextMessage, bytes)
if err != nil {
return nil, err
close(ch)
wac.removeListener(messageTag)
return ch, err
}
wac.msgCount++
@@ -45,8 +64,12 @@ func (wac *Conn) writeJson(data []interface{}) (<-chan string, error) {
}
func (wac *Conn) writeBinary(node binary.Node, metric metric, flag flag, messageTag string) (<-chan string, error) {
ch := make(chan string, 1)
if len(messageTag) < 2 {
return nil, ErrMissingMessageTag
close(ch)
return ch, ErrMissingMessageTag
}
wac.writerLock.Lock()
@@ -54,16 +77,21 @@ func (wac *Conn) writeBinary(node binary.Node, metric metric, flag flag, message
data, err := wac.encryptBinaryMessage(node)
if err != nil {
return nil, errors.Wrap(err, "encryptBinaryMessage(node) failed")
close(ch)
return ch, errors.Wrap(err, "encryptBinaryMessage(node) failed")
}
bytes := []byte(messageTag + ",")
bytes = append(bytes, byte(metric), byte(flag))
bytes = append(bytes, data...)
ch, err := wac.write(websocket.BinaryMessage, messageTag, bytes)
wac.addListener(ch, messageTag)
err = wac.write(websocket.BinaryMessage, bytes)
if err != nil {
return nil, errors.Wrap(err, "failed to write message")
close(ch)
wac.removeListener(messageTag)
return ch, errors.Wrap(err, "failed to write message")
}
wac.msgCount++
@@ -71,9 +99,15 @@ func (wac *Conn) writeBinary(node binary.Node, metric metric, flag flag, message
}
func (wac *Conn) sendKeepAlive() error {
respChan := make(chan string, 1)
wac.addListener(respChan, "!")
bytes := []byte("?,,")
respChan, err := wac.write(websocket.TextMessage, "!", bytes)
err := wac.write(websocket.TextMessage, bytes)
if err != nil {
close(respChan)
wac.removeListener("!")
return errors.Wrap(err, "error sending keepAlive")
}
@@ -122,32 +156,21 @@ func (wac *Conn) sendAdminTest() (bool, error) {
}
}
func (wac *Conn) write(messageType int, answerMessageTag string, data []byte) (<-chan string, error) {
var ch chan string
if answerMessageTag != "" {
ch = make(chan string, 1)
wac.listener.Lock()
wac.listener.m[answerMessageTag] = ch
wac.listener.Unlock()
}
func (wac *Conn) write(messageType int, data []byte) error {
if wac == nil || wac.ws == nil {
return nil, ErrInvalidWebsocket
return ErrInvalidWebsocket
}
wac.ws.Lock()
err := wac.ws.conn.WriteMessage(messageType, data)
wac.ws.Unlock()
if err != nil {
if answerMessageTag != "" {
wac.listener.Lock()
delete(wac.listener.m, answerMessageTag)
wac.listener.Unlock()
}
return nil, errors.Wrap(err, "error writing to websocket")
return errors.Wrap(err, "error writing to websocket")
}
return ch, nil
return nil
}
func (wac *Conn) encryptBinaryMessage(node binary.Node) (data []byte, err error) {

5
vendor/github.com/SevereCloud/vksdk/v2/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,5 @@
_vendor/
vendor/
*.out
coverage.txt
*.test

102
vendor/github.com/SevereCloud/vksdk/v2/.golangci.yml generated vendored Normal file
View File

@@ -0,0 +1,102 @@
---
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- errcheck
- gochecknoglobals
- goconst
- gocritic
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- wsl
- godot
- asciicheck
- nolintlint
- gofumpt
- goerr113
- tparallel
- errorlint
- paralleltest
- forbidigo
- makezero
- thelper
- predeclared
- ifshort
- revive
- durationcheck
- gomoddirectives
- importas
- nilerr
- revive
- wastedassign
# - wrapcheck # TODO: v3 Fix
# - testpackage # TODO: Fix testpackage
# - nestif # TODO: Fix nestif
# - noctx # TODO: Fix noctx
# don't enable:
# - depguard
# - dogsled
# - dupl
# - funlen
# - gochecknoinits
# - gocognit
# - gocyclo
# - godox
# - gomnd
# - lll
# - rowserrcheck
# - scopelint
# - gomodguard
# - exhaustive
# - nlreturn
# - gci
# - exhaustivestruct
# - cyclop
# - promlinter
# - tagliatelle
# depricated
# - maligned
# - interfacer
# - golint
issues:
exclude-rules:
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- linters:
- errcheck
source: ".((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|
.*printf?|os\\.(Un)?Setenv)."
- linters:
- stylecheck
text: "ST1003:.*(Ts|ts).*TS"
exclude-use-default: false

View File

@@ -0,0 +1,2 @@
---
no-hard-tabs: false

20
vendor/github.com/SevereCloud/vksdk/v2/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,20 @@
---
language: go
cache:
directories:
- $HOME/.cache/go-build
- $HOME/gopath/pkg/mod
go:
- 1.x
before_script:
- git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- git describe --tags $(git rev-list --tags --max-count=1) --always
script:
- go test -v -race -coverprofile=coverage.txt -covermode=atomic -p=1 ./...
after_success:
- bash <(curl -s https://codecov.io/bash)

92
vendor/github.com/SevereCloud/vksdk/v2/CONTRIBUTING.md generated vendored Normal file
View File

@@ -0,0 +1,92 @@
# Contributing
## Настройки
`vksdk` написан на [Go](https://golang.org/).
Требования:
- [Go 1.13+](https://golang.org/doc/install)
- [golangci-lint](https://github.com/golangci/golangci-lint)
- [global .gitignore](https://help.github.com/en/articles/ignoring-files#create-a-global-gitignore)
Сделайте fork и клонируйте `vksdk` куда угодно:
```sh
git clone git@github.com:<your name>/vksdk.git
```
Создайте новую ветку
```sh
git checkout -b <name_of_your_new_branch>
```
## Тестирование изменений
Для начала проверьте ваш код с помощью
[golangci-lint](https://github.com/golangci/golangci-lint)
```sh
golangci-lint run
```
Затем можно запускать тесты
```sh
# SERVICE_TOKEN=""
# GROUP_TOKEN=""
# CLIENT_SECRET=""
# USER_TOKEN=""
# WIDGET_TOKEN=""
# CLIENT_ID="123456"
# GROUP_ID="123456"
# ACCOUNT_ID="123456"
go test ./...
```
Задавать токены не обязательно - тесты с их использованием будут пропущены.
**Не** рекомендуется задавать свой `USER_TOKEN`, так как тесты делают много
страшных вещей.
Настройки для VSCode `.vscode/setting.json`
```json
{
"go.testEnvVars": {
"SERVICE_TOKEN": "",
"WIDGET_TOKEN": "",
"GROUP_TOKEN": "",
"CLIENT_SECRET": "",
"USER_TOKEN": "",
"CLIENT_ID": "123456",
"GROUP_ID": "123456",
"ACCOUNT_ID": "123456"
}
}
```
## Создание коммита
Сообщения коммитов должны быть хорошо отформатированы, и чтобы сделать их
«стандартизированным», мы используем
[Conventional Commits](https://www.conventionalcommits.org/ru).
```sh
git add .
git commit
```
## Отправьте pull request
Отправьте изменения в ваш репозиторий
```sh
git push origin <name_of_your_new_branch>
```
Затем откройте [pull request](https://github.com/SevereCloud/vksdk/pulls)
с веткой:
- `master` если это багфикс
- `dev-v1.2.3` если это новая фича

21
vendor/github.com/SevereCloud/vksdk/v2/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2020 Daniil Suvorov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

125
vendor/github.com/SevereCloud/vksdk/v2/README.md generated vendored Normal file
View File

@@ -0,0 +1,125 @@
# VK SDK for Golang
[![Build Status](https://travis-ci.com/SevereCloud/vksdk.svg?branch=master)](https://travis-ci.com/SevereCloud/vksdk)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/SevereCloud/vksdk/v2/v2)](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2?tab=subdirectories)
[![VK Developers](https://img.shields.io/badge/developers-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.com/dev/)
[![codecov](https://codecov.io/gh/SevereCloud/vksdk/branch/master/graph/badge.svg)](https://codecov.io/gh/SevereCloud/vksdk)
[![VK chat](https://img.shields.io/badge/VK%20chat-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.me/join/AJQ1d6Or8Q00Y_CSOESfbqGt)
[![release](https://img.shields.io/github/v/tag/SevereCloud/vksdk?label=release)](https://github.com/SevereCloud/vksdk/releases)
[![license](https://img.shields.io/github/license/SevereCloud/vksdk.svg?maxAge=2592000)](https://github.com/SevereCloud/vksdk/blob/master/LICENSE)
**VK SDK for Golang** ready implementation of the main VK API functions for Go.
[Russian documentation](https://github.com/SevereCloud/vksdk/wiki)
## Features
Version API 5.131.
- [API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/api)
- 400+ methods
- Ability to change the request handler
- Ability to modify HTTP client
- Request Limiter
- Token pool
- [Callback API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/callback)
- Tracking tool for users activity in your VK communities
- Supports all events
- Auto setting callback
- [Bots Long Poll API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/longpoll-bot)
- Allows you to work with community events in real time
- Supports all events
- Ability to modify HTTP client
- [User Long Poll API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/longpoll-user)
- Allows you to work with user events in real time
- Ability to modify HTTP client
- [Streaming API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/streaming)
- Receiving public data from VK by specified keywords
- Ability to modify HTTP client
- [FOAF](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/foaf)
- Machine-readable ontology describing persons
- Works with users and groups
- The only place to get page creation date
- [Games](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/games)
- Checking launch parameters
- Intermediate http handler
- [VK Mini Apps](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/vkapps)
- Checking launch parameters
- Intermediate http handler
- [Payments API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/payments)
- Processes payment notifications
- [Marusia Skills](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/marusia)
- For creating Marusia Skills
- Support SSML
## Install
```bash
# go mod init mymodulename
go get github.com/SevereCloud/vksdk/v2@latest
```
## Use by
- [Joe](https://github.com/go-joe/joe) adapter: <https://github.com/tdakkota/joe-vk-adapter>
- [Logrus](https://github.com/sirupsen/logrus) hook: <https://github.com/SevereCloud/vkrus>
### Example
```go
package main
import (
"context"
"log"
"github.com/SevereCloud/vksdk/v2/api"
"github.com/SevereCloud/vksdk/v2/api/params"
"github.com/SevereCloud/vksdk/v2/events"
"github.com/SevereCloud/vksdk/v2/longpoll-bot"
)
func main() {
token := "<TOKEN>" // use os.Getenv("TOKEN")
vk := api.NewVK(token)
// get information about the group
group, err := vk.GroupsGetByID(nil)
if err != nil {
log.Fatal(err)
}
// Initializing Long Poll
lp, err := longpoll.NewLongPoll(vk, group[0].ID)
if err != nil {
log.Fatal(err)
}
// New message event
lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
log.Printf("%d: %s", obj.Message.PeerID, obj.Message.Text)
if obj.Message.Text == "ping" {
b := params.NewMessagesSendBuilder()
b.Message("pong")
b.RandomID(0)
b.PeerID(obj.Message.PeerID)
_, err := vk.MessagesSend(b.Params)
if err != nil {
log.Fatal(err)
}
}
})
// Run Bots Long Poll
log.Println("Start Long Poll")
if err := lp.Run(); err != nil {
log.Fatal(err)
}
}
```
## LICENSE
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FSevereCloud%2Fvksdk.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FSevereCloud%2Fvksdk?ref=badge_large)

555
vendor/github.com/SevereCloud/vksdk/v2/api/README.md generated vendored Normal file
View File

@@ -0,0 +1,555 @@
# API
[![PkgGoDev](https://pkg.go.dev/badge/github.com/SevereCloud/vksdk/v2/api)](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/api)
[![VK](https://img.shields.io/badge/developers-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.com/dev/first_guide)
Данная библиотека поддерживает версию API **5.122**.
## Запросы
В начале необходимо инициализировать api с помощью [ключа доступа](https://vk.com/dev/access_token):
```go
vk := api.NewVK("<TOKEN>")
```
### Запросы к API
- `users.get` -> `vk.UsersGet(api.Params{})`
- `groups.get` с extended=1 -> `vk.GroupsGetExtended(api.Params{})`
Список всех методов можно найти на
[данной странице](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/api?tab=doc#VK).
Пример запроса [`users.get`](https://vk.com/dev/users.get)
```go
users, err := vk.UsersGet(api.Params{
"user_ids": 1,
})
if err != nil {
log.Fatal(err)
}
```
### Параметры
[![PkgGoDev](https://pkg.go.dev/badge/github.com/SevereCloud/vksdk/v2/api/params)](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/api/params)
Модуль params предназначен для генерации параметров запроса.
```go
// import "github.com/SevereCloud/vksdk/v2/api/params"
b := params.NewMessageSendBuilder()
b.PeerID(123)
b.Random(0)
b.DontParseLinks(false)
b.Message("Test message")
res, err = api.MessageSend(b.Params)
```
### Обработка ошибок
[![VK](https://img.shields.io/badge/developers-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.com/dev/errors)
Обработка ошибок полностью поддерживает методы
[go 1.13](https://blog.golang.org/go1.13-errors)
```go
if errors.Is(err, api.ErrAuth) {
log.Println("User authorization failed")
}
```
```go
var e *api.Error
if errors.As(err, &e) {
switch e.Code {
case api.ErrCaptcha:
log.Println("Требуется ввод кода с картинки (Captcha)")
log.Printf("sid %s img %s", e.CaptchaSID, e.CaptchaImg)
case 1:
log.Println("Код ошибки 1")
default:
log.Printf("Ошибка %d %s", e.Code, e.Text)
}
}
```
Для Execute существует отдельная ошибка `ExecuteErrors`
### Запрос любого метода
Пример запроса [users.get](https://vk.com/dev/users.get)
```go
// Определяем структуру, которую вернет API
var response []object.UsersUser
var err api.Error
params := api.Params{
"user_ids": 1,
}
// Делаем запрос
err = vk.RequestUnmarshal("users.get", &response, params)
if err != nil {
log.Fatal(err)
}
log.Print(response)
```
### Execute
[![PkgGoDev](https://pkg.go.dev/badge/github.com/SevereCloud/vksdk/v2/errors)](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/api#VK.Execute)
[![VK](https://img.shields.io/badge/developers-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.com/dev/execute)
Универсальный метод, который позволяет запускать последовательность других
методов, сохраняя и фильтруя промежуточные результаты.
```go
var response struct {
Text string `json:"text"`
}
err = vk.Execute(`return {text: "hello"};`, &response)
if err != nil {
log.Fatal(err)
}
log.Print(response.Text)
```
### Обработчик запросов
Обработчик `vk.Handler` должен возвращать структуру ответа от VK API и ошибку.
В качестве параметров принимать название метода и параметры.
```go
vk.Handler = func(method string, params ...api.Params) (api.Response, error) {
// ...
}
```
Это может потребоваться, если вы можете поставить свой обработчик с
[fasthttp](https://github.com/valyala/fasthttp) и логгером.
Стандартный обработчик использует [encoding/json](https://pkg.go.dev/net/http)
и [net/http](https://pkg.go.dev/net/http). В стандартном обработчике можно
настроить ограничитель запросов и HTTP клиент.
#### Ограничитель запросов
К методам API ВКонтакте (за исключением методов из секций secure и ads) с
ключом доступа пользователя или сервисным ключом доступа можно обращаться не
чаще 3 раз в секунду. Для ключа доступа сообщества ограничение составляет 20
запросов в секунду. Если логика Вашего приложения подразумевает вызов
нескольких методов подряд, имеет смысл обратить внимание на метод execute. Он
позволяет совершить до 25 обращений к разным методам в рамках одного запроса.
Для методов секции ads действуют собственные ограничения, ознакомиться с ними
Вы можете на [этой странице](https://vk.com/dev/ads_limits).
Максимальное число обращений к методам секции secure зависит от числа
пользователей, установивших приложение. Если приложение установило меньше 10
000 человек, то можно совершать 5 запросов в секунду, до 100 000 — 8 запросов,
до 1 000 000 — 20 запросов, больше 1 млн. — 35 запросов в секунду.
Если Вы превысите частотное ограничение, сервер вернет ошибку с кодом
**6: "Too many requests per second."**.
С помощью параметра `vk.Limit` можно установить ограничение на определенное
количество запросов в секунду
### HTTP client
В модуле реализована возможность изменять HTTP клиент с помощью параметра
`vk.Client`
Пример прокси
```go
dialer, _ := proxy.SOCKS5("tcp", "127.0.0.1:9050", nil, proxy.Direct)
httpTransport := &http.Transport{
Dial: dialer.Dial,
}
httpTransport.Dial = dialer.Dial
client := &http.Client{
Transport: httpTransport,
}
vk.Client = client
```
### Ошибка с Captcha
[![VK](https://img.shields.io/badge/developers-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.com/dev/captcha_error)
Если какое-либо действие (например, отправка сообщения) выполняется
пользователем слишком часто, то запрос к API может возвращать ошибку
"Captcha needed". При этом пользователю понадобится ввести код с изображения
и отправить запрос повторно с передачей введенного кода Captcha в параметрах
запроса.
**Код ошибки**: 14
**Текст ошибки**: Captcha needed
Если возникает данная ошибка, то в сообщении об ошибке передаются также
следующие параметры:
- `err.CaptchaSID` - идентификатор captcha
- `err.CaptchaImg` - ссылка на изображение, которое нужно показать
пользователю, чтобы он ввел текст с этого изображения.
В этом случае следует запросить пользователя ввести текст с изображения
`err.CaptchaImg` и повторить запрос, добавив в него параметры:
- `captcha_sid` - полученный идентификатор
- `captcha_key` - текст, который ввел пользователь
## Загрузка файлов
[![VK](https://img.shields.io/badge/developers-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.com/dev/upload_files)
### 1. Загрузка фотографий в альбом
Допустимые форматы: JPG, PNG, GIF.
Файл объемом не более 50 МБ, соотношение сторон не менее 1:20
Загрузка фотографий в альбом для текущего пользователя:
```go
photosPhoto, err = vk.UploadPhoto(albumID, response.Body)
```
Загрузка фотографий в альбом для группы:
```go
photosPhoto, err = vk.UploadPhotoGroup(groupID, albumID, response.Body)
```
### 2. Загрузка фотографий на стену
Допустимые форматы: JPG, PNG, GIF.
Файл объемом не более 50 МБ, соотношение сторон не менее 1:20
```go
photosPhoto, err = vk.UploadWallPhoto(response.Body)
```
Загрузка фотографий в альбом для группы:
```go
photosPhoto, err = vk.UploadWallPhotoGroup(groupID, response.Body)
```
### 3. Загрузка главной фотографии пользователя или сообщества
Допустимые форматы: JPG, PNG, GIF.
Ограничения: размер не менее 200x200px, соотношение сторон от 0.25 до 3,
сумма высоты и ширины не более 14000px, файл объемом не более 50 МБ,
соотношение сторон не менее 1:20.
Загрузка главной фотографии пользователя
```go
photosPhoto, err = vk.UploadUserPhoto(file)
```
Загрузка фотографии пользователя или сообщества с миниатюрой
```go
photosPhoto, err = vk.UploadOwnerPhoto(ownerID, squareСrop,file)
```
Для загрузки главной фотографии сообщества необходимо передать его идентификатор
со знаком «минус» в параметре `ownerID`.
Дополнительно Вы можете передать параметр `squareСrop` в формате "x,y,w" (без
кавычек), где x и y — координаты верхнего правого угла миниатюры, а w — сторона
квадрата. Тогда для фотографии также будет подготовлена квадратная миниатюра.
Загрузка фотографии пользователя или сообщества без миниатюры:
```go
photosPhoto, err = vk.UploadOwnerPhoto(ownerID, "", file)
```
### 4. Загрузка фотографии в личное сообщение
Допустимые форматы: JPG, PNG, GIF.
Ограничения: сумма высоты и ширины не более 14000px, файл объемом
не более 50 МБ, соотношение сторон не менее 1:20.
```go
photosPhoto, err = vk.UploadMessagesPhoto(peerID, file)
```
### 5. Загрузка главной фотографии для чата
Допустимые форматы: JPG, PNG, GIF.
Ограничения: размер не менее 200x200px, соотношение сторон от 0.25 до 3, сумма
высоты и ширины не более 14000px, файл объемом не более 50 МБ, соотношение
сторон не менее 1:20.
Без обрезки:
```go
messageInfo, err = vk.UploadChatPhoto(peerID, file)
```
С обрезкой:
```go
messageInfo, err = vk.UploadChatPhotoCrop(peerID, cropX, cropY, cropWidth, file)
```
### 6. Загрузка фотографии для товара
Допустимые форматы: JPG, PNG, GIF.
Ограничения: минимальный размер фото — 400x400px, сумма высоты и ширины
не более 14000px, файл объемом не более 50 МБ, соотношение сторон не менее 1:20.
Если Вы хотите загрузить основную фотографию товара, необходимо передать
параметр `mainPhoto = true`. Если фотография не основная, она не будет обрезаться.
Без обрезки:
```go
photosPhoto, err = vk.UploadMarketPhoto(groupID, mainPhoto, file)
```
Основную фотографию с обрезкой:
```go
photosPhoto, err = vk.UploadMarketPhotoCrop(groupID, cropX, cropY, cropWidth, file)
```
### 7. Загрузка фотографии для подборки товаров
Допустимые форматы: JPG, PNG, GIF.
Ограничения: минимальный размер фото — 1280x720px, сумма высоты и ширины
не более 14000px, файл объемом не более 50 МБ, соотношение сторон не менее 1:20.
```go
photosPhoto, err = vk.UploadMarketAlbumPhoto(groupID, file)
```
### 9. Загрузка видеозаписей
Допустимые форматы: AVI, MP4, 3GP, MPEG, MOV, MP3, FLV, WMV.
[Параметры](https://vk.com/dev/video.save)
```go
videoUploadResponse, err = vk.UploadVideo(params, file)
```
После загрузки видеозапись проходит обработку и в списке видеозаписей может
появиться спустя некоторое время.
### 10. Загрузка документов
Допустимые форматы: любые форматы за исключением mp3 и исполняемых файлов.
Ограничения: файл объемом не более 200 МБ.
`title` - название файла с расширением
`tags` - метки для поиска
`typeDoc` - тип документа.
- doc - обычный документ;
- audio_message - голосовое сообщение
Загрузить документ:
```go
docsDoc, err = vk.UploadDoc(title, tags, file)
```
Загрузить документ в группу:
```go
docsDoc, err = vk.UploadGroupDoc(groupID, title, tags, file)
```
Загрузить документ, для последующей отправки документа на стену:
```go
docsDoc, err = vk.UploadWallDoc(title, tags, file)
```
Загрузить документ в группу, для последующей отправки документа на стену:
```go
docsDoc, err = vk.UploadGroupWallDoc(groupID, title, tags, file)
```
Загрузить документ в личное сообщение:
```go
docsDoc, err = vk.UploadMessagesDoc(peerID, typeDoc, title, tags, file)
```
### 11. Загрузка обложки сообщества
Допустимые форматы: JPG, PNG, GIF.
Ограничения: минимальный размер фото — 795x200px, сумма высоты и ширины
не более 14000px, файл объемом не более 50 МБ. Рекомендуемый размер: 1590x400px.
В сутки можно загрузить не более 1500 обложек.
Необходимо указать координаты обрезки фотографии в параметрах
`cropX`, `cropY`, `cropX2`, `cropY2`.
```go
photo, err = vk.UploadOwnerCoverPhoto(groupID, cropX, cropY, cropX2, cropY2, file)
```
### 12. Загрузка аудиосообщения
Допустимые форматы: Ogg Opus.
Ограничения: sample rate 16kHz, variable bitrate 16 kbit/s, длительность
не более 5 минут.
```go
docsDoc, err = vk.UploadMessagesDoc(peerID, "audio_message", title, tags, file)
```
### 13. Загрузка истории
Допустимые форматы: JPG, PNG, GIF.
Ограничения: сумма высоты и ширины не более 14000px, файл объемом
не более 10МБ. Формат видео: h264 video, aac audio,
максимальное разрешение 720х1280, 30fps.
Загрузить историю с фотографией. [Параметры](https://vk.com/dev/stories.getPhotoUploadServer)
```go
uploadInfo, err = vk.UploadStoriesPhoto(params, file)
```
Загрузить историю с видео. [Параметры](https://vk.com/dev/stories.getVideoUploadServer)
```go
uploadInfo, err = vk.UploadStoriesVideo(params, file)
```
### Загрузка фоновой фотографии в опрос
Допустимые форматы: JPG, PNG, GIF.
Ограничения: сумма высоты и ширины не более 14000px, файл объемом не более 50 МБ,
соотношение сторон не менее 1:20.
```go
photosPhoto, err = vk.UploadPollsPhoto(file)
```
```go
photosPhoto, err = vk.UploadOwnerPollsPhoto(ownerID, file)
```
Для загрузки фотографии сообщества необходимо передать его идентификатор со
знаком «минус» в параметре `ownerID`.
### Загрузка фотографии для карточки
Для карточек используются квадратные изображения минимальным размером 400х400.
В случае загрузки неквадратного изображения, оно будет обрезано до квадратного.
Допустимые форматы: JPG, PNG, BMP, TIFF или GIF.
Ограничения: файл объемом не более 5 МБ.
```go
photo, err = vk.UploadPrettyCardsPhoto(file)
```
### Загрузка обложки для формы
Для форм сбора заявок используются прямоугольные изображения размером 1200х300.
В случае загрузки изображения другого размера, оно будет автоматически обрезано
до требуемого.
Допустимые форматы: JPG, PNG, BMP, TIFF или GIF.
Ограничения: файл объемом не более 5 МБ.
```go
photo, err = vk.UploadLeadFormsPhoto(file)
```
Полученные данные можно использовать в методах
[leadForms.create](https://vk.com/dev/leadForms.create)
и
[leadForms.edit](https://vk.com/dev/leadForms.edit).
Полученные данные можно использовать в методах
[prettyCards.create](https://vk.com/dev/prettyCards.create)
и
[prettyCards.edit](https://vk.com/dev/prettyCards.edit).
### Загрузки фотографии в коллекцию приложения для виджетов приложений сообществ
`imageType` (string) - тип изображения.
Возможные значения:
- 24x24
- 50x50
- 160x160
- 160x240
- 510x128
```go
image, err = vk.UploadAppImage(imageType, file)
```
### Загрузки фотографии в коллекцию сообщества для виджетов приложений сообществ
`imageType` (string) - тип изображения.
Возможные значения:
- 24x24
- 50x50
- 160x160
- 160x240
- 510x128
```go
image, err = vk.UploadGroupAppImage(imageType, file)
```
#### Примеры
Загрузка фотографии в альбом:
```go
response, err := os.Open("photo.jpeg")
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
photo, err = vk.UploadPhoto(albumID, response.Body)
if err != nil {
log.Fatal(err)
}
```
Загрузка фотографии в альбом из интернета:
```go
response, err := http.Get("https://sun9-45.userapi.com/c638629/v638629852/2afba/o-dvykjSIB4.jpg")
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
photo, err = vk.UploadPhoto(albumID, response.Body)
if err != nil {
log.Fatal(err)
}
```

196
vendor/github.com/SevereCloud/vksdk/v2/api/account.go generated vendored Normal file
View File

@@ -0,0 +1,196 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// AccountBan account.ban.
//
// https://vk.com/dev/account.ban
func (vk *VK) AccountBan(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.ban", &response, params)
return
}
// AccountChangePasswordResponse struct.
type AccountChangePasswordResponse struct {
Token string `json:"token"`
}
// AccountChangePassword changes a user password after access is successfully restored with the auth.restore method.
//
// https://vk.com/dev/account.changePassword
func (vk *VK) AccountChangePassword(params Params) (response AccountChangePasswordResponse, err error) {
err = vk.RequestUnmarshal("account.changePassword", &response, params)
return
}
// AccountGetActiveOffersResponse struct.
type AccountGetActiveOffersResponse struct {
Count int `json:"count"`
Items []object.AccountOffer `json:"items"`
}
// AccountGetActiveOffers returns a list of active ads (offers).
// If the user fulfill their conditions, he will be able to get
// the appropriate number of votes to his balance.
//
// https://vk.com/dev/account.getActiveOffers
func (vk *VK) AccountGetActiveOffers(params Params) (response AccountGetActiveOffersResponse, err error) {
err = vk.RequestUnmarshal("account.getActiveOffers", &response, params)
return
}
// AccountGetAppPermissions gets settings of the user in this application.
//
// https://vk.com/dev/account.getAppPermissions
func (vk *VK) AccountGetAppPermissions(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.getAppPermissions", &response, params)
return
}
// AccountGetBannedResponse struct.
type AccountGetBannedResponse struct {
Count int `json:"count"`
Items []int `json:"items"`
object.ExtendedResponse
}
// AccountGetBanned returns a user's blacklist.
//
// https://vk.com/dev/account.getBanned
func (vk *VK) AccountGetBanned(params Params) (response AccountGetBannedResponse, err error) {
err = vk.RequestUnmarshal("account.getBanned", &response, params)
return
}
// AccountGetCountersResponse struct.
type AccountGetCountersResponse object.AccountAccountCounters
// AccountGetCounters returns non-null values of user counters.
//
// https://vk.com/dev/account.getCounters
func (vk *VK) AccountGetCounters(params Params) (response AccountGetCountersResponse, err error) {
err = vk.RequestUnmarshal("account.getCounters", &response, params)
return
}
// AccountGetInfoResponse struct.
type AccountGetInfoResponse object.AccountInfo
// AccountGetInfo returns current account info.
//
// https://vk.com/dev/account.getInfo
func (vk *VK) AccountGetInfo(params Params) (response AccountGetInfoResponse, err error) {
err = vk.RequestUnmarshal("account.getInfo", &response, params)
return
}
// AccountGetProfileInfoResponse struct.
type AccountGetProfileInfoResponse object.AccountUserSettings
// AccountGetProfileInfo returns the current account info.
//
// https://vk.com/dev/account.getProfileInfo
func (vk *VK) AccountGetProfileInfo(params Params) (response AccountGetProfileInfoResponse, err error) {
err = vk.RequestUnmarshal("account.getProfileInfo", &response, params)
return
}
// AccountGetPushSettingsResponse struct.
type AccountGetPushSettingsResponse object.AccountPushSettings
// AccountGetPushSettings account.getPushSettings Gets settings of push notifications.
//
// https://vk.com/dev/account.getPushSettings
func (vk *VK) AccountGetPushSettings(params Params) (response AccountGetPushSettingsResponse, err error) {
err = vk.RequestUnmarshal("account.getPushSettings", &response, params)
return
}
// AccountRegisterDevice subscribes an iOS/Android/Windows/Mac based device to receive push notifications.
//
// https://vk.com/dev/account.registerDevice
func (vk *VK) AccountRegisterDevice(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.registerDevice", &response, params)
return
}
// AccountSaveProfileInfoResponse struct.
type AccountSaveProfileInfoResponse struct {
Changed object.BaseBoolInt `json:"changed"`
NameRequest object.AccountNameRequest `json:"name_request"`
}
// AccountSaveProfileInfo edits current profile info.
//
// https://vk.com/dev/account.saveProfileInfo
func (vk *VK) AccountSaveProfileInfo(params Params) (response AccountSaveProfileInfoResponse, err error) {
err = vk.RequestUnmarshal("account.saveProfileInfo", &response, params)
return
}
// AccountSetInfo allows to edit the current account info.
//
// https://vk.com/dev/account.setInfo
func (vk *VK) AccountSetInfo(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.setInfo", &response, params)
return
}
// AccountSetNameInMenu sets an application screen name
// (up to 17 characters), that is shown to the user in the left menu.
//
// https://vk.com/dev/account.setNameInMenu
func (vk *VK) AccountSetNameInMenu(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.setNameInMenu", &response, params)
return
}
// AccountSetOffline marks a current user as offline.
//
// https://vk.com/dev/account.setOffline
func (vk *VK) AccountSetOffline(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.setOffline", &response, params)
return
}
// AccountSetOnline marks the current user as online for 5 minutes.
//
// https://vk.com/dev/account.setOnline
func (vk *VK) AccountSetOnline(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.setOnline", &response, params)
return
}
// AccountSetPushSettings change push settings.
//
// https://vk.com/dev/account.setPushSettings
func (vk *VK) AccountSetPushSettings(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.setPushSettings", &response, params)
return
}
// AccountSetSilenceMode mutes push notifications for the set period of time.
//
// https://vk.com/dev/account.setSilenceMode
func (vk *VK) AccountSetSilenceMode(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.setSilenceMode", &response, params)
return
}
// AccountUnban account.unban.
//
// https://vk.com/dev/account.unban
func (vk *VK) AccountUnban(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.unban", &response, params)
return
}
// AccountUnregisterDevice unsubscribes a device from push notifications.
//
// https://vk.com/dev/account.unregisterDevice
func (vk *VK) AccountUnregisterDevice(params Params) (response int, err error) {
err = vk.RequestUnmarshal("account.unregisterDevice", &response, params)
return
}

581
vendor/github.com/SevereCloud/vksdk/v2/api/ads.go generated vendored Normal file
View File

@@ -0,0 +1,581 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"encoding/json"
"github.com/SevereCloud/vksdk/v2/object"
)
// AdsAddOfficeUsersItem struct.
type AdsAddOfficeUsersItem struct {
OK object.BaseBoolInt
Error AdsError
}
// UnmarshalJSON func.
func (r *AdsAddOfficeUsersItem) UnmarshalJSON(data []byte) (err error) {
if r.OK.UnmarshalJSON(data) != nil {
return json.Unmarshal(data, &r.Error)
}
return
}
// AdsAddOfficeUsersResponse struct.
type AdsAddOfficeUsersResponse []AdsAddOfficeUsersItem
// AdsAddOfficeUsers adds managers and/or supervisors to advertising account.
//
// https://vk.com/dev/ads.addOfficeUsers
func (vk *VK) AdsAddOfficeUsers(params Params) (response AdsAddOfficeUsersResponse, err error) {
err = vk.RequestUnmarshal("ads.addOfficeUsers", &response, params)
return
}
// AdsCheckLinkResponse struct.
type AdsCheckLinkResponse struct {
// link status
Status object.AdsLinkStatus `json:"status"`
// (if status = disallowed) — description of the reason
Description string `json:"description,omitempty"`
// (if the end link differs from original and status = allowed) — end link.
RedirectURL string `json:"redirect_url,omitempty"`
}
// AdsCheckLink allows to check the ad link.
//
// https://vk.com/dev/ads.checkLink
func (vk *VK) AdsCheckLink(params Params) (response AdsCheckLinkResponse, err error) {
err = vk.RequestUnmarshal("ads.checkLink", &response, params)
return
}
// AdsCreateAdsResponse struct.
type AdsCreateAdsResponse []struct {
ID int `json:"id"`
AdsError
}
// AdsCreateAds creates ads.
//
// Please note! Maximum allowed number of ads created in one request is 5.
// Minimum size of ad audience is 50 people.
//
// https://vk.com/dev/ads.createAds
func (vk *VK) AdsCreateAds(params Params) (response AdsCreateAdsResponse, err error) {
err = vk.RequestUnmarshal("ads.createAds", &response, params)
return
}
// AdsCreateCampaignsResponse struct.
type AdsCreateCampaignsResponse []struct {
ID int `json:"id"`
AdsError
}
// AdsCreateCampaigns creates advertising campaigns.
//
// Please note! Allowed number of campaigns created in one request is 50.
//
// https://vk.com/dev/ads.createCampaigns
func (vk *VK) AdsCreateCampaigns(params Params) (response AdsCreateCampaignsResponse, err error) {
err = vk.RequestUnmarshal("ads.createCampaigns", &response, params)
return
}
// AdsCreateClientsResponse struct.
type AdsCreateClientsResponse []struct {
ID int `json:"id"`
AdsError
}
// AdsCreateClients creates clients of an advertising agency.
//
// Available only for advertising agencies.
//
// Please note! Allowed number of clients created in one request is 50.
//
// https://vk.com/dev/ads.createClients
func (vk *VK) AdsCreateClients(params Params) (response AdsCreateClientsResponse, err error) {
err = vk.RequestUnmarshal("ads.createClients", &response, params)
return
}
// AdsCreateLookalikeRequestResponse struct.
type AdsCreateLookalikeRequestResponse struct {
RequestID int `json:"request_id"`
}
// AdsCreateLookalikeRequest creates a request to find a similar audience.
//
// https://vk.com/dev/ads.createLookalikeRequest
func (vk *VK) AdsCreateLookalikeRequest(params Params) (response AdsCreateLookalikeRequestResponse, err error) {
err = vk.RequestUnmarshal("ads.createLookalikeRequest", &response, params)
return
}
// AdsCreateTargetGroupResponse struct.
type AdsCreateTargetGroupResponse struct {
ID int `json:"id"`
}
// AdsCreateTargetGroup Creates a group to re-target ads for users who visited
// advertiser's site (viewed information about the product, registered, etc.).
//
// When executed successfully this method returns user accounting code on
// advertiser's site. You shall add this code to the site page, so users
// registered in VK will be added to the created target group after they visit
// this page.
//
// Use ads.importTargetContacts method to import existing user contacts to
// the group.
//
// Please note! Maximum allowed number of groups for one advertising
// account is 100.
//
// https://vk.com/dev/ads.createTargetGroup
func (vk *VK) AdsCreateTargetGroup(params Params) (response AdsCreateTargetGroupResponse, err error) {
err = vk.RequestUnmarshal("ads.createTargetGroup", &response, params)
return
}
// AdsCreateTargetPixelResponse struct.
type AdsCreateTargetPixelResponse struct {
ID int `json:"id"`
Pixel string `json:"pixel"`
}
// AdsCreateTargetPixel Creates retargeting pixel.
//
// Method returns pixel code for users accounting on the advertiser site.
// Authorized VK users who visited the page with pixel code on it will be
// added to retargeting audience with corresponding rules. You can also use
// Open API, ads.importTargetContacts method and loading from file.
//
// Maximum pixels number per advertising account is 25.
//
// https://vk.com/dev/ads.createTargetPixel
func (vk *VK) AdsCreateTargetPixel(params Params) (response AdsCreateTargetPixelResponse, err error) {
err = vk.RequestUnmarshal("ads.createTargetPixel", &response, params)
return
}
// AdsDeleteAdsResponse struct.
//
// Each response is 0 — deleted successfully, or an error code.
type AdsDeleteAdsResponse []ErrorType
// AdsDeleteAds archives ads.
//
// Warning! Maximum allowed number of ads archived in one request is 100.
//
// https://vk.com/dev/ads.deleteAds
func (vk *VK) AdsDeleteAds(params Params) (response AdsDeleteAdsResponse, err error) {
err = vk.RequestUnmarshal("ads.deleteAds", &response, params)
return
}
// AdsDeleteCampaignsResponse struct.
//
// Each response is 0 — deleted successfully, or an error code.
type AdsDeleteCampaignsResponse []ErrorType
// AdsDeleteCampaigns archives advertising campaigns.
//
//
// Warning! Maximum allowed number of campaigns archived in one request is 100.
//
// https://vk.com/dev/ads.deleteCampaigns
func (vk *VK) AdsDeleteCampaigns(params Params) (response AdsDeleteCampaignsResponse, err error) {
err = vk.RequestUnmarshal("ads.deleteCampaigns", &response, params)
return
}
// AdsDeleteClientsResponse struct.
//
// Each response is 0 — deleted successfully, or an error code.
type AdsDeleteClientsResponse []ErrorType
// AdsDeleteClients archives clients of an advertising agency.
//
// Available only for advertising agencies.
//
// Please note! Maximum allowed number of clients edited in one request is 10.
//
// https://vk.com/dev/ads.deleteClients
func (vk *VK) AdsDeleteClients(params Params) (response AdsDeleteClientsResponse, err error) {
err = vk.RequestUnmarshal("ads.deleteClients", &response, params)
return
}
// AdsDeleteTargetGroup deletes target group.
//
// https://vk.com/dev/ads.deleteTargetGroup
func (vk *VK) AdsDeleteTargetGroup(params Params) (response int, err error) {
err = vk.RequestUnmarshal("ads.deleteTargetGroup", &response, params)
return
}
// AdsDeleteTargetPixel deletes target pixel.
//
// https://vk.com/dev/ads.deleteTargetPixel
func (vk *VK) AdsDeleteTargetPixel(params Params) (response int, err error) {
err = vk.RequestUnmarshal("ads.deleteTargetPixel", &response, params)
return
}
// AdsGetAccountsResponse struct.
type AdsGetAccountsResponse []object.AdsAccount
// AdsGetAccounts returns a list of advertising accounts.
//
// https://vk.com/dev/ads.getAccounts
func (vk *VK) AdsGetAccounts(params Params) (response AdsGetAccountsResponse, err error) {
err = vk.RequestUnmarshal("ads.getAccounts", &response, params)
return
}
// AdsGetAdsResponse struct.
type AdsGetAdsResponse []object.AdsAd
// AdsGetAds returns a list of ads.
//
// https://vk.com/dev/ads.getAds
func (vk *VK) AdsGetAds(params Params) (response AdsGetAdsResponse, err error) {
err = vk.RequestUnmarshal("ads.getAds", &response, params)
return
}
// AdsGetAdsLayoutResponse struct.
type AdsGetAdsLayoutResponse []object.AdsAdLayout
// AdsGetAdsLayout returns descriptions of ad layouts.
//
// https://vk.com/dev/ads.getAdsLayout
func (vk *VK) AdsGetAdsLayout(params Params) (response AdsGetAdsLayoutResponse, err error) {
err = vk.RequestUnmarshal("ads.getAdsLayout", &response, params)
return
}
// TODO: AdsGetAdsTargetingResponse struct.
// type AdsGetAdsTargetingResponse struct{}
// TODO: AdsGetAdsTargeting ...
//
// https://vk.com/dev/ads.getAdsTargeting
// func (vk *VK) AdsGetAdsTargeting(params Params) (response AdsGetAdsTargetingResponse, err error) {
// err = vk.RequestUnmarshal("ads.getAdsTargeting", &response, params)
// return
// }
// TODO: AdsGetBudgetResponse struct.
// type AdsGetBudgetResponse struct{}
// TODO: AdsGetBudget ...
//
// https://vk.com/dev/ads.getBudget
// func (vk *VK) AdsGetBudget(params Params) (response AdsGetBudgetResponse, err error) {
// err = vk.RequestUnmarshal("ads.getBudget", &response, params)
// return
// }
// TODO: AdsGetCampaignsResponse struct.
// type AdsGetCampaignsResponse struct{}
// TODO: AdsGetCampaigns ...
//
// https://vk.com/dev/ads.getCampaigns
// func (vk *VK) AdsGetCampaigns(params Params) (response AdsGetCampaignsResponse, err error) {
// err = vk.RequestUnmarshal("ads.getCampaigns", &response, params)
// return
// }
// TODO: AdsGetCategoriesResponse struct.
// type AdsGetCategoriesResponse struct{}
// TODO: AdsGetCategories ...
//
// https://vk.com/dev/ads.getCategories
// func (vk *VK) AdsGetCategories(params Params) (response AdsGetCategoriesResponse, err error) {
// err = vk.RequestUnmarshal("ads.getCategories", &response, params)
// return
// }
// TODO: AdsGetClientsResponse struct.
// type AdsGetClientsResponse struct{}
// TODO: AdsGetClients ...
//
// https://vk.com/dev/ads.getClients
// func (vk *VK) AdsGetClients(params Params) (response AdsGetClientsResponse, err error) {
// err = vk.RequestUnmarshal("ads.getClients", &response, params)
// return
// }
// TODO: AdsGetDemographicsResponse struct.
// type AdsGetDemographicsResponse struct{}
// TODO: AdsGetDemographics ...
//
// https://vk.com/dev/ads.getDemographics
// func (vk *VK) AdsGetDemographics(params Params) (response AdsGetDemographicsResponse, err error) {
// err = vk.RequestUnmarshal("ads.getDemographics", &response, params)
// return
// }
// TODO: AdsGetFloodStatsResponse struct.
// type AdsGetFloodStatsResponse struct{}
// TODO: AdsGetFloodStats ...
//
// https://vk.com/dev/ads.getFloodStats
// func (vk *VK) AdsGetFloodStats(params Params) (response AdsGetFloodStatsResponse, err error) {
// err = vk.RequestUnmarshal("ads.getFloodStats", &response, params)
// return
// }
// TODO: AdsGetLookalikeRequestsResponse struct.
// type AdsGetLookalikeRequestsResponse struct{}
// TODO: AdsGetLookalikeRequests ...
//
// https://vk.com/dev/ads.getLookalikeRequests
// func (vk *VK) AdsGetLookalikeRequests(params Params) (response AdsGetLookalikeRequestsResponse, err error) {
// err = vk.RequestUnmarshal("ads.getLookalikeRequests", &response, params)
// return
// }
// AdsGetMusiciansResponse struct.
type AdsGetMusiciansResponse struct {
Items []object.BaseObjectWithName
}
// AdsGetMusicians returns a list of musicians.
//
// https://vk.com/dev/ads.getMusicians
func (vk *VK) AdsGetMusicians(params Params) (response AdsGetMusiciansResponse, err error) {
err = vk.RequestUnmarshal("ads.getMusicians", &response, params)
return
}
// TODO: AdsGetOfficeUsersResponse struct.
// type AdsGetOfficeUsersResponse struct{}
// TODO: AdsGetOfficeUsers ...
//
// https://vk.com/dev/ads.getOfficeUsers
// func (vk *VK) AdsGetOfficeUsers(params Params) (response AdsGetOfficeUsersResponse, err error) {
// err = vk.RequestUnmarshal("ads.getOfficeUsers", &response, params)
// return
// }
// TODO: AdsGetPostsReachResponse struct.
// type AdsGetPostsReachResponse struct{}
// TODO: AdsGetPostsReach ...
//
// https://vk.com/dev/ads.getPostsReach
// func (vk *VK) AdsGetPostsReach(params Params) (response AdsGetPostsReachResponse, err error) {
// err = vk.RequestUnmarshal("ads.getPostsReach", &response, params)
// return
// }
// TODO: AdsGetRejectionReasonResponse struct.
// type AdsGetRejectionReasonResponse struct{}
// TODO: AdsGetRejectionReason ...
//
// https://vk.com/dev/ads.getRejectionReason
// func (vk *VK) AdsGetRejectionReason(params Params) (response AdsGetRejectionReasonResponse, err error) {
// err = vk.RequestUnmarshal("ads.getRejectionReason", &response, params)
// return
// }
// TODO: AdsGetStatisticsResponse struct.
// type AdsGetStatisticsResponse struct{}
// TODO: AdsGetStatistics ...
//
// https://vk.com/dev/ads.getStatistics
// func (vk *VK) AdsGetStatistics(params Params) (response AdsGetStatisticsResponse, err error) {
// err = vk.RequestUnmarshal("ads.getStatistics", &response, params)
// return
// }
// TODO: AdsGetSuggestionsResponse struct.
// type AdsGetSuggestionsResponse struct{}
// TODO: AdsGetSuggestions ...
//
// https://vk.com/dev/ads.getSuggestions
// func (vk *VK) AdsGetSuggestions(params Params) (response AdsGetSuggestionsResponse, err error) {
// err = vk.RequestUnmarshal("ads.getSuggestions", &response, params)
// return
// }
// AdsGetTargetGroupsResponse struct.
type AdsGetTargetGroupsResponse []object.AdsTargetGroup
// AdsGetTargetGroups returns a list of target groups.
//
// https://vk.com/dev/ads.getTargetGroups
func (vk *VK) AdsGetTargetGroups(params Params) (response AdsGetTargetGroupsResponse, err error) {
err = vk.RequestUnmarshal("ads.getTargetGroups", &response, params)
return
}
// TODO: AdsGetTargetPixelsResponse struct.
// type AdsGetTargetPixelsResponse struct{}
// TODO: AdsGetTargetPixels ...
//
// https://vk.com/dev/ads.getTargetPixels
// func (vk *VK) AdsGetTargetPixels(params Params) (response AdsGetTargetPixelsResponse, err error) {
// err = vk.RequestUnmarshal("ads.getTargetPixels", &response, params)
// return
// }
// TODO: AdsGetTargetingStatsResponse struct.
// type AdsGetTargetingStatsResponse struct{}
// TODO: AdsGetTargetingStats ...
//
// https://vk.com/dev/ads.getTargetingStats
// func (vk *VK) AdsGetTargetingStats(params Params) (response AdsGetTargetingStatsResponse, err error) {
// err = vk.RequestUnmarshal("ads.getTargetingStats", &response, params)
// return
// }
// TODO: AdsGetUploadURLResponse struct.
// type AdsGetUploadURLResponse struct{}
// TODO: AdsGetUploadURL ...
//
// https://vk.com/dev/ads.getUploadURL
// func (vk *VK) AdsGetUploadURL(params Params) (response AdsGetUploadURLResponse, err error) {
// err = vk.RequestUnmarshal("ads.getUploadURL", &response, params)
// return
// }
// TODO: AdsGetVideoUploadURLResponse struct.
// type AdsGetVideoUploadURLResponse struct{}
// TODO: AdsGetVideoUploadURL ...
//
// https://vk.com/dev/ads.getVideoUploadURL
// func (vk *VK) AdsGetVideoUploadURL(params Params) (response AdsGetVideoUploadURLResponse, err error) {
// err = vk.RequestUnmarshal("ads.getVideoUploadURL", &response, params)
// return
// }
// TODO: AdsImportTargetContactsResponse struct.
// type AdsImportTargetContactsResponse struct{}
// TODO: AdsImportTargetContacts ...
//
// https://vk.com/dev/ads.importTargetContacts
// func (vk *VK) AdsImportTargetContacts(params Params) (response AdsImportTargetContactsResponse, err error) {
// err = vk.RequestUnmarshal("ads.importTargetContacts", &response, params)
// return
// }
// TODO: AdsRemoveOfficeUsersResponse struct.
// type AdsRemoveOfficeUsersResponse struct{}
// TODO: AdsRemoveOfficeUsers ...
//
// https://vk.com/dev/ads.removeOfficeUsers
// func (vk *VK) AdsRemoveOfficeUsers(params Params) (response AdsRemoveOfficeUsersResponse, err error) {
// err = vk.RequestUnmarshal("ads.removeOfficeUsers", &response, params)
// return
// }
// AdsRemoveTargetContacts accepts the request to exclude the advertiser's
// contacts from the retargeting audience.
//
// The maximum allowed number of contacts to be excluded by a single
// request is 1000.
//
// Contacts are excluded within a few hours of the request.
//
// https://vk.com/dev/ads.removeTargetContacts
func (vk *VK) AdsRemoveTargetContacts(params Params) (response int, err error) {
err = vk.RequestUnmarshal("ads.removeTargetContacts", &response, params)
return
}
// TODO: AdsSaveLookalikeRequestResultResponse struct.
// type AdsSaveLookalikeRequestResultResponse struct{}
// TODO: AdsSaveLookalikeRequestResult ...
//
// https://vk.com/dev/ads.saveLookalikeRequestResult
// func (vk *VK) AdsSaveLookalikeRequestResult(params Params) (
// response AdsSaveLookalikeRequestResultResponse,
// err error,
// ) {
// err = vk.RequestUnmarshal("ads.saveLookalikeRequestResult", &response, params)
// return
// }
// TODO: AdsShareTargetGroupResponse struct.
// type AdsShareTargetGroupResponse struct{}
// TODO: AdsShareTargetGroup ...
//
// https://vk.com/dev/ads.shareTargetGroup
// func (vk *VK) AdsShareTargetGroup(params Params) (response AdsShareTargetGroupResponse, err error) {
// err = vk.RequestUnmarshal("ads.shareTargetGroup", &response, params)
// return
// }
// TODO: AdsUpdateAdsResponse struct.
// type AdsUpdateAdsResponse struct{}
// TODO: AdsUpdateAds ...
//
// https://vk.com/dev/ads.updateAds
// func (vk *VK) AdsUpdateAds(params Params) (response AdsUpdateAdsResponse, err error) {
// err = vk.RequestUnmarshal("ads.updateAds", &response, params)
// return
// }
// TODO: AdsUpdateCampaignsResponse struct.
// type AdsUpdateCampaignsResponse struct{}
// TODO: AdsUpdateCampaigns ...
//
// https://vk.com/dev/ads.updateCampaigns
// func (vk *VK) AdsUpdateCampaigns(params Params) (response AdsUpdateCampaignsResponse, err error) {
// err = vk.RequestUnmarshal("ads.updateCampaigns", &response, params)
// return
// }
// TODO: AdsUpdateClientsResponse struct.
// type AdsUpdateClientsResponse struct{}
// TODO: AdsUpdateClients ...
//
// https://vk.com/dev/ads.updateClients
// func (vk *VK) AdsUpdateClients(params Params) (response AdsUpdateClientsResponse, err error) {
// err = vk.RequestUnmarshal("ads.updateClients", &response, params)
// return
// }
// AdsUpdateTargetGroup edits target group.
//
// https://vk.com/dev/ads.updateTargetGroup
func (vk *VK) AdsUpdateTargetGroup(params Params) (response int, err error) {
err = vk.RequestUnmarshal("ads.updateTargetGroup", &response, params)
return
}
// AdsUpdateTargetPixel edits target pixel.
//
// https://vk.com/dev/ads.updateTargetPixel
func (vk *VK) AdsUpdateTargetPixel(params Params) (response int, err error) {
err = vk.RequestUnmarshal("ads. updateTargetPixel", &response, params)
return
}

359
vendor/github.com/SevereCloud/vksdk/v2/api/api.go generated vendored Normal file
View File

@@ -0,0 +1,359 @@
/*
Package api implements VK API.
See more https://vk.com/dev/api_requests
*/
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"bytes"
"context"
"encoding/json"
"fmt"
"mime"
"net/http"
"net/url"
"reflect"
"sync"
"sync/atomic"
"time"
"github.com/SevereCloud/vksdk/v2"
"github.com/SevereCloud/vksdk/v2/internal"
"github.com/SevereCloud/vksdk/v2/object"
)
// Api constants.
const (
Version = vksdk.API
MethodURL = "https://api.vk.com/method/"
)
// VKontakte API methods (except for methods from secure and ads sections)
// with user access key or service access key can be accessed
// no more than 3 times per second. The community access key is limited
// to 20 requests per second.
//
// Maximum amount of calls to the secure section methods depends
// on the app's users amount. If an app has less than
// 10 000 users, 5 requests per second,
// up to 100 000 8 requests,
// up to 1 000 000 20 requests,
// 1 000 000+ 35 requests.
//
// The ads section methods are subject to their own limitations,
// you can read them on this page - https://vk.com/dev/ads_limits
//
// If one of this limits is exceeded, the server will return following error:
// "Too many requests per second". (errors.TooMany).
//
// If your app's logic implies many requests in a row, check the execute method.
// It allows for up to 25 requests for different methods in a single request.
//
// In addition to restrictions on the frequency of calls, there are also
// quantitative restrictions on calling the same type of methods.
//
// After exceeding the quantitative limit, access to a particular method may
// require entering a captcha (see https://vk.com/dev/captcha_error),
// and may also be temporarily restricted (in this case, the server does
// not return a response to the call of a particular method, but handles
// any other requests without problems).
//
// If this error occurs, the following parameters are also passed in
// the error message:
//
// CaptchaSID - identifier captcha.
//
// CaptchaImg - a link to the image that you want to show the user
// to enter text from that image.
//
// In this case, you should ask the user to enter text from
// the CaptchaImg image and repeat the request by adding parameters to it:
//
// captcha_sid - the obtained identifier;
//
// captcha_key - text entered by the user.
//
// More info: https://vk.com/dev/api_requests
const (
LimitUserToken = 3
LimitGroupToken = 20
)
// VK struct.
type VK struct {
accessTokens []string
lastToken uint32
MethodURL string
Version string
Client *http.Client
Limit int
UserAgent string
Handler func(method string, params ...Params) (Response, error)
mux sync.Mutex
lastTime time.Time
rps int
}
// Response struct.
type Response struct {
Response json.RawMessage `json:"response"`
Error Error `json:"error"`
ExecuteErrors ExecuteErrors `json:"execute_errors"`
}
// NewVK returns a new VK.
//
// The VKSDK will use the http.DefaultClient.
// This means that if the http.DefaultClient is modified by other components
// of your application the modifications will be picked up by the SDK as well.
//
// In some cases this might be intended, but it is a better practice
// to create a custom HTTP Client to share explicitly through
// your application. You can configure the VKSDK to use the custom
// HTTP Client by setting the VK.Client value.
//
// This set limit 20 requests per second for one token.
func NewVK(tokens ...string) *VK {
var vk VK
vk.accessTokens = tokens
vk.Version = Version
vk.Handler = vk.defaultHandler
vk.MethodURL = MethodURL
vk.Client = http.DefaultClient
vk.Limit = LimitGroupToken
vk.UserAgent = internal.UserAgent
return &vk
}
// getToken return next token (simple round-robin).
func (vk *VK) getToken() string {
i := atomic.AddUint32(&vk.lastToken, 1)
return vk.accessTokens[(int(i)-1)%len(vk.accessTokens)]
}
// Params type.
type Params map[string]interface{}
// Lang - determines the language for the data to be displayed on. For
// example country and city names. If you use a non-cyrillic language,
// cyrillic symbols will be transliterated automatically.
// Numeric format from account.getInfo is supported as well.
//
// p.Lang(object.LangRU)
//
// See all language code in module object.
func (p Params) Lang(v int) Params {
p["lang"] = v
return p
}
// TestMode allows to send requests from a native app without switching it on
// for all users.
func (p Params) TestMode(v bool) Params {
p["test_mode"] = v
return p
}
// CaptchaSID received ID.
//
// See https://vk.com/dev/captcha_error
func (p Params) CaptchaSID(v string) Params {
p["captcha_sid"] = v
return p
}
// CaptchaKey text input.
//
// See https://vk.com/dev/captcha_error
func (p Params) CaptchaKey(v string) Params {
p["captcha_key"] = v
return p
}
// Confirm parameter.
//
// See https://vk.com/dev/need_confirmation
func (p Params) Confirm(v bool) Params {
p["confirm"] = v
return p
}
// WithContext parameter.
func (p Params) WithContext(ctx context.Context) Params {
p[":context"] = ctx
return p
}
func buildQuery(sliceParams ...Params) (context.Context, url.Values) {
query := url.Values{}
ctx := context.Background()
for _, params := range sliceParams {
for key, value := range params {
if key != ":context" {
query.Set(key, FmtValue(value, 0))
} else {
ctx = value.(context.Context)
}
}
}
return ctx, query
}
// defaultHandler provides access to VK API methods.
func (vk *VK) defaultHandler(method string, sliceParams ...Params) (Response, error) {
u := vk.MethodURL + method
ctx, query := buildQuery(sliceParams...)
attempt := 0
for {
var response Response
attempt++
// Rate limiting
if vk.Limit > 0 {
vk.mux.Lock()
sleepTime := time.Second - time.Since(vk.lastTime)
if sleepTime < 0 {
vk.lastTime = time.Now()
vk.rps = 0
} else if vk.rps == vk.Limit*len(vk.accessTokens) {
time.Sleep(sleepTime)
vk.lastTime = time.Now()
vk.rps = 0
}
vk.rps++
vk.mux.Unlock()
}
rawBody := bytes.NewBufferString(query.Encode())
req, err := http.NewRequestWithContext(ctx, "POST", u, rawBody)
if err != nil {
return response, err
}
req.Header.Set("User-Agent", vk.UserAgent)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := vk.Client.Do(req)
if err != nil {
return response, err
}
mediatype, _, _ := mime.ParseMediaType(resp.Header.Get("Content-Type"))
if mediatype != "application/json" {
_ = resp.Body.Close()
return response, &InvalidContentType{mediatype}
}
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
_ = resp.Body.Close()
return response, err
}
_ = resp.Body.Close()
switch response.Error.Code {
case ErrNoType:
return response, nil
case ErrTooMany:
if attempt < vk.Limit {
continue
}
return response, &response.Error
}
return response, &response.Error
}
}
// Request provides access to VK API methods.
func (vk *VK) Request(method string, sliceParams ...Params) ([]byte, error) {
token := vk.getToken()
reqParams := Params{
"access_token": token,
"v": vk.Version,
}
sliceParams = append(sliceParams, reqParams)
resp, err := vk.Handler(method, sliceParams...)
return resp.Response, err
}
// RequestUnmarshal provides access to VK API methods.
func (vk *VK) RequestUnmarshal(method string, obj interface{}, sliceParams ...Params) error {
rawResponse, err := vk.Request(method, sliceParams...)
if err != nil {
return err
}
return json.Unmarshal(rawResponse, &obj)
}
func fmtReflectValue(value reflect.Value, depth int) string {
switch f := value; value.Kind() {
case reflect.Invalid:
return ""
case reflect.Bool:
return fmtBool(f.Bool())
case reflect.Array, reflect.Slice:
s := ""
for i := 0; i < f.Len(); i++ {
if i > 0 {
s += ","
}
s += FmtValue(f.Index(i).Interface(), depth)
}
return s
case reflect.Ptr:
// pointer to array or slice or struct? ok at top level
// but not embedded (avoid loops)
if depth == 0 && f.Pointer() != 0 {
switch a := f.Elem(); a.Kind() {
case reflect.Array, reflect.Slice, reflect.Struct, reflect.Map:
return FmtValue(a.Interface(), depth+1)
}
}
}
return fmt.Sprint(value)
}
// FmtValue return vk format string.
func FmtValue(value interface{}, depth int) string {
if value == nil {
return ""
}
switch f := value.(type) {
case bool:
return fmtBool(f)
case object.Attachment:
return f.ToAttachment()
case object.JSONObject:
return f.ToJSON()
case reflect.Value:
return fmtReflectValue(f, depth)
}
return fmtReflectValue(reflect.ValueOf(value), depth)
}

149
vendor/github.com/SevereCloud/vksdk/v2/api/apps.go generated vendored Normal file
View File

@@ -0,0 +1,149 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// AppsDeleteAppRequests deletes all request notifications from the current app.
//
// https://vk.com/dev/apps.deleteAppRequests
func (vk *VK) AppsDeleteAppRequests(params Params) (response int, err error) {
err = vk.RequestUnmarshal("apps.deleteAppRequests", &response, params)
return
}
// AppsGetResponse struct.
type AppsGetResponse struct {
Count int `json:"count"`
Items []object.AppsApp `json:"items"`
object.ExtendedResponse
}
// AppsGet returns applications data.
//
// https://vk.com/dev/apps.get
func (vk *VK) AppsGet(params Params) (response AppsGetResponse, err error) {
err = vk.RequestUnmarshal("apps.get", &response, params)
return
}
// AppsGetCatalogResponse struct.
type AppsGetCatalogResponse struct {
Count int `json:"count"`
Items []object.AppsApp `json:"items"`
object.ExtendedResponse
}
// AppsGetCatalog returns a list of applications (apps) available to users in the App Catalog.
//
// https://vk.com/dev/apps.getCatalog
func (vk *VK) AppsGetCatalog(params Params) (response AppsGetCatalogResponse, err error) {
err = vk.RequestUnmarshal("apps.getCatalog", &response, params)
return
}
// AppsGetFriendsListResponse struct.
type AppsGetFriendsListResponse struct {
Count int `json:"count"`
Items []int `json:"items"`
}
// AppsGetFriendsList creates friends list for requests and invites in current app.
//
// extended=0
//
// https://vk.com/dev/apps.getFriendsList
func (vk *VK) AppsGetFriendsList(params Params) (response AppsGetFriendsListResponse, err error) {
err = vk.RequestUnmarshal("apps.getFriendsList", &response, params, Params{"extended": false})
return
}
// AppsGetFriendsListExtendedResponse struct.
type AppsGetFriendsListExtendedResponse struct {
Count int `json:"count"`
Items []object.UsersUser `json:"items"`
}
// AppsGetFriendsListExtended creates friends list for requests and invites in current app.
//
// extended=1
//
// https://vk.com/dev/apps.getFriendsList
func (vk *VK) AppsGetFriendsListExtended(params Params) (response AppsGetFriendsListExtendedResponse, err error) {
err = vk.RequestUnmarshal("apps.getFriendsList", &response, params, Params{"extended": true})
return
}
// AppsGetLeaderboardResponse struct.
type AppsGetLeaderboardResponse struct {
Count int `json:"count"`
Items []object.AppsLeaderboard `json:"items"`
}
// AppsGetLeaderboard returns players rating in the game.
//
// extended=0
//
// https://vk.com/dev/apps.getLeaderboard
func (vk *VK) AppsGetLeaderboard(params Params) (response AppsGetLeaderboardResponse, err error) {
err = vk.RequestUnmarshal("apps.getLeaderboard", &response, params, Params{"extended": false})
return
}
// AppsGetLeaderboardExtendedResponse struct.
type AppsGetLeaderboardExtendedResponse struct {
Count int `json:"count"`
Items []struct {
Score int `json:"score"`
UserID int `json:"user_id"`
} `json:"items"`
Profiles []object.UsersUser `json:"profiles"`
}
// AppsGetLeaderboardExtended returns players rating in the game.
//
// extended=1
//
// https://vk.com/dev/apps.getLeaderboard
func (vk *VK) AppsGetLeaderboardExtended(params Params) (response AppsGetLeaderboardExtendedResponse, err error) {
err = vk.RequestUnmarshal("apps.getLeaderboard", &response, params, Params{"extended": true})
return
}
// AppsGetScopesResponse struct.
type AppsGetScopesResponse struct {
Count int `json:"count"`
Items []object.AppsScope `json:"items"`
}
// AppsGetScopes ...
//
// TODO: write docs.
//
// https://vk.com/dev/apps.getScopes
func (vk *VK) AppsGetScopes(params Params) (response AppsGetScopesResponse, err error) {
err = vk.RequestUnmarshal("apps.getScopes", &response, params)
return
}
// AppsGetScore returns user score in app.
//
// NOTE: vk wtf!?
//
// https://vk.com/dev/apps.getScore
func (vk *VK) AppsGetScore(params Params) (response string, err error) {
err = vk.RequestUnmarshal("apps.getScore", &response, params)
return
}
// AppsSendRequest sends a request to another user in an app that uses VK authorization.
//
// https://vk.com/dev/apps.sendRequest
func (vk *VK) AppsSendRequest(params Params) (response int, err error) {
err = vk.RequestUnmarshal("apps.sendRequest", &response, params)
return
}

View File

@@ -0,0 +1,100 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// AppWidgetsGetAppImageUploadServerResponse struct.
type AppWidgetsGetAppImageUploadServerResponse struct {
UploadURL string `json:"upload_url"`
}
// AppWidgetsGetAppImageUploadServer returns a URL for uploading a
// photo to the app collection for community app widgets.
//
// https://vk.com/dev/appWidgets.getAppImageUploadServer
func (vk *VK) AppWidgetsGetAppImageUploadServer(params Params) (
response AppWidgetsGetAppImageUploadServerResponse,
err error,
) {
err = vk.RequestUnmarshal("appWidgets.getAppImageUploadServer", &response, params)
return
}
// AppWidgetsGetAppImagesResponse struct.
type AppWidgetsGetAppImagesResponse struct {
Count int `json:"count"`
Items []object.AppWidgetsImage `json:"items"`
}
// AppWidgetsGetAppImages returns an app collection of images for community app widgets.
//
// https://vk.com/dev/appWidgets.getAppImages
func (vk *VK) AppWidgetsGetAppImages(params Params) (response AppWidgetsGetAppImagesResponse, err error) {
err = vk.RequestUnmarshal("appWidgets.getAppImages", &response, params)
return
}
// AppWidgetsGetGroupImageUploadServerResponse struct.
type AppWidgetsGetGroupImageUploadServerResponse struct {
UploadURL string `json:"upload_url"`
}
// AppWidgetsGetGroupImageUploadServer returns a URL for uploading
// a photo to the community collection for community app widgets.
//
// https://vk.com/dev/appWidgets.getGroupImageUploadServer
func (vk *VK) AppWidgetsGetGroupImageUploadServer(params Params) (
response AppWidgetsGetGroupImageUploadServerResponse,
err error,
) {
err = vk.RequestUnmarshal("appWidgets.getGroupImageUploadServer", &response, params)
return
}
// AppWidgetsGetGroupImagesResponse struct.
type AppWidgetsGetGroupImagesResponse struct {
Count int `json:"count"`
Items []object.AppWidgetsImage `json:"items"`
}
// AppWidgetsGetGroupImages returns a community collection of images for community app widgets.
//
// https://vk.com/dev/appWidgets.getGroupImages
func (vk *VK) AppWidgetsGetGroupImages(params Params) (response AppWidgetsGetGroupImagesResponse, err error) {
err = vk.RequestUnmarshal("appWidgets.getGroupImages", &response, params)
return
}
// AppWidgetsGetImagesByID returns an image for community app widgets by its ID.
//
// https://vk.com/dev/appWidgets.getImagesById
func (vk *VK) AppWidgetsGetImagesByID(params Params) (response object.AppWidgetsImage, err error) {
err = vk.RequestUnmarshal("appWidgets.getImagesById", &response, params)
return
}
// AppWidgetsSaveAppImage allows to save image into app collection for community app widgets.
//
// https://vk.com/dev/appWidgets.saveAppImage
func (vk *VK) AppWidgetsSaveAppImage(params Params) (response object.AppWidgetsImage, err error) {
err = vk.RequestUnmarshal("appWidgets.saveAppImage", &response, params)
return
}
// AppWidgetsSaveGroupImage allows to save image into community collection for community app widgets.
//
// https://vk.com/dev/appWidgets.saveGroupImage
func (vk *VK) AppWidgetsSaveGroupImage(params Params) (response object.AppWidgetsImage, err error) {
err = vk.RequestUnmarshal("appWidgets.saveGroupImage", &response, params)
return
}
// AppWidgetsUpdate allows to update community app widget.
//
// https://vk.com/dev/appWidgets.update
func (vk *VK) AppWidgetsUpdate(params Params) (response int, err error) {
err = vk.RequestUnmarshal("appWidgets.update", &response, params)
return
}

26
vendor/github.com/SevereCloud/vksdk/v2/api/auth.go generated vendored Normal file
View File

@@ -0,0 +1,26 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
// AuthCheckPhone checks a user's phone number for correctness.
//
// https://vk.com/dev/auth.checkPhone
//
// Deprecated: This method is deprecated and may be disabled soon, please avoid
// using it.
func (vk *VK) AuthCheckPhone(params Params) (response int, err error) {
err = vk.RequestUnmarshal("auth.checkPhone", &response, params)
return
}
// AuthRestoreResponse struct.
type AuthRestoreResponse struct {
Success int `json:"success"`
SID string `json:"sid"`
}
// AuthRestore allows to restore account access using a code received via SMS.
//
// https://vk.com/dev/auth.restore
func (vk *VK) AuthRestore(params Params) (response AuthRestoreResponse, err error) {
err = vk.RequestUnmarshal("auth.restore", &response, params)
return
}

173
vendor/github.com/SevereCloud/vksdk/v2/api/board.go generated vendored Normal file
View File

@@ -0,0 +1,173 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// BoardAddTopic creates a new topic on a community's discussion board.
//
// https://vk.com/dev/board.addTopic
func (vk *VK) BoardAddTopic(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.addTopic", &response, params)
return
}
// BoardCloseTopic closes a topic on a community's discussion board so that comments cannot be posted.
//
// https://vk.com/dev/board.closeTopic
func (vk *VK) BoardCloseTopic(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.closeTopic", &response, params)
return
}
// BoardCreateComment adds a comment on a topic on a community's discussion board.
//
// https://vk.com/dev/board.createComment
func (vk *VK) BoardCreateComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.createComment", &response, params)
return
}
// BoardDeleteComment deletes a comment on a topic on a community's discussion board.
//
// https://vk.com/dev/board.deleteComment
func (vk *VK) BoardDeleteComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.deleteComment", &response, params)
return
}
// BoardDeleteTopic deletes a topic from a community's discussion board.
//
// https://vk.com/dev/board.deleteTopic
func (vk *VK) BoardDeleteTopic(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.deleteTopic", &response, params)
return
}
// BoardEditComment edits a comment on a topic on a community's discussion board.
//
// https://vk.com/dev/board.editComment
func (vk *VK) BoardEditComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.editComment", &response, params)
return
}
// BoardEditTopic edits the title of a topic on a community's discussion board.
//
// https://vk.com/dev/board.editTopic
func (vk *VK) BoardEditTopic(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.editTopic", &response, params)
return
}
// BoardFixTopic pins a topic (fixes its place) to the top of a community's discussion board.
//
// https://vk.com/dev/board.fixTopic
func (vk *VK) BoardFixTopic(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.fixTopic", &response, params)
return
}
// BoardGetCommentsResponse struct.
type BoardGetCommentsResponse struct {
Count int `json:"count"`
Items []object.BoardTopicComment `json:"items"`
Poll object.BoardTopicPoll `json:"poll"`
RealOffset int `json:"real_offset"`
}
// BoardGetComments returns a list of comments on a topic on a community's discussion board.
//
// extended=0
//
// https://vk.com/dev/board.getComments
func (vk *VK) BoardGetComments(params Params) (response BoardGetCommentsResponse, err error) {
err = vk.RequestUnmarshal("board.getComments", &response, params, Params{"extended": false})
return
}
// BoardGetCommentsExtendedResponse struct.
type BoardGetCommentsExtendedResponse struct {
Count int `json:"count"`
Items []object.BoardTopicComment `json:"items"`
Poll object.BoardTopicPoll `json:"poll"`
RealOffset int `json:"real_offset"`
Profiles []object.UsersUser `json:"profiles"`
Groups []object.GroupsGroup `json:"groups"`
}
// BoardGetCommentsExtended returns a list of comments on a topic on a community's discussion board.
//
// extended=1
//
// https://vk.com/dev/board.getComments
func (vk *VK) BoardGetCommentsExtended(params Params) (response BoardGetCommentsExtendedResponse, err error) {
err = vk.RequestUnmarshal("board.getComments", &response, params, Params{"extended": true})
return
}
// BoardGetTopicsResponse struct.
type BoardGetTopicsResponse struct {
Count int `json:"count"`
Items []object.BoardTopic `json:"items"`
DefaultOrder float64 `json:"default_order"` // BUG(VK): default_order int https://vk.com/bug136682
CanAddTopics object.BaseBoolInt `json:"can_add_topics"`
}
// BoardGetTopics returns a list of topics on a community's discussion board.
//
// extended=0
//
// https://vk.com/dev/board.getTopics
func (vk *VK) BoardGetTopics(params Params) (response BoardGetTopicsResponse, err error) {
err = vk.RequestUnmarshal("board.getTopics", &response, params, Params{"extended": false})
return
}
// BoardGetTopicsExtendedResponse struct.
type BoardGetTopicsExtendedResponse struct {
Count int `json:"count"`
Items []object.BoardTopic `json:"items"`
DefaultOrder float64 `json:"default_order"` // BUG(VK): default_order int https://vk.com/bug136682
CanAddTopics object.BaseBoolInt `json:"can_add_topics"`
Profiles []object.UsersUser `json:"profiles"`
Groups []object.GroupsGroup `json:"groups"`
}
// BoardGetTopicsExtended returns a list of topics on a community's discussion board.
//
// extended=1
//
// https://vk.com/dev/board.getTopics
func (vk *VK) BoardGetTopicsExtended(params Params) (response BoardGetTopicsExtendedResponse, err error) {
err = vk.RequestUnmarshal("board.getTopics", &response, params, Params{"extended": true})
return
}
// BoardOpenTopic re-opens a previously closed topic on a community's discussion board.
//
// https://vk.com/dev/board.openTopic
func (vk *VK) BoardOpenTopic(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.openTopic", &response, params)
return
}
// BoardRestoreComment restores a comment deleted from a topic on a community's discussion board.
//
// https://vk.com/dev/board.restoreComment
func (vk *VK) BoardRestoreComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.restoreComment", &response, params)
return
}
// BoardUnfixTopic unpins a pinned topic from the top of a community's discussion board.
//
// https://vk.com/dev/board.unfixTopic
func (vk *VK) BoardUnfixTopic(params Params) (response int, err error) {
err = vk.RequestUnmarshal("board.unfixTopic", &response, params)
return
}

View File

@@ -0,0 +1,7 @@
package api
// CaptchaForce api method.
func (vk *VK) CaptchaForce(params Params) (response int, err error) {
err = vk.RequestUnmarshal("captcha.force", &response, params)
return
}

163
vendor/github.com/SevereCloud/vksdk/v2/api/database.go generated vendored Normal file
View File

@@ -0,0 +1,163 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// DatabaseGetChairsResponse struct.
type DatabaseGetChairsResponse struct {
Count int `json:"count"`
Items []object.BaseObject `json:"items"`
}
// DatabaseGetChairs returns list of chairs on a specified faculty.
//
// https://vk.com/dev/database.getChairs
func (vk *VK) DatabaseGetChairs(params Params) (response DatabaseGetChairsResponse, err error) {
err = vk.RequestUnmarshal("database.getChairs", &response, params)
return
}
// DatabaseGetCitiesResponse struct.
type DatabaseGetCitiesResponse struct {
Count int `json:"count"`
Items []object.DatabaseCity `json:"items"`
}
// DatabaseGetCities returns a list of cities.
//
// https://vk.com/dev/database.getCities
func (vk *VK) DatabaseGetCities(params Params) (response DatabaseGetCitiesResponse, err error) {
err = vk.RequestUnmarshal("database.getCities", &response, params)
return
}
// DatabaseGetCitiesByIDResponse struct.
type DatabaseGetCitiesByIDResponse []object.DatabaseCity
// DatabaseGetCitiesByID returns information about cities by their IDs.
//
// https://vk.com/dev/database.getCitiesByID
func (vk *VK) DatabaseGetCitiesByID(params Params) (response DatabaseGetCitiesByIDResponse, err error) {
err = vk.RequestUnmarshal("database.getCitiesById", &response, params)
return
}
// DatabaseGetCountriesResponse struct.
type DatabaseGetCountriesResponse struct {
Count int `json:"count"`
Items []object.BaseObject `json:"items"`
}
// DatabaseGetCountries returns a list of countries.
//
// https://vk.com/dev/database.getCountries
func (vk *VK) DatabaseGetCountries(params Params) (response DatabaseGetCountriesResponse, err error) {
err = vk.RequestUnmarshal("database.getCountries", &response, params)
return
}
// DatabaseGetCountriesByIDResponse struct.
type DatabaseGetCountriesByIDResponse []object.BaseObject
// DatabaseGetCountriesByID returns information about countries by their IDs.
//
// https://vk.com/dev/database.getCountriesByID
func (vk *VK) DatabaseGetCountriesByID(params Params) (response DatabaseGetCountriesByIDResponse, err error) {
err = vk.RequestUnmarshal("database.getCountriesById", &response, params)
return
}
// DatabaseGetFacultiesResponse struct.
type DatabaseGetFacultiesResponse struct {
Count int `json:"count"`
Items []object.DatabaseFaculty `json:"items"`
}
// DatabaseGetFaculties returns a list of faculties (i.e., university departments).
//
// https://vk.com/dev/database.getFaculties
func (vk *VK) DatabaseGetFaculties(params Params) (response DatabaseGetFacultiesResponse, err error) {
err = vk.RequestUnmarshal("database.getFaculties", &response, params)
return
}
// DatabaseGetMetroStationsResponse struct.
type DatabaseGetMetroStationsResponse struct {
Count int `json:"count"`
Items []object.DatabaseMetroStation `json:"items"`
}
// DatabaseGetMetroStations returns the list of metro stations.
//
// https://vk.com/dev/database.getMetroStations
func (vk *VK) DatabaseGetMetroStations(params Params) (response DatabaseGetMetroStationsResponse, err error) {
err = vk.RequestUnmarshal("database.getMetroStations", &response, params)
return
}
// DatabaseGetMetroStationsByIDResponse struct.
type DatabaseGetMetroStationsByIDResponse []object.DatabaseMetroStation
// DatabaseGetMetroStationsByID returns information about one or several metro stations by their identifiers.
//
// https://vk.com/dev/database.getMetroStationsById
func (vk *VK) DatabaseGetMetroStationsByID(params Params) (response DatabaseGetMetroStationsByIDResponse, err error) {
err = vk.RequestUnmarshal("database.getMetroStationsById", &response, params)
return
}
// DatabaseGetRegionsResponse struct.
type DatabaseGetRegionsResponse struct {
Count int `json:"count"`
Items []object.DatabaseRegion `json:"items"`
}
// DatabaseGetRegions returns a list of regions.
//
// https://vk.com/dev/database.getRegions
func (vk *VK) DatabaseGetRegions(params Params) (response DatabaseGetRegionsResponse, err error) {
err = vk.RequestUnmarshal("database.getRegions", &response, params)
return
}
// DatabaseGetSchoolClassesResponse struct.
type DatabaseGetSchoolClassesResponse [][]interface{}
// DatabaseGetSchoolClasses returns a list of school classes specified for the country.
//
// BUG(VK): database.getSchoolClasses bad return.
//
// https://vk.com/dev/database.getSchoolClasses
func (vk *VK) DatabaseGetSchoolClasses(params Params) (response DatabaseGetSchoolClassesResponse, err error) {
err = vk.RequestUnmarshal("database.getSchoolClasses", &response, params)
return
}
// DatabaseGetSchoolsResponse struct.
type DatabaseGetSchoolsResponse struct {
Count int `json:"count"`
Items []object.DatabaseSchool `json:"items"`
}
// DatabaseGetSchools returns a list of schools.
//
// https://vk.com/dev/database.getSchools
func (vk *VK) DatabaseGetSchools(params Params) (response DatabaseGetSchoolsResponse, err error) {
err = vk.RequestUnmarshal("database.getSchools", &response, params)
return
}
// DatabaseGetUniversitiesResponse struct.
type DatabaseGetUniversitiesResponse struct {
Count int `json:"count"`
Items []object.DatabaseUniversity `json:"items"`
}
// DatabaseGetUniversities returns a list of higher education institutions.
//
// https://vk.com/dev/database.getUniversities
func (vk *VK) DatabaseGetUniversities(params Params) (response DatabaseGetUniversitiesResponse, err error) {
err = vk.RequestUnmarshal("database.getUniversities", &response, params)
return
}

137
vendor/github.com/SevereCloud/vksdk/v2/api/docs.go generated vendored Normal file
View File

@@ -0,0 +1,137 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// DocsAdd copies a document to a user's or community's document list.
//
// https://vk.com/dev/docs.add
func (vk *VK) DocsAdd(params Params) (response int, err error) {
err = vk.RequestUnmarshal("docs.add", &response, params)
return
}
// DocsDelete deletes a user or community document.
//
// https://vk.com/dev/docs.delete
func (vk *VK) DocsDelete(params Params) (response int, err error) {
err = vk.RequestUnmarshal("docs.delete", &response, params)
return
}
// DocsEdit edits a document.
//
// https://vk.com/dev/docs.edit
func (vk *VK) DocsEdit(params Params) (response int, err error) {
err = vk.RequestUnmarshal("docs.edit", &response, params)
return
}
// DocsGetResponse struct.
type DocsGetResponse struct {
Count int `json:"count"`
Items []object.DocsDoc `json:"items"`
}
// DocsGet returns detailed information about user or community documents.
//
// https://vk.com/dev/docs.get
func (vk *VK) DocsGet(params Params) (response DocsGetResponse, err error) {
err = vk.RequestUnmarshal("docs.get", &response, params)
return
}
// DocsGetByIDResponse struct.
type DocsGetByIDResponse []object.DocsDoc
// DocsGetByID returns information about documents by their IDs.
//
// https://vk.com/dev/docs.getById
func (vk *VK) DocsGetByID(params Params) (response DocsGetByIDResponse, err error) {
err = vk.RequestUnmarshal("docs.getById", &response, params)
return
}
// DocsGetMessagesUploadServerResponse struct.
type DocsGetMessagesUploadServerResponse struct {
UploadURL string `json:"upload_url"`
}
// DocsGetMessagesUploadServer returns the server address for document upload.
//
// https://vk.com/dev/docs.getMessagesUploadServer
func (vk *VK) DocsGetMessagesUploadServer(params Params) (response DocsGetMessagesUploadServerResponse, err error) {
err = vk.RequestUnmarshal("docs.getMessagesUploadServer", &response, params)
return
}
// DocsGetTypesResponse struct.
type DocsGetTypesResponse struct {
Count int `json:"count"`
Items []object.DocsDocTypes `json:"items"`
}
// DocsGetTypes returns documents types available for current user.
//
// https://vk.com/dev/docs.getTypes
func (vk *VK) DocsGetTypes(params Params) (response DocsGetTypesResponse, err error) {
err = vk.RequestUnmarshal("docs.getTypes", &response, params)
return
}
// DocsGetUploadServerResponse struct.
type DocsGetUploadServerResponse struct {
UploadURL string `json:"upload_url"`
}
// DocsGetUploadServer returns the server address for document upload.
//
// https://vk.com/dev/docs.getUploadServer
func (vk *VK) DocsGetUploadServer(params Params) (response DocsGetUploadServerResponse, err error) {
err = vk.RequestUnmarshal("docs.getUploadServer", &response, params)
return
}
// DocsGetWallUploadServerResponse struct.
type DocsGetWallUploadServerResponse struct {
UploadURL string `json:"upload_url"`
}
// DocsGetWallUploadServer returns the server address for document upload onto a user's or community's wall.
//
// https://vk.com/dev/docs.getWallUploadServer
func (vk *VK) DocsGetWallUploadServer(params Params) (response DocsGetWallUploadServerResponse, err error) {
err = vk.RequestUnmarshal("docs.getWallUploadServer", &response, params)
return
}
// DocsSaveResponse struct.
type DocsSaveResponse struct {
Type string `json:"type"`
AudioMessage object.MessagesAudioMessage `json:"audio_message"`
Doc object.DocsDoc `json:"doc"`
Graffiti object.MessagesGraffiti `json:"graffiti"`
}
// DocsSave saves a document after uploading it to a server.
//
// https://vk.com/dev/docs.save
func (vk *VK) DocsSave(params Params) (response DocsSaveResponse, err error) {
err = vk.RequestUnmarshal("docs.save", &response, params)
return
}
// DocsSearchResponse struct.
type DocsSearchResponse struct {
Count int `json:"count"`
Items []object.DocsDoc `json:"items"`
}
// DocsSearch returns a list of documents matching the search criteria.
//
// https://vk.com/dev/docs.search
func (vk *VK) DocsSearch(params Params) (response DocsSearchResponse, err error) {
err = vk.RequestUnmarshal("docs.search", &response, params)
return
}

49
vendor/github.com/SevereCloud/vksdk/v2/api/donut.go generated vendored Normal file
View File

@@ -0,0 +1,49 @@
package api
import "github.com/SevereCloud/vksdk/v2/object"
// DonutGetFriendsResponse struct.
type DonutGetFriendsResponse struct {
Count int `json:"count"`
Items []object.UsersUser `json:"items"`
}
// DonutGetFriends method.
//
// https://vk.com/dev/donut.getFriends
func (vk *VK) DonutGetFriends(params Params) (response DonutGetFriendsResponse, err error) {
err = vk.RequestUnmarshal("donut.getFriends", &response, params)
return
}
// DonutGetSubscription method.
//
// https://vk.com/dev/donut.getSubscription
func (vk *VK) DonutGetSubscription(params Params) (response object.DonutDonatorSubscriptionInfo, err error) {
err = vk.RequestUnmarshal("donut.getSubscription", &response, params)
return
}
// DonutGetSubscriptionsResponse struct.
type DonutGetSubscriptionsResponse struct {
Subscriptions []object.DonutDonatorSubscriptionInfo `json:"subscriptions"`
Count int `json:"count"`
Profiles []object.UsersUser `json:"profiles"`
Groups []object.GroupsGroup `json:"groups"`
}
// DonutGetSubscriptions method.
//
// https://vk.com/dev/donut.getSubscriptions
func (vk *VK) DonutGetSubscriptions(params Params) (response DonutGetSubscriptionsResponse, err error) {
err = vk.RequestUnmarshal("donut.getSubscriptions", &response, params)
return
}
// DonutIsDon method.
//
// https://vk.com/dev/donut.isDon
func (vk *VK) DonutIsDon(params Params) (response int, err error) {
err = vk.RequestUnmarshal("donut.isDon", &response, params)
return
}

View File

@@ -0,0 +1,19 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// DownloadedGamesGetPaidStatusResponse struct.
type DownloadedGamesGetPaidStatusResponse struct {
IsPaid object.BaseBoolInt `json:"is_paid"`
}
// DownloadedGamesGetPaidStatus method.
//
// https://vk.com/dev/downloadedGames.getPaidStatus
func (vk *VK) DownloadedGamesGetPaidStatus(params Params) (response DownloadedGamesGetPaidStatusResponse, err error) {
err = vk.RequestUnmarshal("downloadedGames.getPaidStatus", &response, params, Params{"extended": false})
return
}

948
vendor/github.com/SevereCloud/vksdk/v2/api/errors.go generated vendored Normal file
View File

@@ -0,0 +1,948 @@
package api
import (
"errors"
"fmt"
"github.com/SevereCloud/vksdk/v2/object"
)
// ErrorType is the type of an error.
type ErrorType int
// Error returns the message of a ErrorType.
func (e ErrorType) Error() string {
return fmt.Sprintf("api: error with code %d", e)
}
// Error codes. See https://vk.com/dev/errors
const (
ErrNoType ErrorType = 0 // NoType error
// Unknown error occurred
//
// Try again later.
ErrUnknown ErrorType = 1
// Application is disabled. Enable your application or use test mode
//
// You need to switch on the app in Settings
// https://vk.com/editapp?id={Your API_ID}
// or use the test mode (test_mode=1).
ErrDisabled ErrorType = 2
// Unknown method passed.
//
// Check the method name: http://vk.com/dev/methods
ErrMethod ErrorType = 3
ErrSignature ErrorType = 4 // Incorrect signature
// User authorization failed
//
// Make sure that you use a correct authorization type.
ErrAuth ErrorType = 5
// Too many requests per second
//
// Decrease the request frequency or use the execute method.
// More details on frequency limits here:
// https://vk.com/dev/api_requests
ErrTooMany ErrorType = 6
// Permission to perform this action is denied
//
// Make sure that your have received required permissions during the
// authorization.
// You can do it with the account.getAppPermissions method.
// https://vk.com/dev/permissions
ErrPermission ErrorType = 7
// Invalid request
//
// Check the request syntax and used parameters list (it can be found on
// a method description page).
ErrRequest ErrorType = 8
// Flood control
//
// You need to decrease the count of identical requests. For more efficient
// work you may use execute.
ErrFlood ErrorType = 9
// Internal server error
//
// Try again later.
ErrServer ErrorType = 10
// In test mode application should be disabled or user should be authorized
//
// Switch the app off in Settings:
//
// https://vk.com/editapp?id={Your API_ID}
//
ErrEnabledInTest ErrorType = 11
// Unable to compile code.
ErrCompile ErrorType = 12
// Runtime error occurred during code invocation.
ErrRuntime ErrorType = 13
// Captcha needed.
//
// See https://vk.com/dev/captcha_error
ErrCaptcha ErrorType = 14
// Access denied
//
// Make sure that you use correct identifiers and the content is available
// for the user in the full version of the site.
ErrAccess ErrorType = 15
// HTTP authorization failed
//
// To avoid this error check if a user has the 'Use secure connection'
// option enabled with the account.getInfo method.
ErrAuthHTTPS ErrorType = 16
// Validation required
//
// Make sure that you don't use a token received with
// http://vk.com/dev/auth_mobile for a request from the server.
// It's restricted.
//
// https://vk.com/dev/need_validation
ErrAuthValidation ErrorType = 17
ErrUserDeleted ErrorType = 18 // User was deleted or banned
ErrBlocked ErrorType = 19 // Content blocked
// Permission to perform this action is denied for non-standalone
// applications.
ErrMethodPermission ErrorType = 20
// Permission to perform this action is allowed only for standalone and
// OpenAPI applications.
ErrMethodAds ErrorType = 21
ErrUpload ErrorType = 22 // Upload error
// This method was disabled.
//
// All the methods available now are listed here: http://vk.com/dev/methods
ErrMethodDisabled ErrorType = 23
// Confirmation required
//
// In some cases VK requires to request action confirmation from the user
// (for Standalone apps only).
//
// Following parameter is transmitted with the error message as well:
//
// confirmation_text text of the message to be shown in the default
// confirmation window.
//
// The app should display the default confirmation window
// with text from confirmation_text and two buttons: "Continue" and
// "Cancel".
// If user confirms the action repeat the request with an extra parameter:
//
// confirm = 1.
//
// https://vk.com/dev/need_confirmation
ErrNeedConfirmation ErrorType = 24
ErrNeedTokenConfirmation ErrorType = 25 // Token confirmation required
ErrGroupAuth ErrorType = 27 // Group authorization failed
ErrAppAuth ErrorType = 28 // Application authorization failed
// Rate limit reached.
//
// More details on rate limits here: https://vk.com/dev/data_limits
ErrRateLimit ErrorType = 29
ErrPrivateProfile ErrorType = 30 // This profile is private
// Method execution was interrupted due to timeout.
ErrExecutionTimeout ErrorType = 36
// User was banned.
ErrUserBanned ErrorType = 37
// Unknown application.
ErrUnknownApplication ErrorType = 38
// Unknown user.
ErrUnknownUser ErrorType = 39
// Unknown group.
ErrUnknownGroup ErrorType = 40
// Additional signup required.
ErrAdditionalSignupRequired ErrorType = 41
// One of the parameters specified was missing or invalid
//
// Check the required parameters list and their format on a method
// description page.
ErrParam ErrorType = 100
// Invalid application API ID
//
// Find the app in the administrated list in settings:
// http://vk.com/apps?act=settings
// And set the correct API_ID in the request.
ErrParamAPIID ErrorType = 101
ErrLimits ErrorType = 103 // Out of limits
ErrNotFound ErrorType = 104 // Not found
ErrSaveFile ErrorType = 105 // Couldn't save file
ErrActionFailed ErrorType = 106 // Unable to process action
// Invalid user id
//
// Make sure that you use a correct id. You can get an id using a screen
// name with the utils.resolveScreenName method.
ErrParamUserID ErrorType = 113
ErrParamAlbumID ErrorType = 114 // Invalid album id
ErrParamServer ErrorType = 118 // Invalid server
ErrParamTitle ErrorType = 119 // Invalid title
ErrParamPhotos ErrorType = 122 // Invalid photos
ErrParamHash ErrorType = 121 // Invalid hash
ErrParamPhoto ErrorType = 129 // Invalid photo
ErrParamGroupID ErrorType = 125 // Invalid group id
ErrParamPageID ErrorType = 140 // Page not found
ErrAccessPage ErrorType = 141 // Access to page denied
// The mobile number of the user is unknown.
ErrMobileNotActivated ErrorType = 146
// Application has insufficient funds.
ErrInsufficientFunds ErrorType = 147
// Access to the menu of the user denied.
ErrAccessMenu ErrorType = 148
// Invalid timestamp
//
// You may get a correct value with the utils.getServerTime method.
ErrParamTimestamp ErrorType = 150
ErrFriendsListID ErrorType = 171 // Invalid list id
// Reached the maximum number of lists.
ErrFriendsListLimit ErrorType = 173
// Cannot add user himself as friend.
ErrFriendsAddYourself ErrorType = 174
// Cannot add this user to friends as they have put you on their blacklist.
ErrFriendsAddInEnemy ErrorType = 175
// Cannot add this user to friends as you put him on blacklist.
ErrFriendsAddEnemy ErrorType = 176
// Cannot add this user to friends as user not found.
ErrFriendsAddNotFound ErrorType = 177
ErrParamNoteID ErrorType = 180 // Note not found
ErrAccessNote ErrorType = 181 // Access to note denied
ErrAccessNoteComment ErrorType = 182 // You can't comment this note
ErrAccessComment ErrorType = 183 // Access to comment denied
// Access to album denied
//
// Make sure you use correct ids (owner_id is always positive for users,
// negative for communities) and the current user has access to the
// requested content in the full version of the site.
ErrAccessAlbum ErrorType = 200
// Access to audio denied
//
// Make sure you use correct ids (owner_id is always positive for users,
// negative for communities) and the current user has access to the
// requested content in the full version of the site.
ErrAccessAudio ErrorType = 201
// Access to group denied
//
// Make sure that the current user is a member or admin of the community
// (for closed and private groups and events).
ErrAccessGroup ErrorType = 203
// Access denied.
ErrAccessVideo ErrorType = 204
// Access denied.
ErrAccessMarket ErrorType = 205
// Access to wall's post denied.
ErrWallAccessPost ErrorType = 210
// Access to wall's comment denied.
ErrWallAccessComment ErrorType = 211
// Access to post comments denied.
ErrWallAccessReplies ErrorType = 212
// Access to status replies denied.
ErrWallAccessAddReply ErrorType = 213
// Access to adding post denied.
ErrWallAddPost ErrorType = 214
// Advertisement post was recently added.
ErrWallAdsPublished ErrorType = 219
// Too many recipients.
ErrWallTooManyRecipients ErrorType = 220
// User disabled track name broadcast.
ErrStatusNoAudio ErrorType = 221
// Hyperlinks are forbidden.
ErrWallLinksForbidden ErrorType = 222
// Too many replies.
ErrWallReplyOwnerFlood ErrorType = 223
// Too many ads posts.
ErrWallAdsPostLimitReached ErrorType = 224
// Donut is disabled.
ErrDonutDisabled ErrorType = 225
// Reaction can not be applied to the object.
ErrLikesReactionCanNotBeApplied ErrorType = 232
// Access to poll denied.
ErrPollsAccess ErrorType = 250
// Invalid answer id.
ErrPollsAnswerID ErrorType = 252
// Invalid poll id.
ErrPollsPollID ErrorType = 251
// Access denied, please vote first.
ErrPollsAccessWithoutVote ErrorType = 253
// Access to the groups list is denied due to the user's privacy settings.
ErrAccessGroups ErrorType = 260
// This album is full
//
// You need to delete the odd objects from the album or use another album.
ErrAlbumFull ErrorType = 300
ErrAlbumsLimit ErrorType = 302 // Albums number limit is reached
// Permission denied. You must enable votes processing in application
// settings
//
// Check the app settings:
//
// http://vk.com/editapp?id={Your API_ID}&section=payments
//
ErrVotesPermission ErrorType = 500
// Not enough votes.
ErrVotes ErrorType = 503
// Not enough money on owner's balance.
ErrNotEnoughMoney ErrorType = 504
// Permission denied. You have no access to operations specified with
// given object(s).
ErrAdsPermission ErrorType = 600
// Permission denied. You have requested too many actions this day. Try
// later.
ErrWeightedFlood ErrorType = 601
// Some part of the request has not been completed.
ErrAdsPartialSuccess ErrorType = 602
// Some ads error occurred.
ErrAdsSpecific ErrorType = 603
// Invalid domain.
ErrAdsDomainInvalid ErrorType = 604
// Domain is forbidden.
ErrAdsDomainForbidden ErrorType = 605
// Domain is reserved.
ErrAdsDomainReserved ErrorType = 606
// Domain is occupied.
ErrAdsDomainOccupied ErrorType = 607
// Domain is active.
ErrAdsDomainActive ErrorType = 608
// Domain app is invalid.
ErrAdsDomainAppInvalid ErrorType = 609
// Domain app is forbidden.
ErrAdsDomainAppForbidden ErrorType = 610
// Application must be verified.
ErrAdsApplicationMustBeVerified ErrorType = 611
// Application must be in domains list of site of ad unit.
ErrAdsApplicationMustBeInDomainsList ErrorType = 612
// Application is blocked.
ErrAdsApplicationBlocked ErrorType = 613
// Domain of type specified is forbidden in current office type.
ErrAdsDomainTypeForbiddenInCurrentOffice ErrorType = 614
// Domain group is invalid.
ErrAdsDomainGroupInvalid ErrorType = 615
// Domain group is forbidden.
ErrAdsDomainGroupForbidden ErrorType = 616
// Domain app is blocked.
ErrAdsDomainAppBlocked ErrorType = 617
// Domain group is not open.
ErrAdsDomainGroupNotOpen ErrorType = 618
// Domain group is not possible to be joined to adsweb.
ErrAdsDomainGroupNotPossibleJoined ErrorType = 619
// Domain group is blocked.
ErrAdsDomainGroupBlocked ErrorType = 620
// Domain group has restriction: links are forbidden.
ErrAdsDomainGroupLinksForbidden ErrorType = 621
// Domain group has restriction: excluded from search.
ErrAdsDomainGroupExcludedFromSearch ErrorType = 622
// Domain group has restriction: cover is forbidden.
ErrAdsDomainGroupCoverForbidden ErrorType = 623
// Domain group has wrong category.
ErrAdsDomainGroupWrongCategory ErrorType = 624
// Domain group has wrong name.
ErrAdsDomainGroupWrongName ErrorType = 625
// Domain group has low posts reach.
ErrAdsDomainGroupLowPostsReach ErrorType = 626
// Domain group has wrong class.
ErrAdsDomainGroupWrongClass ErrorType = 627
// Domain group is created recently.
ErrAdsDomainGroupCreatedRecently ErrorType = 628
// Object deleted.
ErrAdsObjectDeleted ErrorType = 629
// Lookalike request with same source already in progress.
ErrAdsLookalikeRequestAlreadyInProgress ErrorType = 630
// Max count of lookalike requests per day reached.
ErrAdsLookalikeRequestsLimit ErrorType = 631
// Given audience is too small.
ErrAdsAudienceTooSmall ErrorType = 632
// Given audience is too large.
ErrAdsAudienceTooLarge ErrorType = 633
// Lookalike request audience save already in progress.
ErrAdsLookalikeAudienceSaveAlreadyInProgress ErrorType = 634
// Max count of lookalike request audience saves per day reached.
ErrAdsLookalikeSavesLimit ErrorType = 635
// Max count of retargeting groups reached.
ErrAdsRetargetingGroupsLimit ErrorType = 636
// Domain group has active nemesis punishment.
ErrAdsDomainGroupActiveNemesisPunishment ErrorType = 637
// Cannot edit creator role.
ErrGroupChangeCreator ErrorType = 700
// User should be in club.
ErrGroupNotInClub ErrorType = 701
// Too many officers in club.
ErrGroupTooManyOfficers ErrorType = 702
// You need to enable 2FA for this action.
ErrGroupNeed2fa ErrorType = 703
// User needs to enable 2FA for this action.
ErrGroupHostNeed2fa ErrorType = 704
// Too many addresses in club.
ErrGroupTooManyAddresses ErrorType = 706
// "Application is not installed in community.
ErrGroupAppIsNotInstalledInCommunity ErrorType = 711
// Invite link is invalid - expired, deleted or not exists.
ErrGroupInvalidInviteLink ErrorType = 714
// This video is already added.
ErrVideoAlreadyAdded ErrorType = 800
// Comments for this video are closed.
ErrVideoCommentsClosed ErrorType = 801
// Can't send messages for users from blacklist.
ErrMessagesUserBlocked ErrorType = 900
// Can't send messages for users without permission.
ErrMessagesDenySend ErrorType = 901
// Can't send messages to this user due to their privacy settings.
ErrMessagesPrivacy ErrorType = 902
// Value of ts or pts is too old.
ErrMessagesTooOldPts ErrorType = 907
// Value of ts or pts is too new.
ErrMessagesTooNewPts ErrorType = 908
// Can't edit this message, because it's too old.
ErrMessagesEditExpired ErrorType = 909
// Can't sent this message, because it's too big.
ErrMessagesTooBig ErrorType = 910
// Keyboard format is invalid.
ErrMessagesKeyboardInvalid ErrorType = 911
// This is a chat bot feature, change this status in settings.
ErrMessagesChatBotFeature ErrorType = 912
// Too many forwarded messages.
ErrMessagesTooLongForwards ErrorType = 913
// Message is too long.
ErrMessagesTooLongMessage ErrorType = 914
// You don't have access to this chat.
ErrMessagesChatUserNoAccess ErrorType = 917
// You can't see invite link for this chat.
ErrMessagesCantSeeInviteLink ErrorType = 919
// Can't edit this kind of message.
ErrMessagesEditKindDisallowed ErrorType = 920
// Can't forward these messages.
ErrMessagesCantFwd ErrorType = 921
// Can't delete this message for everybody.
ErrMessagesCantDeleteForAll ErrorType = 924
// You are not admin of this chat.
ErrMessagesChatNotAdmin ErrorType = 925
// Chat does not exist.
ErrMessagesChatNotExist ErrorType = 927
// You can't change invite link for this chat.
ErrMessagesCantChangeInviteLink ErrorType = 931
// Your community can't interact with this peer.
ErrMessagesGroupPeerAccess ErrorType = 932
// User not found in chat.
ErrMessagesChatUserNotInChat ErrorType = 935
// Contact not found.
ErrMessagesContactNotFound ErrorType = 936
// Message request already send.
ErrMessagesMessageRequestAlreadySend ErrorType = 939
// Too many posts in messages.
ErrMessagesTooManyPosts ErrorType = 940
// Cannot pin one-time story.
ErrMessagesCantPinOneTimeStory ErrorType = 942
// Cannot use this intent.
ErrMessagesCantUseIntent ErrorType = 943
// Limits overflow for this intent.
ErrMessagesLimitIntent ErrorType = 944
// Chat was disabled.
ErrMessagesChatDisabled ErrorType = 945
// Chat not support.
ErrMessagesChatNotSupported ErrorType = 946
// Can't add user to chat, because user has no access to group.
ErrMessagesMemberAccessToGroupDenied ErrorType = 947
// Can't edit pinned message yet.
ErrMessagesEditPinned ErrorType = 949
// Can't send message, reply timed out.
ErrMessagesReplyTimedOut ErrorType = 950
// Invalid phone number.
ErrParamPhone ErrorType = 1000
// This phone number is used by another user.
ErrPhoneAlreadyUsed ErrorType = 1004
// Too many auth attempts, try again later.
ErrAuthFloodError ErrorType = 1105
// Processing.. Try later.
ErrAuthDelay ErrorType = 1112
// Invalid document id.
ErrParamDocID ErrorType = 1150
// Access to document deleting is denied.
ErrParamDocDeleteAccess ErrorType = 1151
// Invalid document title.
ErrParamDocTitle ErrorType = 1152
// Access to document is denied.
ErrParamDocAccess ErrorType = 1153
// Original photo was changed.
ErrPhotoChanged ErrorType = 1160
// Too many feed lists.
ErrTooManyLists ErrorType = 1170
// This achievement is already unlocked.
ErrAppsAlreadyUnlocked ErrorType = 1251
// Subscription not found.
ErrAppsSubscriptionNotFound ErrorType = 1256
// Subscription is in invalid status.
ErrAppsSubscriptionInvalidStatus ErrorType = 1257
// Invalid screen name.
ErrInvalidAddress ErrorType = 1260
// Catalog is not available for this user.
ErrCommunitiesCatalogDisabled ErrorType = 1310
// Catalog categories are not available for this user.
ErrCommunitiesCategoriesDisabled ErrorType = 1311
// Too late for restore.
ErrMarketRestoreTooLate ErrorType = 1400
// Comments for this market are closed.
ErrMarketCommentsClosed ErrorType = 1401
// Album not found.
ErrMarketAlbumNotFound ErrorType = 1402
// Item not found.
ErrMarketItemNotFound ErrorType = 1403
// Item already added to album.
ErrMarketItemAlreadyAdded ErrorType = 1404
// Too many items.
ErrMarketTooManyItems ErrorType = 1405
// Too many items in album.
ErrMarketTooManyItemsInAlbum ErrorType = 1406
// Too many albums.
ErrMarketTooManyAlbums ErrorType = 1407
// Item has bad links in description.
ErrMarketItemHasBadLinks ErrorType = 1408
// Extended market not enabled.
ErrMarketShopNotEnabled ErrorType = 1409
// Grouping items with different properties.
ErrMarketGroupingItemsWithDifferentProperties ErrorType = 1412
// Grouping already has such variant.
ErrMarketGroupingAlreadyHasSuchVariant ErrorType = 1413
// Variant not found.
ErrMarketVariantNotFound ErrorType = 1416
// Property not found.
ErrMarketPropertyNotFound ErrorType = 1417
// Grouping must have two or more items.
ErrMarketGroupingMustContainMoreThanOneItem ErrorType = 1425
// Item must have distinct properties.
ErrMarketGroupingItemsMustHaveDistinctProperties ErrorType = 1426
// Cart is empty.
ErrMarketOrdersNoCartItems ErrorType = 1427
// Specify width, length, height and weight all together.
ErrMarketInvalidDimensions ErrorType = 1429
// VK Pay status can not be changed.
ErrMarketCantChangeVkpayStatus ErrorType = 1430
// Market was already enabled in this group.
ErrMarketShopAlreadyEnabled ErrorType = 1431
// Market was already disabled in this group.
ErrMarketShopAlreadyDisabled ErrorType = 1432
// Invalid image crop format.
ErrMarketPhotosCropInvalidFormat ErrorType = 1433
// Crop bottom right corner is outside of the image.
ErrMarketPhotosCropOverflow ErrorType = 1434
// Crop size is less than the minimum.
ErrMarketPhotosCropSizeTooLow ErrorType = 1435
// Market not enabled.
ErrMarketNotEnabled ErrorType = 1438
// Cart is empty.
ErrMarketCartEmpty ErrorType = 1427
// Specify width, length, height and weight all together.
ErrMarketSpecifyDimensions ErrorType = 1429
// VK Pay status can not be changed.
ErrVKPayStatus ErrorType = 1430
// Market was already enabled in this group.
ErrMarketAlreadyEnabled ErrorType = 1431
// Market was already disabled in this group.
ErrMarketAlreadyDisabled ErrorType = 1432
// Story has already expired.
ErrStoryExpired ErrorType = 1600
// Incorrect reply privacy.
ErrStoryIncorrectReplyPrivacy ErrorType = 1602
// Card not found.
ErrPrettyCardsCardNotFound ErrorType = 1900
// Too many cards.
ErrPrettyCardsTooManyCards ErrorType = 1901
// Card is connected to post.
ErrPrettyCardsCardIsConnectedToPost ErrorType = 1902
// Servers number limit is reached.
ErrCallbackServersLimit ErrorType = 2000
// Stickers are not purchased.
ErrStickersNotPurchased ErrorType = 2100
// Too many favorite stickers.
ErrStickersTooManyFavorites ErrorType = 2101
// Stickers are not favorite.
ErrStickersNotFavorite ErrorType = 2102
// Specified link is incorrect (can't find source).
ErrWallCheckLinkCantDetermineSource ErrorType = 3102
// Recaptcha needed.
ErrRecaptcha ErrorType = 3300
// Phone validation needed.
ErrPhoneValidation ErrorType = 3301
// Password validation needed.
ErrPasswordValidation ErrorType = 3302
// Otp app validation needed.
ErrOtpAppValidation ErrorType = 3303
// Email confirmation needed.
ErrEmailConfirmation ErrorType = 3304
// Assert votes.
ErrAssertVotes ErrorType = 3305
// Token extension required.
ErrTokenExtension ErrorType = 3609
// User is deactivated.
ErrUserDeactivated ErrorType = 3610
// Service is deactivated for user.
ErrServiceDeactivated ErrorType = 3611
// Can't set AliExpress tag to this type of object.
ErrAliExpressTag ErrorType = 3800
)
// ErrorSubtype is the subtype of an error.
type ErrorSubtype int
// Error returns the message of a ErrorSubtype.
func (e ErrorSubtype) Error() string {
return fmt.Sprintf("api: error with subcode %d", e)
}
// Error struct VK.
type Error struct {
Code ErrorType `json:"error_code"`
Subcode ErrorSubtype `json:"error_subcode"`
Message string `json:"error_msg"`
Text string `json:"error_text"`
CaptchaSID string `json:"captcha_sid"`
CaptchaImg string `json:"captcha_img"`
// In some cases VK requires to request action confirmation from the user
// (for Standalone apps only). Following error will be returned:
//
// Error code: 24
// Error text: Confirmation required
//
// Following parameter is transmitted with the error message as well:
//
// confirmation_text text of the message to be shown in the default
// confirmation window.
//
// The app should display the default confirmation window with text from
// confirmation_text and two buttons: "Continue" and "Cancel". If user
// confirms the action repeat the request with an extra parameter:
// confirm = 1.
//
// See https://vk.com/dev/need_confirmation
ConfirmationText string `json:"confirmation_text"`
// In some cases VK requires a user validation procedure. . As a result
// starting from API version 5.0 (for the older versions captcha_error
// will be requested) following error will be returned as a reply to any
// API request:
//
// Error code: 17
// Error text: Validation Required
//
// Following parameter is transmitted with an error message:
// redirect_uri a special address to open in a browser to pass the
// validation procedure.
//
// After passing the validation a user will be redirected to the service
// page:
//
// https://oauth.vk.com/blank.html#{Data required for validation}
//
// In case of successful validation following parameters will be
// transmitted after #:
//
// https://oauth.vk.com/blank.html#success=1&access_token={NEW USER TOKEN}&user_id={USER ID}
//
// If a token was not received by https a new secret will be transmitted
// as well.
//
// In case of unsuccessful validation following address is transmitted:
//
// https://oauth.vk.com/blank.html#fail=1
//
// See https://vk.com/dev/need_validation
RedirectURI string `json:"redirect_uri"`
RequestParams []object.BaseRequestParam `json:"request_params"`
}
// Error returns the message of a Error.
func (e Error) Error() string {
return "api: " + e.Message
}
// Is unwraps its first argument sequentially looking for an error that matches
// the second.
func (e Error) Is(target error) bool {
var tError *Error
if errors.As(target, &tError) {
return e.Code == tError.Code && e.Message == tError.Message
}
var tErrorType ErrorType
if errors.As(target, &tErrorType) {
return e.Code == tErrorType
}
return false
}
// ExecuteError struct.
//
// TODO: v3 Code is ErrorType.
type ExecuteError struct {
Method string `json:"method"`
Code int `json:"error_code"`
Msg string `json:"error_msg"`
}
// ExecuteErrors type.
type ExecuteErrors []ExecuteError
// Error returns the message of a ExecuteErrors.
func (e ExecuteErrors) Error() string {
return fmt.Sprintf("api: execute errors (%d)", len(e))
}
// InvalidContentType type.
type InvalidContentType struct {
ContentType string
}
// Error returns the message of a InvalidContentType.
func (e InvalidContentType) Error() string {
return "api: invalid content-type"
}
// UploadError type.
type UploadError struct {
Err string `json:"error"`
Code int `json:"error_code"`
Descr string `json:"error_descr"`
IsLogged bool `json:"error_is_logged"`
}
// Error returns the message of a UploadError.
func (e UploadError) Error() string {
if e.Err != "" {
return "api: " + e.Err
}
return fmt.Sprintf("api: upload code %d", e.Code)
}
// AdsError struct.
type AdsError struct {
Code ErrorType `json:"error_code"`
Desc string `json:"error_desc"`
}
// Error returns the message of a AdsError.
func (e AdsError) Error() string {
return "api: " + e.Desc
}
// Is unwraps its first argument sequentially looking for an error that matches
// the second.
func (e AdsError) Is(target error) bool {
var tAdsError *AdsError
if errors.As(target, &tAdsError) {
return e.Code == tAdsError.Code && e.Desc == tAdsError.Desc
}
var tErrorType ErrorType
if errors.As(target, &tErrorType) {
return e.Code == tErrorType
}
return false
}

52
vendor/github.com/SevereCloud/vksdk/v2/api/execute.go generated vendored Normal file
View File

@@ -0,0 +1,52 @@
package api
import "encoding/json"
// ExecuteWithArgs a universal method for calling a sequence of other methods
// while saving and filtering interim results.
//
// The Args map variable allows you to retrieve the parameters passed during
// the request and avoids code formatting.
//
// return Args.code; // return parameter "code"
// return Args.v; // return parameter "v"
//
// https://vk.com/dev/execute
func (vk *VK) ExecuteWithArgs(code string, params Params, obj interface{}) error {
token := vk.getToken()
reqParams := Params{
"code": code,
"access_token": token,
"v": vk.Version,
}
resp, err := vk.Handler("execute", params, reqParams)
jsonErr := json.Unmarshal(resp.Response, &obj)
if jsonErr != nil {
return jsonErr
}
if resp.ExecuteErrors != nil {
return &resp.ExecuteErrors
}
return err
}
// Execute a universal method for calling a sequence of other methods while
// saving and filtering interim results.
//
// https://vk.com/dev/execute
func (vk *VK) Execute(code string, obj interface{}) error {
return vk.ExecuteWithArgs(code, Params{}, obj)
}
func fmtBool(value bool) string {
if value {
return "1"
}
return "0"
}

231
vendor/github.com/SevereCloud/vksdk/v2/api/fave.go generated vendored Normal file
View File

@@ -0,0 +1,231 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// FaveAddArticle adds a link to user faves.
//
// https://vk.com/dev/fave.addArticle
func (vk *VK) FaveAddArticle(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.addArticle", &response, params)
return
}
// FaveAddLink adds a link to user faves.
//
// https://vk.com/dev/fave.addLink
func (vk *VK) FaveAddLink(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.addLink", &response, params)
return
}
// FaveAddPage method.
//
// https://vk.com/dev/fave.addPage
func (vk *VK) FaveAddPage(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.addPage", &response, params)
return
}
// FaveAddPost method.
//
// https://vk.com/dev/fave.addPost
func (vk *VK) FaveAddPost(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.addPost", &response, params)
return
}
// FaveAddProduct method.
//
// https://vk.com/dev/fave.addProduct
func (vk *VK) FaveAddProduct(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.addProduct", &response, params)
return
}
// FaveAddTagResponse struct.
type FaveAddTagResponse object.FaveTag
// FaveAddTag method.
//
// https://vk.com/dev/fave.addTag
func (vk *VK) FaveAddTag(params Params) (response FaveAddTagResponse, err error) {
err = vk.RequestUnmarshal("fave.addTag", &response, params)
return
}
// FaveAddVideo method.
//
// https://vk.com/dev/fave.addVideo
func (vk *VK) FaveAddVideo(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.addVideo", &response, params)
return
}
// FaveEditTag method.
//
// https://vk.com/dev/fave.editTag
func (vk *VK) FaveEditTag(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.editTag", &response, params)
return
}
// FaveGetResponse struct.
type FaveGetResponse struct {
Count int `json:"count"`
Items []object.FaveItem `json:"items"`
}
// FaveGet method.
//
// extended=0
//
// https://vk.com/dev/fave.get
func (vk *VK) FaveGet(params Params) (response FaveGetResponse, err error) {
err = vk.RequestUnmarshal("fave.get", &response, params, Params{"extended": false})
return
}
// FaveGetExtendedResponse struct.
type FaveGetExtendedResponse struct {
Count int `json:"count"`
Items []object.FaveItem `json:"items"`
object.ExtendedResponse
}
// FaveGetExtended method.
//
// extended=1
//
// https://vk.com/dev/fave.get
func (vk *VK) FaveGetExtended(params Params) (response FaveGetExtendedResponse, err error) {
err = vk.RequestUnmarshal("fave.get", &response, params, Params{"extended": true})
return
}
// FaveGetPagesResponse struct.
type FaveGetPagesResponse struct {
Count int `json:"count"`
Items []object.FavePage `json:"items"`
}
// FaveGetPages method.
//
// https://vk.com/dev/fave.getPages
func (vk *VK) FaveGetPages(params Params) (response FaveGetPagesResponse, err error) {
err = vk.RequestUnmarshal("fave.getPages", &response, params)
return
}
// FaveGetTagsResponse struct.
type FaveGetTagsResponse struct {
Count int `json:"count"`
Items []object.FaveTag `json:"items"`
}
// FaveGetTags method.
//
// https://vk.com/dev/fave.getTags
func (vk *VK) FaveGetTags(params Params) (response FaveGetTagsResponse, err error) {
err = vk.RequestUnmarshal("fave.getTags", &response, params)
return
}
// FaveMarkSeen method.
//
// https://vk.com/dev/fave.markSeen
func (vk *VK) FaveMarkSeen(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.markSeen", &response, params)
return
}
// FaveRemoveArticle method.
//
// https://vk.com/dev/fave.removeArticle
func (vk *VK) FaveRemoveArticle(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.removeArticle", &response, params)
return
}
// FaveRemoveLink removes link from the user's faves.
//
// https://vk.com/dev/fave.removeLink
func (vk *VK) FaveRemoveLink(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.removeLink", &response, params)
return
}
// FaveRemovePage method.
//
// https://vk.com/dev/fave.removePage
func (vk *VK) FaveRemovePage(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.removePage", &response, params)
return
}
// FaveRemovePost method.
//
// https://vk.com/dev/fave.removePost
func (vk *VK) FaveRemovePost(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.removePost", &response, params)
return
}
// FaveRemoveProduct method.
//
// https://vk.com/dev/fave.removeProduct
func (vk *VK) FaveRemoveProduct(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.removeProduct", &response, params)
return
}
// FaveRemoveTag method.
//
// https://vk.com/dev/fave.removeTag
func (vk *VK) FaveRemoveTag(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.removeTag", &response, params)
return
}
// FaveRemoveVideo method.
//
// https://vk.com/dev/fave.removeVideo
func (vk *VK) FaveRemoveVideo(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.removeVideo", &response, params)
return
}
// FaveReorderTags method.
//
// https://vk.com/dev/fave.reorderTags
func (vk *VK) FaveReorderTags(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.reorderTags", &response, params)
return
}
// FaveSetPageTags method.
//
// https://vk.com/dev/fave.setPageTags
func (vk *VK) FaveSetPageTags(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.setPageTags", &response, params)
return
}
// FaveSetTags method.
//
// https://vk.com/dev/fave.setTags
func (vk *VK) FaveSetTags(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.setTags", &response, params)
return
}
// FaveTrackPageInteraction method.
//
// https://vk.com/dev/fave.trackPageInteraction
func (vk *VK) FaveTrackPageInteraction(params Params) (response int, err error) {
err = vk.RequestUnmarshal("fave.trackPageInteraction", &response, params)
return
}

295
vendor/github.com/SevereCloud/vksdk/v2/api/friends.go generated vendored Normal file
View File

@@ -0,0 +1,295 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// FriendsAdd approves or creates a friend request.
//
// https://vk.com/dev/friends.add
func (vk *VK) FriendsAdd(params Params) (response int, err error) {
err = vk.RequestUnmarshal("friends.add", &response, params)
return
}
// FriendsAddListResponse struct.
type FriendsAddListResponse struct {
ListID int `json:"list_id"`
}
// FriendsAddList creates a new friend list for the current user.
//
// https://vk.com/dev/friends.addList
func (vk *VK) FriendsAddList(params Params) (response FriendsAddListResponse, err error) {
err = vk.RequestUnmarshal("friends.addList", &response, params)
return
}
// FriendsAreFriendsResponse struct.
type FriendsAreFriendsResponse []object.FriendsFriendStatus
// FriendsAreFriends checks the current user's friendship status with other specified users.
//
// https://vk.com/dev/friends.areFriends
func (vk *VK) FriendsAreFriends(params Params) (response FriendsAreFriendsResponse, err error) {
err = vk.RequestUnmarshal("friends.areFriends", &response, params)
return
}
// FriendsDeleteResponse struct.
type FriendsDeleteResponse struct {
Success object.BaseBoolInt `json:"success"`
FriendDeleted object.BaseBoolInt `json:"friend_deleted"`
OutRequestDeleted object.BaseBoolInt `json:"out_request_deleted"`
InRequestDeleted object.BaseBoolInt `json:"in_request_deleted"`
SuggestionDeleted object.BaseBoolInt `json:"suggestion_deleted"`
}
// FriendsDelete declines a friend request or deletes a user from the current user's friend list.
//
// https://vk.com/dev/friends.delete
func (vk *VK) FriendsDelete(params Params) (response FriendsDeleteResponse, err error) {
err = vk.RequestUnmarshal("friends.delete", &response, params)
return
}
// FriendsDeleteAllRequests marks all incoming friend requests as viewed.
//
// https://vk.com/dev/friends.deleteAllRequests
func (vk *VK) FriendsDeleteAllRequests(params Params) (response int, err error) {
err = vk.RequestUnmarshal("friends.deleteAllRequests", &response, params)
return
}
// FriendsDeleteList deletes a friend list of the current user.
//
// https://vk.com/dev/friends.deleteList
func (vk *VK) FriendsDeleteList(params Params) (response int, err error) {
err = vk.RequestUnmarshal("friends.deleteList", &response, params)
return
}
// FriendsEdit edits the friend lists of the selected user.
//
// https://vk.com/dev/friends.edit
func (vk *VK) FriendsEdit(params Params) (response int, err error) {
err = vk.RequestUnmarshal("friends.edit", &response, params)
return
}
// FriendsEditList edits a friend list of the current user.
//
// https://vk.com/dev/friends.editList
func (vk *VK) FriendsEditList(params Params) (response int, err error) {
err = vk.RequestUnmarshal("friends.editList", &response, params)
return
}
// FriendsGetResponse struct.
type FriendsGetResponse struct {
Count int `json:"count"`
Items []int `json:"items"`
}
// FriendsGet returns a list of user IDs or detailed information about a user's friends.
//
// https://vk.com/dev/friends.get
func (vk *VK) FriendsGet(params Params) (response FriendsGetResponse, err error) {
err = vk.RequestUnmarshal("friends.get", &response, params)
return
}
// FriendsGetFieldsResponse struct.
type FriendsGetFieldsResponse struct {
Count int `json:"count"`
Items []object.FriendsUserXtrLists `json:"items"`
}
// FriendsGetFields returns a list of user IDs or detailed information about a user's friends.
//
// https://vk.com/dev/friends.get
func (vk *VK) FriendsGetFields(params Params) (response FriendsGetFieldsResponse, err error) {
reqParams := make(Params)
if v, prs := params["fields"]; v == "" || !prs {
reqParams["fields"] = "id"
}
err = vk.RequestUnmarshal("friends.get", &response, params, reqParams)
return
}
// FriendsGetAppUsersResponse struct.
type FriendsGetAppUsersResponse []int
// FriendsGetAppUsers returns a list of IDs of the current user's friends who installed the application.
//
// https://vk.com/dev/friends.getAppUsers
func (vk *VK) FriendsGetAppUsers(params Params) (response FriendsGetAppUsersResponse, err error) {
err = vk.RequestUnmarshal("friends.getAppUsers", &response, params)
return
}
// FriendsGetByPhonesResponse struct.
type FriendsGetByPhonesResponse []object.FriendsUserXtrPhone
// FriendsGetByPhones returns a list of the current user's friends
// whose phone numbers, validated or specified in a profile, are in a given list.
//
// https://vk.com/dev/friends.getByPhones
func (vk *VK) FriendsGetByPhones(params Params) (response FriendsGetByPhonesResponse, err error) {
err = vk.RequestUnmarshal("friends.getByPhones", &response, params)
return
}
// FriendsGetListsResponse struct.
type FriendsGetListsResponse struct {
Count int `json:"count"`
Items []object.FriendsFriendsList `json:"items"`
}
// FriendsGetLists returns a list of the user's friend lists.
//
// https://vk.com/dev/friends.getLists
func (vk *VK) FriendsGetLists(params Params) (response FriendsGetListsResponse, err error) {
err = vk.RequestUnmarshal("friends.getLists", &response, params)
return
}
// FriendsGetMutualResponse struct.
type FriendsGetMutualResponse []int
// FriendsGetMutual returns a list of user IDs of the mutual friends of two users.
//
// https://vk.com/dev/friends.getMutual
func (vk *VK) FriendsGetMutual(params Params) (response FriendsGetMutualResponse, err error) {
err = vk.RequestUnmarshal("friends.getMutual", &response, params)
return
}
// FriendsGetOnline returns a list of user IDs of a user's friends who are online.
//
// online_mobile=0
//
// https://vk.com/dev/friends.getOnline
func (vk *VK) FriendsGetOnline(params Params) (response []int, err error) {
err = vk.RequestUnmarshal("friends.getOnline", &response, params, Params{"online_mobile": false})
return
}
// FriendsGetOnlineOnlineMobileResponse struct.
type FriendsGetOnlineOnlineMobileResponse struct {
Online []int `json:"online"`
OnlineMobile []int `json:"online_mobile"`
}
// FriendsGetOnlineOnlineMobile returns a list of user IDs of a user's friends who are online.
//
// online_mobile=1
//
// https://vk.com/dev/friends.getOnline
func (vk *VK) FriendsGetOnlineOnlineMobile(params Params) (response FriendsGetOnlineOnlineMobileResponse, err error) {
err = vk.RequestUnmarshal("friends.getOnline", &response, params, Params{"online_mobile": true})
return
}
// FriendsGetRecentResponse struct.
type FriendsGetRecentResponse []int
// FriendsGetRecent returns a list of user IDs of the current user's recently added friends.
//
// https://vk.com/dev/friends.getRecent
func (vk *VK) FriendsGetRecent(params Params) (response FriendsGetRecentResponse, err error) {
err = vk.RequestUnmarshal("friends.getRecent", &response, params)
return
}
// FriendsGetRequestsResponse struct.
type FriendsGetRequestsResponse struct {
Count int `json:"count"` // Total requests number
Items []int `json:"items"`
}
// FriendsGetRequests returns information about the current user's incoming and outgoing friend requests.
//
// https://vk.com/dev/friends.getRequests
func (vk *VK) FriendsGetRequests(params Params) (response FriendsGetRequestsResponse, err error) {
reqParams := Params{
"need_mutual": false,
"extended": false,
}
err = vk.RequestUnmarshal("friends.getRequests", &response, params, reqParams)
return
}
// FriendsGetRequestsNeedMutualResponse struct.
type FriendsGetRequestsNeedMutualResponse struct {
Count int `json:"count"` // Total requests number
Items []object.FriendsRequests `json:"items"`
}
// FriendsGetRequestsNeedMutual returns information about the current user's incoming and outgoing friend requests.
//
// https://vk.com/dev/friends.getRequests
func (vk *VK) FriendsGetRequestsNeedMutual(params Params) (response FriendsGetRequestsNeedMutualResponse, err error) {
reqParams := Params{
"extended": false,
"need_mutual": true,
}
err = vk.RequestUnmarshal("friends.getRequests", &response, params, reqParams)
return
}
// FriendsGetRequestsExtendedResponse struct.
type FriendsGetRequestsExtendedResponse struct {
Count int `json:"count"`
Items []object.FriendsRequestsXtrMessage `json:"items"`
}
// FriendsGetRequestsExtended returns information about the current user's incoming and outgoing friend requests.
//
// https://vk.com/dev/friends.getRequests
func (vk *VK) FriendsGetRequestsExtended(params Params) (response FriendsGetRequestsExtendedResponse, err error) {
reqParams := Params{
"need_mutual": false,
"extended": true,
}
err = vk.RequestUnmarshal("friends.getRequests", &response, params, reqParams)
return
}
// FriendsGetSuggestionsResponse struct.
type FriendsGetSuggestionsResponse struct {
Count int `json:"count"`
Items []object.UsersUser `json:"items"`
}
// FriendsGetSuggestions returns a list of profiles of users whom the current user may know.
//
// https://vk.com/dev/friends.getSuggestions
func (vk *VK) FriendsGetSuggestions(params Params) (response FriendsGetSuggestionsResponse, err error) {
err = vk.RequestUnmarshal("friends.getSuggestions", &response, params)
return
}
// FriendsSearchResponse struct.
type FriendsSearchResponse struct {
Count int `json:"count"`
Items []object.UsersUser `json:"items"`
}
// FriendsSearch returns a list of friends matching the search criteria.
//
// https://vk.com/dev/friends.search
func (vk *VK) FriendsSearch(params Params) (response FriendsSearchResponse, err error) {
err = vk.RequestUnmarshal("friends.search", &response, params)
return
}

32
vendor/github.com/SevereCloud/vksdk/v2/api/gifts.go generated vendored Normal file
View File

@@ -0,0 +1,32 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import "github.com/SevereCloud/vksdk/v2/object"
// GiftsGetResponse struct.
type GiftsGetResponse struct {
Count int `json:"count"`
Items []object.GiftsGift `json:"items"`
}
// GiftsGet returns a list of user gifts.
//
// https://vk.com/dev/gifts.get
func (vk *VK) GiftsGet(params Params) (response GiftsGetResponse, err error) {
err = vk.RequestUnmarshal("gifts.get", &response, params)
return
}
// GiftsGetCatalogResponse struct.
type GiftsGetCatalogResponse []struct {
Name string `json:"name"`
Title string `json:"title"`
Items []object.GiftsGift `json:"items"`
}
// GiftsGetCatalog returns catalog.
//
// https://vk.com/dev/gifts.get
func (vk *VK) GiftsGetCatalog(params Params) (response GiftsGetCatalogResponse, err error) {
err = vk.RequestUnmarshal("gifts.getCatalog", &response, params)
return
}

712
vendor/github.com/SevereCloud/vksdk/v2/api/groups.go generated vendored Normal file
View File

@@ -0,0 +1,712 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// GroupsAddAddressResponse struct.
type GroupsAddAddressResponse object.GroupsAddress
// GroupsAddAddress groups.addAddress.
//
// https://vk.com/dev/groups.addAddress
func (vk *VK) GroupsAddAddress(params Params) (response GroupsAddAddressResponse, err error) {
err = vk.RequestUnmarshal("groups.addAddress", &response, params)
return
}
// GroupsAddCallbackServerResponse struct.
type GroupsAddCallbackServerResponse struct {
ServerID int `json:"server_id"`
}
// GroupsAddCallbackServer callback API server to the community.
//
// https://vk.com/dev/groups.addCallbackServer
func (vk *VK) GroupsAddCallbackServer(params Params) (response GroupsAddCallbackServerResponse, err error) {
err = vk.RequestUnmarshal("groups.addCallbackServer", &response, params)
return
}
// GroupsAddLinkResponse struct.
type GroupsAddLinkResponse object.GroupsGroupLink
// GroupsAddLink allows to add a link to the community.
//
// https://vk.com/dev/groups.addLink
func (vk *VK) GroupsAddLink(params Params) (response GroupsAddLinkResponse, err error) {
err = vk.RequestUnmarshal("groups.addLink", &response, params)
return
}
// GroupsApproveRequest allows to approve join request to the community.
//
// https://vk.com/dev/groups.approveRequest
func (vk *VK) GroupsApproveRequest(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.approveRequest", &response, params)
return
}
// GroupsBan adds a user or a group to the community blacklist.
//
// https://vk.com/dev/groups.ban
func (vk *VK) GroupsBan(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.ban", &response, params)
return
}
// GroupsCreateResponse struct.
type GroupsCreateResponse object.GroupsGroup
// GroupsCreate creates a new community.
//
// https://vk.com/dev/groups.create
func (vk *VK) GroupsCreate(params Params) (response GroupsCreateResponse, err error) {
err = vk.RequestUnmarshal("groups.create", &response, params)
return
}
// GroupsDeleteAddress groups.deleteAddress.
//
// https://vk.com/dev/groups.deleteAddress
func (vk *VK) GroupsDeleteAddress(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.deleteAddress", &response, params)
return
}
// GroupsDeleteCallbackServer callback API server from the community.
//
// https://vk.com/dev/groups.deleteCallbackServer
func (vk *VK) GroupsDeleteCallbackServer(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.deleteCallbackServer", &response, params)
return
}
// GroupsDeleteLink allows to delete a link from the community.
//
// https://vk.com/dev/groups.deleteLink
func (vk *VK) GroupsDeleteLink(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.deleteLink", &response, params)
return
}
// GroupsDisableOnline disables "online" status in the community.
//
// https://vk.com/dev/groups.disableOnline
func (vk *VK) GroupsDisableOnline(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.disableOnline", &response, params)
return
}
// GroupsEdit edits a community.
//
// https://vk.com/dev/groups.edit
func (vk *VK) GroupsEdit(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.edit", &response, params)
return
}
// GroupsEditAddressResponse struct.
type GroupsEditAddressResponse object.GroupsAddress
// GroupsEditAddress groups.editAddress.
//
// https://vk.com/dev/groups.editAddress
func (vk *VK) GroupsEditAddress(params Params) (response GroupsEditAddressResponse, err error) {
err = vk.RequestUnmarshal("groups.editAddress", &response, params)
return
}
// GroupsEditCallbackServer edits Callback API server in the community.
//
// https://vk.com/dev/groups.editCallbackServer
func (vk *VK) GroupsEditCallbackServer(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.editCallbackServer", &response, params)
return
}
// GroupsEditLink allows to edit a link in the community.
//
// https://vk.com/dev/groups.editLink
func (vk *VK) GroupsEditLink(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.editLink", &response, params)
return
}
// GroupsEditManager allows to add, remove or edit the community manager .
//
// https://vk.com/dev/groups.editManager
func (vk *VK) GroupsEditManager(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.editManager", &response, params)
return
}
// GroupsEnableOnline enables "online" status in the community.
//
// https://vk.com/dev/groups.enableOnline
func (vk *VK) GroupsEnableOnline(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.enableOnline", &response, params)
return
}
// GroupsGetResponse struct.
type GroupsGetResponse struct {
Count int `json:"count"`
Items []int `json:"items"`
}
// GroupsGet returns a list of the communities to which a user belongs.
//
// extended=0
//
// https://vk.com/dev/groups.get
func (vk *VK) GroupsGet(params Params) (response GroupsGetResponse, err error) {
err = vk.RequestUnmarshal("groups.get", &response, params, Params{"extended": false})
return
}
// GroupsGetExtendedResponse struct.
type GroupsGetExtendedResponse struct {
Count int `json:"count"`
Items []object.GroupsGroup `json:"items"`
}
// GroupsGetExtended returns a list of the communities to which a user belongs.
//
// extended=1
//
// https://vk.com/dev/groups.get
func (vk *VK) GroupsGetExtended(params Params) (response GroupsGetExtendedResponse, err error) {
err = vk.RequestUnmarshal("groups.get", &response, params, Params{"extended": true})
return
}
// GroupsGetAddressesResponse struct.
type GroupsGetAddressesResponse struct {
Count int `json:"count"`
Items []object.GroupsAddress `json:"items"`
}
// GroupsGetAddresses groups.getAddresses.
//
// https://vk.com/dev/groups.getAddresses
func (vk *VK) GroupsGetAddresses(params Params) (response GroupsGetAddressesResponse, err error) {
err = vk.RequestUnmarshal("groups.getAddresses", &response, params)
return
}
// GroupsGetBannedResponse struct.
type GroupsGetBannedResponse struct {
Count int `json:"count"`
Items []object.GroupsOwnerXtrBanInfo `json:"items"`
}
// GroupsGetBanned returns a list of users on a community blacklist.
//
// https://vk.com/dev/groups.getBanned
func (vk *VK) GroupsGetBanned(params Params) (response GroupsGetBannedResponse, err error) {
err = vk.RequestUnmarshal("groups.getBanned", &response, params)
return
}
// GroupsGetByIDResponse struct.
type GroupsGetByIDResponse []object.GroupsGroup
// GroupsGetByID returns information about communities by their IDs.
//
// https://vk.com/dev/groups.getById
func (vk *VK) GroupsGetByID(params Params) (response GroupsGetByIDResponse, err error) {
err = vk.RequestUnmarshal("groups.getById", &response, params)
return
}
// GroupsGetCallbackConfirmationCodeResponse struct.
type GroupsGetCallbackConfirmationCodeResponse struct {
Code string `json:"code"`
}
// GroupsGetCallbackConfirmationCode returns Callback API confirmation code for the community.
//
// https://vk.com/dev/groups.getCallbackConfirmationCode
func (vk *VK) GroupsGetCallbackConfirmationCode(params Params) (
response GroupsGetCallbackConfirmationCodeResponse,
err error,
) {
err = vk.RequestUnmarshal("groups.getCallbackConfirmationCode", &response, params)
return
}
// GroupsGetCallbackServersResponse struct.
type GroupsGetCallbackServersResponse struct {
Count int `json:"count"`
Items []object.GroupsCallbackServer `json:"items"`
}
// GroupsGetCallbackServers receives a list of Callback API servers from the community.
//
// https://vk.com/dev/groups.getCallbackServers
func (vk *VK) GroupsGetCallbackServers(params Params) (response GroupsGetCallbackServersResponse, err error) {
err = vk.RequestUnmarshal("groups.getCallbackServers", &response, params)
return
}
// GroupsGetCallbackSettingsResponse struct.
type GroupsGetCallbackSettingsResponse object.GroupsCallbackSettings
// GroupsGetCallbackSettings returns Callback API notifications settings.
//
// BUG(VK): MessageEdit always 0 https://vk.com/bugtracker?act=show&id=86762
//
// https://vk.com/dev/groups.getCallbackSettings
func (vk *VK) GroupsGetCallbackSettings(params Params) (response GroupsGetCallbackSettingsResponse, err error) {
err = vk.RequestUnmarshal("groups.getCallbackSettings", &response, params)
return
}
// GroupsGetCatalogResponse struct.
type GroupsGetCatalogResponse struct {
Count int `json:"count"`
Items []object.GroupsGroup `json:"items"`
}
// GroupsGetCatalog returns communities list for a catalog category.
//
// https://vk.com/dev/groups.getCatalog
func (vk *VK) GroupsGetCatalog(params Params) (response GroupsGetCatalogResponse, err error) {
err = vk.RequestUnmarshal("groups.getCatalog", &response, params)
return
}
// GroupsGetCatalogInfoResponse struct.
type GroupsGetCatalogInfoResponse struct {
Enabled object.BaseBoolInt `json:"enabled"`
Categories []object.GroupsGroupCategory `json:"categories"`
}
// GroupsGetCatalogInfo returns categories list for communities catalog.
//
// extended=0
//
// https://vk.com/dev/groups.getCatalogInfo
func (vk *VK) GroupsGetCatalogInfo(params Params) (response GroupsGetCatalogInfoResponse, err error) {
err = vk.RequestUnmarshal("groups.getCatalogInfo", &response, params, Params{"extended": false})
return
}
// GroupsGetCatalogInfoExtendedResponse struct.
type GroupsGetCatalogInfoExtendedResponse struct {
Enabled object.BaseBoolInt `json:"enabled"`
Categories []object.GroupsGroupCategoryFull `json:"categories"`
}
// GroupsGetCatalogInfoExtended returns categories list for communities catalog.
//
// extended=1
//
// https://vk.com/dev/groups.getCatalogInfo
func (vk *VK) GroupsGetCatalogInfoExtended(params Params) (response GroupsGetCatalogInfoExtendedResponse, err error) {
err = vk.RequestUnmarshal("groups.getCatalogInfo", &response, params, Params{"extended": true})
return
}
// GroupsGetInvitedUsersResponse struct.
type GroupsGetInvitedUsersResponse struct {
Count int `json:"count"`
Items []object.UsersUser `json:"items"`
}
// GroupsGetInvitedUsers returns invited users list of a community.
//
// https://vk.com/dev/groups.getInvitedUsers
func (vk *VK) GroupsGetInvitedUsers(params Params) (response GroupsGetInvitedUsersResponse, err error) {
err = vk.RequestUnmarshal("groups.getInvitedUsers", &response, params)
return
}
// GroupsGetInvitesResponse struct.
type GroupsGetInvitesResponse struct {
Count int `json:"count"`
Items []object.GroupsGroupXtrInvitedBy `json:"items"`
}
// GroupsGetInvites returns a list of invitations to join communities and events.
//
// https://vk.com/dev/groups.getInvites
func (vk *VK) GroupsGetInvites(params Params) (response GroupsGetInvitesResponse, err error) {
err = vk.RequestUnmarshal("groups.getInvites", &response, params)
return
}
// GroupsGetInvitesExtendedResponse struct.
type GroupsGetInvitesExtendedResponse struct {
Count int `json:"count"`
Items []object.GroupsGroupXtrInvitedBy `json:"items"`
object.ExtendedResponse
}
// GroupsGetInvitesExtended returns a list of invitations to join communities and events.
//
// https://vk.com/dev/groups.getInvites
func (vk *VK) GroupsGetInvitesExtended(params Params) (response GroupsGetInvitesExtendedResponse, err error) {
err = vk.RequestUnmarshal("groups.getInvites", &response, params)
return
}
// GroupsGetLongPollServerResponse struct.
type GroupsGetLongPollServerResponse object.GroupsLongPollServer
// GroupsGetLongPollServer returns data for Bots Long Poll API connection.
//
// https://vk.com/dev/groups.getLongPollServer
func (vk *VK) GroupsGetLongPollServer(params Params) (response GroupsGetLongPollServerResponse, err error) {
err = vk.RequestUnmarshal("groups.getLongPollServer", &response, params)
return
}
// GroupsGetLongPollSettingsResponse struct.
type GroupsGetLongPollSettingsResponse object.GroupsLongPollSettings
// GroupsGetLongPollSettings returns Bots Long Poll API settings.
//
// https://vk.com/dev/groups.getLongPollSettings
func (vk *VK) GroupsGetLongPollSettings(params Params) (response GroupsGetLongPollSettingsResponse, err error) {
err = vk.RequestUnmarshal("groups.getLongPollSettings", &response, params)
return
}
// GroupsGetMembersResponse struct.
type GroupsGetMembersResponse struct {
Count int `json:"count"`
Items []int `json:"items"`
}
// GroupsGetMembers returns a list of community members.
//
// https://vk.com/dev/groups.getMembers
func (vk *VK) GroupsGetMembers(params Params) (response GroupsGetMembersResponse, err error) {
err = vk.RequestUnmarshal("groups.getMembers", &response, params, Params{"filter": ""})
return
}
// GroupsGetMembersFieldsResponse struct.
type GroupsGetMembersFieldsResponse struct {
Count int `json:"count"`
Items []object.UsersUser `json:"items"`
}
// GroupsGetMembersFields returns a list of community members.
//
// https://vk.com/dev/groups.getMembers
func (vk *VK) GroupsGetMembersFields(params Params) (response GroupsGetMembersFieldsResponse, err error) {
reqParams := make(Params)
if v, prs := params["fields"]; v == "" || !prs {
reqParams["fields"] = "id"
}
err = vk.RequestUnmarshal("groups.getMembers", &response, params, reqParams)
return
}
// GroupsGetMembersFilterManagersResponse struct.
type GroupsGetMembersFilterManagersResponse struct {
Count int `json:"count"`
Items []object.GroupsMemberRoleXtrUsersUser `json:"items"`
}
// GroupsGetMembersFilterManagers returns a list of community members.
//
// filter=managers
//
// https://vk.com/dev/groups.getMembers
func (vk *VK) GroupsGetMembersFilterManagers(params Params) (
response GroupsGetMembersFilterManagersResponse,
err error,
) {
err = vk.RequestUnmarshal("groups.getMembers", &response, params, Params{"filter": "managers"})
return
}
// GroupsGetOnlineStatusResponse struct.
type GroupsGetOnlineStatusResponse object.GroupsOnlineStatus
// GroupsGetOnlineStatus returns a community's online status.
//
// https://vk.com/dev/groups.getOnlineStatus
func (vk *VK) GroupsGetOnlineStatus(params Params) (response GroupsGetOnlineStatusResponse, err error) {
err = vk.RequestUnmarshal("groups.getOnlineStatus", &response, params)
return
}
// GroupsGetRequestsResponse struct.
type GroupsGetRequestsResponse struct {
Count int `json:"count"`
Items []int `json:"items"`
}
// GroupsGetRequests returns a list of requests to the community.
//
// https://vk.com/dev/groups.getRequests
func (vk *VK) GroupsGetRequests(params Params) (response GroupsGetRequestsResponse, err error) {
err = vk.RequestUnmarshal("groups.getRequests", &response, params, Params{"fields": ""})
return
}
// GroupsGetRequestsFieldsResponse struct.
type GroupsGetRequestsFieldsResponse struct {
Count int `json:"count"`
Items []object.UsersUser `json:"items"`
}
// GroupsGetRequestsFields returns a list of requests to the community.
//
// https://vk.com/dev/groups.getRequests
func (vk *VK) GroupsGetRequestsFields(params Params) (response GroupsGetRequestsFieldsResponse, err error) {
reqParams := make(Params)
if v, prs := params["fields"]; v == "" || !prs {
reqParams["fields"] = "id"
}
err = vk.RequestUnmarshal("groups.getRequests", &response, params, reqParams)
return
}
// GroupsGetSettingsResponse struct.
type GroupsGetSettingsResponse object.GroupsGroupSettings
// GroupsGetSettings returns community settings.
//
// https://vk.com/dev/groups.getSettings
func (vk *VK) GroupsGetSettings(params Params) (response GroupsGetSettingsResponse, err error) {
err = vk.RequestUnmarshal("groups.getSettings", &response, params)
return
}
// GroupsGetTagListResponse struct.
type GroupsGetTagListResponse []object.GroupsTag
// GroupsGetTagList returns community tags list.
//
// https://vk.com/dev/groups.getTagList
func (vk *VK) GroupsGetTagList(params Params) (response GroupsGetTagListResponse, err error) {
err = vk.RequestUnmarshal("groups.getTagList", &response, params)
return
}
// GroupsGetTokenPermissionsResponse struct.
type GroupsGetTokenPermissionsResponse object.GroupsTokenPermissions
// GroupsGetTokenPermissions returns permissions scope for the community's access_token.
//
// https://vk.com/dev/groups.getTokenPermissions
func (vk *VK) GroupsGetTokenPermissions(params Params) (response GroupsGetTokenPermissionsResponse, err error) {
err = vk.RequestUnmarshal("groups.getTokenPermissions", &response, params)
return
}
// GroupsInvite allows to invite friends to the community.
//
// https://vk.com/dev/groups.invite
func (vk *VK) GroupsInvite(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.invite", &response, params)
return
}
// GroupsIsMember returns information specifying whether a user is a member of a community.
//
// extended=0
//
// https://vk.com/dev/groups.isMember
func (vk *VK) GroupsIsMember(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.isMember", &response, params, Params{"extended": false})
return
}
// GroupsIsMemberExtendedResponse struct.
type GroupsIsMemberExtendedResponse struct {
Invitation object.BaseBoolInt `json:"invitation"` // Information whether user has been invited to the group
Member object.BaseBoolInt `json:"member"` // Information whether user is a member of the group
Request object.BaseBoolInt `json:"request"` // Information whether user has send request to the group
CanInvite object.BaseBoolInt `json:"can_invite"` // Information whether user can be invite
CanRecall object.BaseBoolInt `json:"can_recall"` // Information whether user's invite to the group can be recalled
}
// GroupsIsMemberExtended returns information specifying whether a user is a member of a community.
//
// extended=1
//
// https://vk.com/dev/groups.isMember
func (vk *VK) GroupsIsMemberExtended(params Params) (response GroupsIsMemberExtendedResponse, err error) {
err = vk.RequestUnmarshal("groups.isMember", &response, params, Params{"extended": true})
return
}
// GroupsIsMemberUserIDsExtendedResponse struct.
type GroupsIsMemberUserIDsExtendedResponse []object.GroupsMemberStatusFull
// GroupsIsMemberUserIDsExtended returns information specifying whether a user is a member of a community.
//
// extended=1
// need user_ids
//
// https://vk.com/dev/groups.isMember
func (vk *VK) GroupsIsMemberUserIDsExtended(params Params) (response GroupsIsMemberUserIDsExtendedResponse, err error) {
err = vk.RequestUnmarshal("groups.isMember", &response, params, Params{"extended": true})
return
}
// GroupsIsMemberUserIDsResponse struct.
type GroupsIsMemberUserIDsResponse []object.GroupsMemberStatus
// GroupsIsMemberUserIDs returns information specifying whether a user is a member of a community.
//
// extended=0
// need user_ids
//
// https://vk.com/dev/groups.isMember
func (vk *VK) GroupsIsMemberUserIDs(params Params) (response GroupsIsMemberUserIDsResponse, err error) {
err = vk.RequestUnmarshal("groups.isMember", &response, params, Params{"extended": false})
return
}
// GroupsJoin with this method you can join the group or public page, and also confirm your participation in an event.
//
// https://vk.com/dev/groups.join
func (vk *VK) GroupsJoin(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.join", &response, params)
return
}
// GroupsLeave with this method you can leave a group, public page, or event.
//
// https://vk.com/dev/groups.leave
func (vk *VK) GroupsLeave(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.leave", &response, params)
return
}
// GroupsRemoveUser removes a user from the community.
//
// https://vk.com/dev/groups.removeUser
func (vk *VK) GroupsRemoveUser(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.removeUser", &response, params)
return
}
// GroupsReorderLink allows to reorder links in the community.
//
// https://vk.com/dev/groups.reorderLink
func (vk *VK) GroupsReorderLink(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.reorderLink", &response, params)
return
}
// GroupsSearchResponse struct.
type GroupsSearchResponse struct {
Count int `json:"count"`
Items []object.GroupsGroup `json:"items"`
}
// GroupsSearch returns a list of communities matching the search criteria.
//
// https://vk.com/dev/groups.search
func (vk *VK) GroupsSearch(params Params) (response GroupsSearchResponse, err error) {
err = vk.RequestUnmarshal("groups.search", &response, params)
return
}
// GroupsSetCallbackSettings allow to set notifications settings for Callback API.
//
// https://vk.com/dev/groups.setCallbackSettings
func (vk *VK) GroupsSetCallbackSettings(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.setCallbackSettings", &response, params)
return
}
// GroupsSetLongPollSettings allows to set Bots Long Poll API settings in the community.
//
// https://vk.com/dev/groups.setLongPollSettings
func (vk *VK) GroupsSetLongPollSettings(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.setLongPollSettings", &response, params)
return
}
// GroupsSetSettings sets community settings.
//
// https://vk.com/dev/groups.setSettings
func (vk *VK) GroupsSetSettings(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.setSettings", &response, params)
return
}
// GroupsSetUserNote allows to create or edit a note about a user as part
// of the user's correspondence with the community.
//
// https://vk.com/dev/groups.setUserNote
func (vk *VK) GroupsSetUserNote(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.setUserNote", &response, params)
return
}
// GroupsTagAdd allows to add a new tag to the community.
//
// https://vk.com/dev/groups.tagAdd
func (vk *VK) GroupsTagAdd(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.tagAdd", &response, params)
return
}
// GroupsTagBind allows to "bind" and "unbind" community tags to conversations.
//
// https://vk.com/dev/groups.tagBind
func (vk *VK) GroupsTagBind(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.tagBind", &response, params)
return
}
// GroupsTagDelete allows to remove a community tag
//
// The remote tag will be automatically "unbind" from all conversations to
// which it was "bind" earlier.
//
// https://vk.com/dev/groups.tagDelete
func (vk *VK) GroupsTagDelete(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.tagDelete", &response, params)
return
}
// GroupsTagUpdate allows to change an existing tag.
//
// https://vk.com/dev/groups.tagUpdate
func (vk *VK) GroupsTagUpdate(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.tagUpdate", &response, params)
return
}
// GroupsToggleMarket method.
//
// https://vk.com/dev/groups.toggleMarket
func (vk *VK) GroupsToggleMarket(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.toggleMarket", &response, params)
return
}
// GroupsUnban groups.unban.
//
// https://vk.com/dev/groups.unban
func (vk *VK) GroupsUnban(params Params) (response int, err error) {
err = vk.RequestUnmarshal("groups.unban", &response, params)
return
}

View File

@@ -0,0 +1,89 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// LeadFormsCreateResponse struct.
type LeadFormsCreateResponse struct {
FormID int `json:"form_id"`
URL string `json:"url"`
}
// LeadFormsCreate leadForms.create.
//
// https://vk.com/dev/leadForms.create
func (vk *VK) LeadFormsCreate(params Params) (response LeadFormsCreateResponse, err error) {
err = vk.RequestUnmarshal("leadForms.create", &response, params)
return
}
// LeadFormsDeleteResponse struct.
type LeadFormsDeleteResponse struct {
FormID int `json:"form_id"`
}
// LeadFormsDelete leadForms.delete.
//
// https://vk.com/dev/leadForms.delete
func (vk *VK) LeadFormsDelete(params Params) (response LeadFormsDeleteResponse, err error) {
err = vk.RequestUnmarshal("leadForms.delete", &response, params)
return
}
// LeadFormsGetResponse struct.
type LeadFormsGetResponse object.LeadFormsForm
// LeadFormsGet leadForms.get.
//
// https://vk.com/dev/leadForms.get
func (vk *VK) LeadFormsGet(params Params) (response LeadFormsGetResponse, err error) {
err = vk.RequestUnmarshal("leadForms.get", &response, params)
return
}
// LeadFormsGetLeadsResponse struct.
type LeadFormsGetLeadsResponse struct {
Leads []object.LeadFormsLead `json:"leads"`
}
// LeadFormsGetLeads leadForms.getLeads.
//
// https://vk.com/dev/leadForms.getLeads
func (vk *VK) LeadFormsGetLeads(params Params) (response LeadFormsGetLeadsResponse, err error) {
err = vk.RequestUnmarshal("leadForms.getLeads", &response, params)
return
}
// LeadFormsGetUploadURL leadForms.getUploadURL.
//
// https://vk.com/dev/leadForms.getUploadURL
func (vk *VK) LeadFormsGetUploadURL(params Params) (response string, err error) {
err = vk.RequestUnmarshal("leadForms.getUploadURL", &response, params)
return
}
// LeadFormsListResponse struct.
type LeadFormsListResponse []object.LeadFormsForm
// LeadFormsList leadForms.list.
//
// https://vk.com/dev/leadForms.list
func (vk *VK) LeadFormsList(params Params) (response LeadFormsListResponse, err error) {
err = vk.RequestUnmarshal("leadForms.list", &response, params)
return
}
// LeadFormsUpdateResponse struct.
type LeadFormsUpdateResponse struct {
FormID int `json:"form_id"`
URL string `json:"url"`
}
// LeadFormsUpdate leadForms.update.
//
// https://vk.com/dev/leadForms.update
func (vk *VK) LeadFormsUpdate(params Params) (response LeadFormsUpdateResponse, err error) {
err = vk.RequestUnmarshal("leadForms.update", &response, params)
return
}

74
vendor/github.com/SevereCloud/vksdk/v2/api/leads.go generated vendored Normal file
View File

@@ -0,0 +1,74 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// LeadsCheckUserResponse struct.
type LeadsCheckUserResponse object.LeadsChecked
// LeadsCheckUser checks if the user can start the lead.
//
// https://vk.com/dev/leads.checkUser
func (vk *VK) LeadsCheckUser(params Params) (response LeadsCheckUserResponse, err error) {
err = vk.RequestUnmarshal("leads.checkUser", &response, params)
return
}
// LeadsCompleteResponse struct.
type LeadsCompleteResponse object.LeadsComplete
// LeadsComplete completes the lead started by user.
//
// https://vk.com/dev/leads.complete
func (vk *VK) LeadsComplete(params Params) (response LeadsCompleteResponse, err error) {
err = vk.RequestUnmarshal("leads.complete", &response, params)
return
}
// LeadsGetStatsResponse struct.
type LeadsGetStatsResponse object.LeadsLead
// LeadsGetStats returns lead stats data.
//
// https://vk.com/dev/leads.getStats
func (vk *VK) LeadsGetStats(params Params) (response LeadsGetStatsResponse, err error) {
err = vk.RequestUnmarshal("leads.getStats", &response, params)
return
}
// LeadsGetUsersResponse struct.
type LeadsGetUsersResponse object.LeadsEntry
// LeadsGetUsers returns a list of last user actions for the offer.
//
// https://vk.com/dev/leads.getUsers
func (vk *VK) LeadsGetUsers(params Params) (response LeadsGetUsersResponse, err error) {
err = vk.RequestUnmarshal("leads.getUsers", &response, params)
return
}
// LeadsMetricHitResponse struct.
type LeadsMetricHitResponse struct {
Result object.BaseBoolInt `json:"result"` // Information whether request has been processed successfully
RedirectLink string `json:"redirect_link"` // Redirect link
}
// LeadsMetricHit counts the metric event.
//
// https://vk.com/dev/leads.metricHit
func (vk *VK) LeadsMetricHit(params Params) (response LeadsMetricHitResponse, err error) {
err = vk.RequestUnmarshal("leads.metricHit", &response, params)
return
}
// LeadsStartResponse struct.
type LeadsStartResponse object.LeadsStart
// LeadsStart creates new session for the user passing the offer.
//
// https://vk.com/dev/leads.start
func (vk *VK) LeadsStart(params Params) (response LeadsStartResponse, err error) {
err = vk.RequestUnmarshal("leads.start", &response, params)
return
}

79
vendor/github.com/SevereCloud/vksdk/v2/api/likes.go generated vendored Normal file
View File

@@ -0,0 +1,79 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// LikesAddResponse struct.
type LikesAddResponse struct {
Likes int `json:"likes"`
}
// LikesAdd adds the specified object to the Likes list of the current user.
//
// https://vk.com/dev/likes.add
func (vk *VK) LikesAdd(params Params) (response LikesAddResponse, err error) {
err = vk.RequestUnmarshal("likes.add", &response, params)
return
}
// LikesDeleteResponse struct.
type LikesDeleteResponse struct {
Likes int `json:"likes"`
}
// LikesDelete deletes the specified object from the Likes list of the current user.
//
// https://vk.com/dev/likes.delete
func (vk *VK) LikesDelete(params Params) (response LikesDeleteResponse, err error) {
err = vk.RequestUnmarshal("likes.delete", &response, params)
return
}
// LikesGetListResponse struct.
type LikesGetListResponse struct {
Count int `json:"count"`
Items []int `json:"items"`
}
// LikesGetList likes.getList returns a list of IDs of users who added the specified object to their Likes list.
//
// extended=0
//
// https://vk.com/dev/likes.getList
func (vk *VK) LikesGetList(params Params) (response LikesGetListResponse, err error) {
err = vk.RequestUnmarshal("likes.getList", &response, params, Params{"extended": false})
return
}
// LikesGetListExtendedResponse struct.
type LikesGetListExtendedResponse struct {
Count int `json:"count"`
Items []object.UsersUser `json:"items"`
}
// LikesGetListExtended likes.getList returns a list of IDs of users who added the specified object to their Likes list.
//
// extended=1
//
// https://vk.com/dev/likes.getList
func (vk *VK) LikesGetListExtended(params Params) (response LikesGetListExtendedResponse, err error) {
err = vk.RequestUnmarshal("likes.getList", &response, params, Params{"extended": true})
return
}
// LikesIsLikedResponse struct.
type LikesIsLikedResponse struct {
Liked object.BaseBoolInt `json:"liked"`
Copied object.BaseBoolInt `json:"copied"`
}
// LikesIsLiked checks for the object in the Likes list of the specified user.
//
// https://vk.com/dev/likes.isLiked
func (vk *VK) LikesIsLiked(params Params) (response LikesIsLikedResponse, err error) {
err = vk.RequestUnmarshal("likes.isLiked", &response, params)
return
}

320
vendor/github.com/SevereCloud/vksdk/v2/api/market.go generated vendored Normal file
View File

@@ -0,0 +1,320 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// MarketAddResponse struct.
type MarketAddResponse struct {
MarketItemID int `json:"market_item_id"` // Item ID
}
// MarketAdd adds a new item to the market.
//
// https://vk.com/dev/market.add
func (vk *VK) MarketAdd(params Params) (response MarketAddResponse, err error) {
err = vk.RequestUnmarshal("market.add", &response, params)
return
}
// MarketAddAlbumResponse struct.
type MarketAddAlbumResponse struct {
MarketAlbumID int `json:"market_album_id"` // Album ID
}
// MarketAddAlbum creates new collection of items.
//
// https://vk.com/dev/market.addAlbum
func (vk *VK) MarketAddAlbum(params Params) (response MarketAddAlbumResponse, err error) {
err = vk.RequestUnmarshal("market.addAlbum", &response, params)
return
}
// MarketAddToAlbum adds an item to one or multiple collections.
//
// https://vk.com/dev/market.addToAlbum
func (vk *VK) MarketAddToAlbum(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.addToAlbum", &response, params)
return
}
// MarketCreateComment creates a new comment for an item.
//
// https://vk.com/dev/market.createComment
func (vk *VK) MarketCreateComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.createComment", &response, params)
return
}
// MarketDelete deletes an item.
//
// https://vk.com/dev/market.delete
func (vk *VK) MarketDelete(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.delete", &response, params)
return
}
// MarketDeleteAlbum deletes a collection of items.
//
// https://vk.com/dev/market.deleteAlbum
func (vk *VK) MarketDeleteAlbum(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.deleteAlbum", &response, params)
return
}
// MarketDeleteComment deletes an item's comment.
//
// https://vk.com/dev/market.deleteComment
func (vk *VK) MarketDeleteComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.deleteComment", &response, params)
return
}
// MarketEdit edits an item.
//
// https://vk.com/dev/market.edit
func (vk *VK) MarketEdit(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.edit", &response, params)
return
}
// MarketEditAlbum edits a collection of items.
//
// https://vk.com/dev/market.editAlbum
func (vk *VK) MarketEditAlbum(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.editAlbum", &response, params)
return
}
// MarketEditComment changes item comment's text.
//
// https://vk.com/dev/market.editComment
func (vk *VK) MarketEditComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.editComment", &response, params)
return
}
// MarketEditOrder edits an order.
//
// https://vk.com/dev/market.editOrder
func (vk *VK) MarketEditOrder(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.editOrder", &response, params)
return
}
// MarketGetResponse struct.
type MarketGetResponse struct {
Count int `json:"count"`
Items []object.MarketMarketItem `json:"items"`
}
// MarketGet returns items list for a community.
//
// https://vk.com/dev/market.get
func (vk *VK) MarketGet(params Params) (response MarketGetResponse, err error) {
err = vk.RequestUnmarshal("market.get", &response, params)
return
}
// MarketGetAlbumByIDResponse struct.
type MarketGetAlbumByIDResponse struct {
Count int `json:"count"`
Items []object.MarketMarketAlbum `json:"items"`
}
// MarketGetAlbumByID returns items album's data.
//
// https://vk.com/dev/market.getAlbumById
func (vk *VK) MarketGetAlbumByID(params Params) (response MarketGetAlbumByIDResponse, err error) {
err = vk.RequestUnmarshal("market.getAlbumById", &response, params)
return
}
// MarketGetAlbumsResponse struct.
type MarketGetAlbumsResponse struct {
Count int `json:"count"`
Items []object.MarketMarketAlbum `json:"items"`
}
// MarketGetAlbums returns community's collections list.
//
// https://vk.com/dev/market.getAlbums
func (vk *VK) MarketGetAlbums(params Params) (response MarketGetAlbumsResponse, err error) {
err = vk.RequestUnmarshal("market.getAlbums", &response, params)
return
}
// MarketGetByIDResponse struct.
type MarketGetByIDResponse struct {
Count int `json:"count"`
Items []object.MarketMarketItem `json:"items"`
}
// MarketGetByID returns information about market items by their iDs.
//
// https://vk.com/dev/market.getById
func (vk *VK) MarketGetByID(params Params) (response MarketGetByIDResponse, err error) {
err = vk.RequestUnmarshal("market.getById", &response, params)
return
}
// MarketGetCategoriesResponse struct.
type MarketGetCategoriesResponse struct {
Count int `json:"count"`
Items []object.MarketMarketCategory `json:"items"`
}
// MarketGetCategories returns a list of market categories.
//
// https://vk.com/dev/market.getCategories
func (vk *VK) MarketGetCategories(params Params) (response MarketGetCategoriesResponse, err error) {
err = vk.RequestUnmarshal("market.getCategories", &response, params)
return
}
// MarketGetCommentsResponse struct.
type MarketGetCommentsResponse struct {
Count int `json:"count"`
Items []object.WallWallComment `json:"items"`
}
// MarketGetComments returns comments list for an item.
//
// extended=0
//
// https://vk.com/dev/market.getComments
func (vk *VK) MarketGetComments(params Params) (response MarketGetCommentsResponse, err error) {
err = vk.RequestUnmarshal("market.getComments", &response, params, Params{"extended": false})
return
}
// MarketGetCommentsExtendedResponse struct.
type MarketGetCommentsExtendedResponse struct {
Count int `json:"count"`
Items []object.WallWallComment `json:"items"`
object.ExtendedResponse
}
// MarketGetCommentsExtended returns comments list for an item.
//
// extended=1
//
// https://vk.com/dev/market.getComments
func (vk *VK) MarketGetCommentsExtended(params Params) (response MarketGetCommentsExtendedResponse, err error) {
err = vk.RequestUnmarshal("market.getComments", &response, params, Params{"extended": true})
return
}
// MarketGetGroupOrdersResponse struct.
type MarketGetGroupOrdersResponse struct {
Count int `json:"count"`
Items []object.MarketOrder `json:"items"`
}
// MarketGetGroupOrders returns community's orders list.
//
// https://vk.com/dev/market.getGroupOrders
func (vk *VK) MarketGetGroupOrders(params Params) (response MarketGetGroupOrdersResponse, err error) {
err = vk.RequestUnmarshal("market.getGroupOrders", &response, params)
return
}
// MarketGetOrderByIDResponse struct.
type MarketGetOrderByIDResponse struct {
Order object.MarketOrder `json:"order"`
}
// MarketGetOrderByID returns order by id.
//
// https://vk.com/dev/market.getOrderById
func (vk *VK) MarketGetOrderByID(params Params) (response MarketGetOrderByIDResponse, err error) {
err = vk.RequestUnmarshal("market.getOrderById", &response, params)
return
}
// MarketGetOrderItemsResponse struct.
type MarketGetOrderItemsResponse struct {
Count int `json:"count"`
Items []object.MarketOrderItem `json:"items"`
}
// MarketGetOrderItems returns items of an order.
//
// https://vk.com/dev/market.getOrderItems
func (vk *VK) MarketGetOrderItems(params Params) (response MarketGetOrderItemsResponse, err error) {
err = vk.RequestUnmarshal("market.getOrderItems", &response, params)
return
}
// MarketRemoveFromAlbum removes an item from one or multiple collections.
//
// https://vk.com/dev/market.removeFromAlbum
func (vk *VK) MarketRemoveFromAlbum(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.removeFromAlbum", &response, params)
return
}
// MarketReorderAlbums reorders the collections list.
//
// https://vk.com/dev/market.reorderAlbums
func (vk *VK) MarketReorderAlbums(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.reorderAlbums", &response, params)
return
}
// MarketReorderItems changes item place in a collection.
//
// https://vk.com/dev/market.reorderItems
func (vk *VK) MarketReorderItems(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.reorderItems", &response, params)
return
}
// MarketReport sends a complaint to the item.
//
// https://vk.com/dev/market.report
func (vk *VK) MarketReport(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.report", &response, params)
return
}
// MarketReportComment sends a complaint to the item's comment.
//
// https://vk.com/dev/market.reportComment
func (vk *VK) MarketReportComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.reportComment", &response, params)
return
}
// MarketRestore restores recently deleted item.
//
// https://vk.com/dev/market.restore
func (vk *VK) MarketRestore(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.restore", &response, params)
return
}
// MarketRestoreComment restores a recently deleted comment.
//
// https://vk.com/dev/market.restoreComment
func (vk *VK) MarketRestoreComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("market.restoreComment", &response, params)
return
}
// MarketSearchResponse struct.
type MarketSearchResponse struct {
Count int `json:"count"`
Items []object.MarketMarketItem `json:"items"`
ViewType int `json:"view_type"`
}
// MarketSearch searches market items in a community's catalog.
//
// https://vk.com/dev/market.search
func (vk *VK) MarketSearch(params Params) (response MarketSearchResponse, err error) {
err = vk.RequestUnmarshal("market.search", &response, params)
return
}

616
vendor/github.com/SevereCloud/vksdk/v2/api/messages.go generated vendored Normal file
View File

@@ -0,0 +1,616 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// MessagesAddChatUser adds a new user to a chat.
//
// https://vk.com/dev/messages.addChatUser
func (vk *VK) MessagesAddChatUser(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.addChatUser", &response, params)
return
}
// MessagesAllowMessagesFromGroup allows sending messages from community to the current user.
//
// https://vk.com/dev/messages.allowMessagesFromGroup
func (vk *VK) MessagesAllowMessagesFromGroup(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.allowMessagesFromGroup", &response, params)
return
}
// MessagesCreateChat creates a chat with several participants.
//
// https://vk.com/dev/messages.createChat
func (vk *VK) MessagesCreateChat(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.createChat", &response, params)
return
}
// MessagesDeleteResponse struct.
type MessagesDeleteResponse map[string]int
// MessagesDelete deletes one or more messages.
//
// https://vk.com/dev/messages.delete
func (vk *VK) MessagesDelete(params Params) (response MessagesDeleteResponse, err error) {
err = vk.RequestUnmarshal("messages.delete", &response, params)
return
}
// MessagesDeleteChatPhotoResponse struct.
type MessagesDeleteChatPhotoResponse struct {
MessageID int `json:"message_id"`
Chat object.MessagesChat `json:"chat"`
}
// MessagesDeleteChatPhoto deletes a chat's cover picture.
//
// https://vk.com/dev/messages.deleteChatPhoto
func (vk *VK) MessagesDeleteChatPhoto(params Params) (response MessagesDeleteChatPhotoResponse, err error) {
err = vk.RequestUnmarshal("messages.deleteChatPhoto", &response, params)
return
}
// MessagesDeleteConversationResponse struct.
type MessagesDeleteConversationResponse struct {
LastDeletedID int `json:"last_deleted_id"` // Id of the last message, that was deleted
}
// MessagesDeleteConversation deletes private messages in a conversation.
//
// https://vk.com/dev/messages.deleteConversation
func (vk *VK) MessagesDeleteConversation(params Params) (response MessagesDeleteConversationResponse, err error) {
err = vk.RequestUnmarshal("messages.deleteConversation", &response, params)
return
}
// MessagesDenyMessagesFromGroup denies sending message from community to the current user.
//
// https://vk.com/dev/messages.denyMessagesFromGroup
func (vk *VK) MessagesDenyMessagesFromGroup(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.denyMessagesFromGroup", &response, params)
return
}
// MessagesEdit edits the message.
//
// https://vk.com/dev/messages.edit
func (vk *VK) MessagesEdit(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.edit", &response, params)
return
}
// MessagesEditChat edits the title of a chat.
//
// https://vk.com/dev/messages.editChat
func (vk *VK) MessagesEditChat(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.editChat", &response, params)
return
}
// MessagesGetByConversationMessageIDResponse struct.
type MessagesGetByConversationMessageIDResponse struct {
Count int `json:"count"`
Items []object.MessagesMessage `json:"items"`
object.ExtendedResponse
}
// MessagesGetByConversationMessageID messages.getByConversationMessageId.
//
// https://vk.com/dev/messages.getByConversationMessageId
func (vk *VK) MessagesGetByConversationMessageID(params Params) (
response MessagesGetByConversationMessageIDResponse,
err error,
) {
err = vk.RequestUnmarshal("messages.getByConversationMessageId", &response, params)
return
}
// MessagesGetByIDResponse struct.
type MessagesGetByIDResponse struct {
Count int `json:"count"`
Items []object.MessagesMessage `json:"items"`
}
// MessagesGetByID returns messages by their IDs.
//
// extended=0
//
// https://vk.com/dev/messages.getById
func (vk *VK) MessagesGetByID(params Params) (response MessagesGetByIDResponse, err error) {
err = vk.RequestUnmarshal("messages.getById", &response, params, Params{"extended": false})
return
}
// MessagesGetByIDExtendedResponse struct.
type MessagesGetByIDExtendedResponse struct {
Count int `json:"count"`
Items []object.MessagesMessage `json:"items"`
object.ExtendedResponse
}
// MessagesGetByIDExtended returns messages by their IDs.
//
// extended=1
//
// https://vk.com/dev/messages.getById
func (vk *VK) MessagesGetByIDExtended(params Params) (response MessagesGetByIDExtendedResponse, err error) {
err = vk.RequestUnmarshal("messages.getById", &response, params, Params{"extended": true})
return
}
// MessagesGetChatResponse struct.
type MessagesGetChatResponse object.MessagesChat
// MessagesGetChat returns information about a chat.
//
// https://vk.com/dev/messages.getChat
func (vk *VK) MessagesGetChat(params Params) (response MessagesGetChatResponse, err error) {
err = vk.RequestUnmarshal("messages.getChat", &response, params)
return
}
// MessagesGetChatChatIDsResponse struct.
type MessagesGetChatChatIDsResponse []object.MessagesChat
// MessagesGetChatChatIDs returns information about a chat.
//
// https://vk.com/dev/messages.getChat
func (vk *VK) MessagesGetChatChatIDs(params Params) (response MessagesGetChatChatIDsResponse, err error) {
err = vk.RequestUnmarshal("messages.getChat", &response, params)
return
}
// MessagesGetChatPreviewResponse struct.
type MessagesGetChatPreviewResponse struct {
Preview object.MessagesChatPreview `json:"preview"`
object.ExtendedResponse
}
// MessagesGetChatPreview allows to receive chat preview by the invitation link.
//
// https://vk.com/dev/messages.getChatPreview
func (vk *VK) MessagesGetChatPreview(params Params) (response MessagesGetChatPreviewResponse, err error) {
err = vk.RequestUnmarshal("messages.getChatPreview", &response, params)
return
}
// MessagesGetConversationMembersResponse struct.
type MessagesGetConversationMembersResponse struct {
Items []struct {
MemberID int `json:"member_id"`
JoinDate int `json:"join_date"`
InvitedBy int `json:"invited_by"`
IsOwner object.BaseBoolInt `json:"is_owner,omitempty"`
IsAdmin object.BaseBoolInt `json:"is_admin,omitempty"`
CanKick object.BaseBoolInt `json:"can_kick,omitempty"`
} `json:"items"`
Count int `json:"count"`
ChatRestrictions struct {
OnlyAdminsInvite object.BaseBoolInt `json:"only_admins_invite"`
OnlyAdminsEditPin object.BaseBoolInt `json:"only_admins_edit_pin"`
OnlyAdminsEditInfo object.BaseBoolInt `json:"only_admins_edit_info"`
AdminsPromoteUsers object.BaseBoolInt `json:"admins_promote_users"`
} `json:"chat_restrictions"`
object.ExtendedResponse
}
// MessagesGetConversationMembers returns a list of IDs of users participating in a conversation.
//
// https://vk.com/dev/messages.getConversationMembers
func (vk *VK) MessagesGetConversationMembers(params Params) (
response MessagesGetConversationMembersResponse,
err error,
) {
err = vk.RequestUnmarshal("messages.getConversationMembers", &response, params)
return
}
// MessagesGetConversationsResponse struct.
type MessagesGetConversationsResponse struct {
Count int `json:"count"`
Items []object.MessagesConversationWithMessage `json:"items"`
UnreadCount int `json:"unread_count"`
object.ExtendedResponse
}
// MessagesGetConversations returns a list of conversations.
//
// https://vk.com/dev/messages.getConversations
func (vk *VK) MessagesGetConversations(params Params) (response MessagesGetConversationsResponse, err error) {
err = vk.RequestUnmarshal("messages.getConversations", &response, params)
return
}
// MessagesGetConversationsByIDResponse struct.
type MessagesGetConversationsByIDResponse struct {
Count int `json:"count"`
Items []object.MessagesConversation `json:"items"`
}
// MessagesGetConversationsByID returns conversations by their IDs.
//
// extended=0
//
// https://vk.com/dev/messages.getConversationsById
func (vk *VK) MessagesGetConversationsByID(params Params) (response MessagesGetConversationsByIDResponse, err error) {
err = vk.RequestUnmarshal("messages.getConversationsById", &response, params, Params{"extended": false})
return
}
// MessagesGetConversationsByIDExtendedResponse struct.
type MessagesGetConversationsByIDExtendedResponse struct {
Count int `json:"count"`
Items []object.MessagesConversation `json:"items"`
object.ExtendedResponse
}
// MessagesGetConversationsByIDExtended returns conversations by their IDs.
//
// extended=1
//
// https://vk.com/dev/messages.getConversationsById
func (vk *VK) MessagesGetConversationsByIDExtended(params Params) (
response MessagesGetConversationsByIDExtendedResponse,
err error,
) {
err = vk.RequestUnmarshal("messages.getConversationsById", &response, params, Params{"extended": true})
return
}
// MessagesGetHistoryResponse struct.
type MessagesGetHistoryResponse struct {
Count int `json:"count"`
Items []object.MessagesMessage `json:"items"`
// extended=1
object.ExtendedResponse
// extended=1
Conversations []object.MessagesConversation `json:"conversations,omitempty"`
// Deprecated: use .Conversations.InRead
InRead int `json:"in_read,omitempty"`
// Deprecated: use .Conversations.OutRead
OutRead int `json:"out_read,omitempty"`
}
// MessagesGetHistory returns message history for the specified user or group chat.
//
// https://vk.com/dev/messages.getHistory
func (vk *VK) MessagesGetHistory(params Params) (response MessagesGetHistoryResponse, err error) {
err = vk.RequestUnmarshal("messages.getHistory", &response, params)
return
}
// MessagesGetHistoryAttachmentsResponse struct.
type MessagesGetHistoryAttachmentsResponse struct {
Items []object.MessagesHistoryAttachment `json:"items"`
NextFrom string `json:"next_from"`
object.ExtendedResponse
}
// MessagesGetHistoryAttachments returns media files from the dialog or group chat.
//
// https://vk.com/dev/messages.getHistoryAttachments
func (vk *VK) MessagesGetHistoryAttachments(params Params) (response MessagesGetHistoryAttachmentsResponse, err error) {
err = vk.RequestUnmarshal("messages.getHistoryAttachments", &response, params)
return
}
// MessagesGetImportantMessagesResponse struct.
type MessagesGetImportantMessagesResponse struct {
Messages struct {
Count int `json:"count"`
Items []object.MessagesMessage `json:"items"`
} `json:"messages"`
Conversations []object.MessagesConversation `json:"conversations"`
object.ExtendedResponse
}
// MessagesGetImportantMessages messages.getImportantMessages.
//
// https://vk.com/dev/messages.getImportantMessages
func (vk *VK) MessagesGetImportantMessages(params Params) (response MessagesGetImportantMessagesResponse, err error) {
err = vk.RequestUnmarshal("messages.getImportantMessages", &response, params)
return
}
// MessagesGetIntentUsersResponse struct.
type MessagesGetIntentUsersResponse struct {
Count int `json:"count"`
Items []int `json:"items"`
Profiles []object.MessagesMessage `json:"profiles,omitempty"`
}
// MessagesGetIntentUsers method.
//
// https://vk.com/dev/messages.getIntentUsers
func (vk *VK) MessagesGetIntentUsers(params Params) (response MessagesGetIntentUsersResponse, err error) {
err = vk.RequestUnmarshal("messages.getIntentUsers", &response, params)
return
}
// MessagesGetInviteLinkResponse struct.
type MessagesGetInviteLinkResponse struct {
Link string `json:"link"`
}
// MessagesGetInviteLink receives a link to invite a user to the chat.
//
// https://vk.com/dev/messages.getInviteLink
func (vk *VK) MessagesGetInviteLink(params Params) (response MessagesGetInviteLinkResponse, err error) {
err = vk.RequestUnmarshal("messages.getInviteLink", &response, params)
return
}
// MessagesGetLastActivityResponse struct.
type MessagesGetLastActivityResponse object.MessagesLastActivity
// MessagesGetLastActivity returns a user's current status and date of last activity.
//
// https://vk.com/dev/messages.getLastActivity
func (vk *VK) MessagesGetLastActivity(params Params) (response MessagesGetLastActivityResponse, err error) {
err = vk.RequestUnmarshal("messages.getLastActivity", &response, params)
return
}
// MessagesGetLongPollHistoryResponse struct.
type MessagesGetLongPollHistoryResponse struct {
History [][]int `json:"history"`
Groups []object.GroupsGroup `json:"groups"`
Messages struct {
Count int `json:"count"`
Items []object.MessagesMessage `json:"items"`
} `json:"messages"`
Profiles []object.UsersUser `json:"profiles"`
// Chats struct {} `json:"chats"`
NewPTS int `json:"new_pts"`
FromPTS int `json:"from_pts"`
More object.BaseBoolInt `json:"chats"`
Conversations []object.MessagesConversation `json:"conversations"`
}
// MessagesGetLongPollHistory returns updates in user's private messages.
//
// https://vk.com/dev/messages.getLongPollHistory
func (vk *VK) MessagesGetLongPollHistory(params Params) (response MessagesGetLongPollHistoryResponse, err error) {
err = vk.RequestUnmarshal("messages.getLongPollHistory", &response, params)
return
}
// MessagesGetLongPollServerResponse struct.
type MessagesGetLongPollServerResponse object.MessagesLongPollParams
// MessagesGetLongPollServer returns data required for connection to a Long Poll server.
//
// https://vk.com/dev/messages.getLongPollServer
func (vk *VK) MessagesGetLongPollServer(params Params) (response MessagesGetLongPollServerResponse, err error) {
err = vk.RequestUnmarshal("messages.getLongPollServer", &response, params)
return
}
// MessagesIsMessagesFromGroupAllowedResponse struct.
type MessagesIsMessagesFromGroupAllowedResponse struct {
IsAllowed object.BaseBoolInt `json:"is_allowed"`
}
// MessagesIsMessagesFromGroupAllowed returns information whether
// sending messages from the community to current user is allowed.
//
// https://vk.com/dev/messages.isMessagesFromGroupAllowed
func (vk *VK) MessagesIsMessagesFromGroupAllowed(params Params) (
response MessagesIsMessagesFromGroupAllowedResponse,
err error,
) {
err = vk.RequestUnmarshal("messages.isMessagesFromGroupAllowed", &response, params)
return
}
// MessagesJoinChatByInviteLinkResponse struct.
type MessagesJoinChatByInviteLinkResponse struct {
ChatID int `json:"chat_id"`
}
// MessagesJoinChatByInviteLink allows to enter the chat by the invitation link.
//
// https://vk.com/dev/messages.joinChatByInviteLink
func (vk *VK) MessagesJoinChatByInviteLink(params Params) (response MessagesJoinChatByInviteLinkResponse, err error) {
err = vk.RequestUnmarshal("messages.joinChatByInviteLink", &response, params)
return
}
// MessagesMarkAsAnsweredConversation messages.markAsAnsweredConversation.
//
// https://vk.com/dev/messages.markAsAnsweredConversation
func (vk *VK) MessagesMarkAsAnsweredConversation(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.markAsAnsweredConversation", &response, params)
return
}
// MessagesMarkAsImportantResponse struct.
type MessagesMarkAsImportantResponse []int
// MessagesMarkAsImportant marks and un marks messages as important (starred).
//
// https://vk.com/dev/messages.markAsImportant
func (vk *VK) MessagesMarkAsImportant(params Params) (response MessagesMarkAsImportantResponse, err error) {
err = vk.RequestUnmarshal("messages.markAsImportant", &response, params)
return
}
// MessagesMarkAsImportantConversation messages.markAsImportantConversation.
//
// https://vk.com/dev/messages.markAsImportantConversation
func (vk *VK) MessagesMarkAsImportantConversation(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.markAsImportantConversation", &response, params)
return
}
// MessagesMarkAsRead marks messages as read.
//
// https://vk.com/dev/messages.markAsRead
func (vk *VK) MessagesMarkAsRead(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.markAsRead", &response, params)
return
}
// MessagesPinResponse struct.
type MessagesPinResponse object.MessagesMessage
// MessagesPin messages.pin.
//
// https://vk.com/dev/messages.pin
func (vk *VK) MessagesPin(params Params) (response MessagesPinResponse, err error) {
err = vk.RequestUnmarshal("messages.pin", &response, params)
return
}
// MessagesRemoveChatUser allows the current user to leave a chat or, if the
// current user started the chat, allows the user to remove another user from
// the chat.
//
// https://vk.com/dev/messages.removeChatUser
func (vk *VK) MessagesRemoveChatUser(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.removeChatUser", &response, params)
return
}
// MessagesRestore restores a deleted message.
//
// https://vk.com/dev/messages.restore
func (vk *VK) MessagesRestore(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.restore", &response, params)
return
}
// MessagesSearchResponse struct.
type MessagesSearchResponse struct {
Count int `json:"count"`
Items []object.MessagesMessage `json:"items"`
object.ExtendedResponse
Conversations []object.MessagesConversation `json:"conversations,omitempty"`
}
// MessagesSearch returns a list of the current user's private messages that match search criteria.
//
// https://vk.com/dev/messages.search
func (vk *VK) MessagesSearch(params Params) (response MessagesSearchResponse, err error) {
err = vk.RequestUnmarshal("messages.search", &response, params)
return
}
// MessagesSearchConversationsResponse struct.
type MessagesSearchConversationsResponse struct {
Count int `json:"count"`
Items []object.MessagesConversation `json:"items"`
object.ExtendedResponse
}
// MessagesSearchConversations returns a list of conversations that match search criteria.
//
// https://vk.com/dev/messages.searchConversations
func (vk *VK) MessagesSearchConversations(params Params) (response MessagesSearchConversationsResponse, err error) {
err = vk.RequestUnmarshal("messages.searchConversations", &response, params)
return
}
// MessagesSend sends a message.
//
// For user_ids or peer_ids parameters, use MessagesSendUserIDs.
//
// https://vk.com/dev/messages.send
func (vk *VK) MessagesSend(params Params) (response int, err error) {
reqParams := Params{
"user_ids": "",
"peer_ids": "",
}
err = vk.RequestUnmarshal("messages.send", &response, params, reqParams)
return
}
// MessagesSendUserIDsResponse struct.
//
// TODO: v3 rename MessagesSendPeerIDsResponse - user_ids outdated.
type MessagesSendUserIDsResponse []struct {
PeerID int `json:"peer_id"`
MessageID int `json:"message_id"`
ConversationMessageID int `json:"conversation_message_id"`
Error Error `json:"error"`
}
// MessagesSendPeerIDs sends a message.
//
// need peer_ids;
//
// https://vk.com/dev/messages.send
func (vk *VK) MessagesSendPeerIDs(params Params) (response MessagesSendUserIDsResponse, err error) {
err = vk.RequestUnmarshal("messages.send", &response, params)
return
}
// MessagesSendUserIDs sends a message.
//
// need user_ids or peer_ids;
//
// https://vk.com/dev/messages.send
//
// Deprecated: user_ids outdated, use MessagesSendPeerIDs.
func (vk *VK) MessagesSendUserIDs(params Params) (response MessagesSendUserIDsResponse, err error) {
return vk.MessagesSendPeerIDs(params)
}
// MessagesSendMessageEventAnswer method.
//
// https://vk.com/dev/messages.sendMessageEventAnswer
func (vk *VK) MessagesSendMessageEventAnswer(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.sendMessageEventAnswer", &response, params)
return
}
// MessagesSendSticker sends a message.
//
// https://vk.com/dev/messages.sendSticker
func (vk *VK) MessagesSendSticker(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.sendSticker", &response, params, Params{"user_ids": ""})
return
}
// MessagesSetActivity changes the status of a user as typing in a conversation.
//
// https://vk.com/dev/messages.setActivity
func (vk *VK) MessagesSetActivity(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.setActivity", &response, params)
return
}
// MessagesSetChatPhotoResponse struct.
type MessagesSetChatPhotoResponse struct {
MessageID int `json:"message_id"`
Chat object.MessagesChat `json:"chat"`
}
// MessagesSetChatPhoto sets a previously-uploaded picture as the cover picture of a chat.
//
// https://vk.com/dev/messages.setChatPhoto
func (vk *VK) MessagesSetChatPhoto(params Params) (response MessagesSetChatPhotoResponse, err error) {
err = vk.RequestUnmarshal("messages.setChatPhoto", &response, params)
return
}
// MessagesUnpin messages.unpin.
//
// https://vk.com/dev/messages.unpin
func (vk *VK) MessagesUnpin(params Params) (response int, err error) {
err = vk.RequestUnmarshal("messages.unpin", &response, params)
return
}

230
vendor/github.com/SevereCloud/vksdk/v2/api/newsfeed.go generated vendored Normal file
View File

@@ -0,0 +1,230 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// NewsfeedAddBan prevents news from specified users and communities
// from appearing in the current user's newsfeed.
//
// https://vk.com/dev/newsfeed.addBan
func (vk *VK) NewsfeedAddBan(params Params) (response int, err error) {
err = vk.RequestUnmarshal("newsfeed.addBan", &response, params)
return
}
// NewsfeedDeleteBan allows news from previously banned users and
// communities to be shown in the current user's newsfeed.
//
// https://vk.com/dev/newsfeed.deleteBan
func (vk *VK) NewsfeedDeleteBan(params Params) (response int, err error) {
err = vk.RequestUnmarshal("newsfeed.deleteBan", &response, params)
return
}
// NewsfeedDeleteList the method allows you to delete a custom news list.
//
// https://vk.com/dev/newsfeed.deleteList
func (vk *VK) NewsfeedDeleteList(params Params) (response int, err error) {
err = vk.RequestUnmarshal("newsfeed.deleteList", &response, params)
return
}
// NewsfeedGetResponse struct.
type NewsfeedGetResponse struct {
Items []object.NewsfeedNewsfeedItem `json:"items"`
object.ExtendedResponse
NextFrom string `json:"next_from"`
}
// NewsfeedGet returns data required to show newsfeed for the current user.
//
// https://vk.com/dev/newsfeed.get
func (vk *VK) NewsfeedGet(params Params) (response NewsfeedGetResponse, err error) {
err = vk.RequestUnmarshal("newsfeed.get", &response, params)
return
}
// NewsfeedGetBannedResponse struct.
type NewsfeedGetBannedResponse struct {
Members []int `json:"members"`
Groups []int `json:"groups"`
}
// NewsfeedGetBanned returns a list of users and communities banned from the current user's newsfeed.
//
// extended=0
//
// https://vk.com/dev/newsfeed.getBanned
func (vk *VK) NewsfeedGetBanned(params Params) (response NewsfeedGetBannedResponse, err error) {
err = vk.RequestUnmarshal("newsfeed.getBanned", &response, params, Params{"extended": false})
return
}
// NewsfeedGetBannedExtendedResponse struct.
type NewsfeedGetBannedExtendedResponse struct {
object.ExtendedResponse
}
// NewsfeedGetBannedExtended returns a list of users and communities banned from the current user's newsfeed.
//
// extended=1
//
// https://vk.com/dev/newsfeed.getBanned
func (vk *VK) NewsfeedGetBannedExtended(params Params) (response NewsfeedGetBannedExtendedResponse, err error) {
err = vk.RequestUnmarshal("newsfeed.getBanned", &response, params, Params{"extended": true})
return
}
// NewsfeedGetCommentsResponse struct.
type NewsfeedGetCommentsResponse struct {
Items []object.NewsfeedNewsfeedItem `json:"items"`
object.ExtendedResponse
NextFrom string `json:"next_from"`
}
// NewsfeedGetComments returns a list of comments in the current user's newsfeed.
//
// https://vk.com/dev/newsfeed.getComments
func (vk *VK) NewsfeedGetComments(params Params) (response NewsfeedGetCommentsResponse, err error) {
err = vk.RequestUnmarshal("newsfeed.getComments", &response, params)
return
}
// NewsfeedGetListsResponse struct.
type NewsfeedGetListsResponse struct {
Count int `json:"count"`
Items []struct {
ID int `json:"id"`
Title string `json:"title"`
NoReposts int `json:"no_reposts"`
SourceIDs []int `json:"source_ids"`
} `json:"items"`
}
// NewsfeedGetLists returns a list of newsfeeds followed by the current user.
//
// https://vk.com/dev/newsfeed.getLists
func (vk *VK) NewsfeedGetLists(params Params) (response NewsfeedGetListsResponse, err error) {
err = vk.RequestUnmarshal("newsfeed.getLists", &response, params)
return
}
// NewsfeedGetMentionsResponse struct.
type NewsfeedGetMentionsResponse struct {
Count int `json:"count"`
Items []object.WallWallpostToID `json:"items"`
}
// NewsfeedGetMentions returns a list of posts on user walls in which the current user is mentioned.
//
// https://vk.com/dev/newsfeed.getMentions
func (vk *VK) NewsfeedGetMentions(params Params) (response NewsfeedGetMentionsResponse, err error) {
err = vk.RequestUnmarshal("newsfeed.getMentions", &response, params)
return
}
// NewsfeedGetRecommendedResponse struct.
type NewsfeedGetRecommendedResponse struct {
Items []object.NewsfeedNewsfeedItem `json:"items"`
Profiles []object.UsersUser `json:"profiles"`
Groups []object.GroupsGroup `json:"groups"`
NextOffset string `json:"next_offset"`
NextFrom string `json:"next_from"`
}
// NewsfeedGetRecommended returns a list of newsfeeds recommended to the current user.
//
// https://vk.com/dev/newsfeed.getRecommended
func (vk *VK) NewsfeedGetRecommended(params Params) (response NewsfeedGetRecommendedResponse, err error) {
err = vk.RequestUnmarshal("newsfeed.getRecommended", &response, params)
return
}
// NewsfeedGetSuggestedSourcesResponse struct.
type NewsfeedGetSuggestedSourcesResponse struct {
Count int `json:"count"`
Items []object.GroupsGroup `json:"items"` // FIXME: GroupsGroup + UsersUser
}
// NewsfeedGetSuggestedSources returns communities and users that current user is suggested to follow.
//
// https://vk.com/dev/newsfeed.getSuggestedSources
func (vk *VK) NewsfeedGetSuggestedSources(params Params) (response NewsfeedGetSuggestedSourcesResponse, err error) {
err = vk.RequestUnmarshal("newsfeed.getSuggestedSources", &response, params)
return
}
// NewsfeedIgnoreItem hides an item from the newsfeed.
//
// https://vk.com/dev/newsfeed.ignoreItem
func (vk *VK) NewsfeedIgnoreItem(params Params) (response int, err error) {
err = vk.RequestUnmarshal("newsfeed.ignoreItem", &response, params)
return
}
// NewsfeedSaveList creates and edits user newsfeed lists.
//
// https://vk.com/dev/newsfeed.saveList
func (vk *VK) NewsfeedSaveList(params Params) (response int, err error) {
err = vk.RequestUnmarshal("newsfeed.saveList", &response, params)
return
}
// NewsfeedSearchResponse struct.
type NewsfeedSearchResponse struct {
Items []object.WallWallpost `json:"items"`
Count int `json:"count"`
TotalCount int `json:"total_count"`
NextFrom string `json:"next_from"`
}
// NewsfeedSearch returns search results by statuses.
//
// extended=0
//
// https://vk.com/dev/newsfeed.search
func (vk *VK) NewsfeedSearch(params Params) (response NewsfeedSearchResponse, err error) {
err = vk.RequestUnmarshal("newsfeed.search", &response, params, Params{"extended": false})
return
}
// NewsfeedSearchExtendedResponse struct.
type NewsfeedSearchExtendedResponse struct {
Items []object.WallWallpost `json:"items"`
Count int `json:"count"`
TotalCount int `json:"total_count"`
Profiles []object.UsersUser `json:"profiles"`
Groups []object.GroupsGroup `json:"groups"`
NextFrom string `json:"next_from"`
}
// NewsfeedSearchExtended returns search results by statuses.
//
// extended=1
//
// https://vk.com/dev/newsfeed.search
func (vk *VK) NewsfeedSearchExtended(params Params) (response NewsfeedSearchExtendedResponse, err error) {
err = vk.RequestUnmarshal("newsfeed.search", &response, params, Params{"extended": true})
return
}
// NewsfeedUnignoreItem returns a hidden item to the newsfeed.
//
// https://vk.com/dev/newsfeed.unignoreItem
func (vk *VK) NewsfeedUnignoreItem(params Params) (response int, err error) {
err = vk.RequestUnmarshal("newsfeed.unignoreItem", &response, params)
return
}
// NewsfeedUnsubscribe unsubscribes the current user from specified newsfeeds.
//
// https://vk.com/dev/newsfeed.unsubscribe
func (vk *VK) NewsfeedUnsubscribe(params Params) (response int, err error) {
err = vk.RequestUnmarshal("newsfeed.unsubscribe", &response, params)
return
}

100
vendor/github.com/SevereCloud/vksdk/v2/api/notes.go generated vendored Normal file
View File

@@ -0,0 +1,100 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// NotesAdd creates a new note for the current user.
//
// https://vk.com/dev/notes.add
func (vk *VK) NotesAdd(params Params) (response int, err error) {
err = vk.RequestUnmarshal("notes.add", &response, params)
return
}
// NotesCreateComment adds a new comment on a note.
//
// https://vk.com/dev/notes.createComment
func (vk *VK) NotesCreateComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("notes.createComment", &response, params)
return
}
// NotesDelete deletes a note of the current user.
//
// https://vk.com/dev/notes.delete
func (vk *VK) NotesDelete(params Params) (response int, err error) {
err = vk.RequestUnmarshal("notes.delete", &response, params)
return
}
// NotesDeleteComment deletes a comment on a note.
//
// https://vk.com/dev/notes.deleteComment
func (vk *VK) NotesDeleteComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("notes.deleteComment", &response, params)
return
}
// NotesEdit edits a note of the current user.
//
// https://vk.com/dev/notes.edit
func (vk *VK) NotesEdit(params Params) (response int, err error) {
err = vk.RequestUnmarshal("notes.edit", &response, params)
return
}
// NotesEditComment edits a comment on a note.
//
// https://vk.com/dev/notes.editComment
func (vk *VK) NotesEditComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("notes.editComment", &response, params)
return
}
// NotesGetResponse struct.
type NotesGetResponse struct {
Count int `json:"count"`
Items []object.NotesNote `json:"items"`
}
// NotesGet returns a list of notes created by a user.
//
// https://vk.com/dev/notes.get
func (vk *VK) NotesGet(params Params) (response NotesGetResponse, err error) {
err = vk.RequestUnmarshal("notes.get", &response, params)
return
}
// NotesGetByIDResponse struct.
type NotesGetByIDResponse object.NotesNote
// NotesGetByID returns a note by its ID.
//
// https://vk.com/dev/notes.getById
func (vk *VK) NotesGetByID(params Params) (response NotesGetByIDResponse, err error) {
err = vk.RequestUnmarshal("notes.getById", &response, params)
return
}
// NotesGetCommentsResponse struct.
type NotesGetCommentsResponse struct {
Count int `json:"count"`
Items []object.NotesNoteComment `json:"items"`
}
// NotesGetComments returns a list of comments on a note.
//
// https://vk.com/dev/notes.getComments
func (vk *VK) NotesGetComments(params Params) (response NotesGetCommentsResponse, err error) {
err = vk.RequestUnmarshal("notes.getComments", &response, params)
return
}
// NotesRestoreComment restores a deleted comment on a note.
//
// https://vk.com/dev/notes.restoreComment
func (vk *VK) NotesRestoreComment(params Params) (response int, err error) {
err = vk.RequestUnmarshal("notes.restoreComment", &response, params)
return
}

View File

@@ -0,0 +1,54 @@
package api // import "github.com/SevereCloud/vksdk/v2/api"
import (
"github.com/SevereCloud/vksdk/v2/object"
)
// NotificationsGetResponse struct.
type NotificationsGetResponse struct {
Count int `json:"count"`
Items []object.NotificationsNotification `json:"items"`
Profiles []object.UsersUser `json:"profiles"`
Groups []object.GroupsGroup `json:"groups"`
Photos []object.PhotosPhoto `json:"photos"`
Videos []object.VideoVideo `json:"videos"`
Apps []object.AppsApp `json:"apps"`
LastViewed int `json:"last_viewed"`
NextFrom string `json:"next_from"`
TTL int `json:"ttl"`
}
// NotificationsGet returns a list of notifications about other users' feedback to the current user's wall posts.
//
// https://vk.com/dev/notifications.get
func (vk *VK) NotificationsGet(params Params) (response NotificationsGetResponse, err error) {
err = vk.RequestUnmarshal("notifications.get", &response, params)
return
}
// NotificationsMarkAsViewed resets the counter of new notifications
// about other users' feedback to the current user's wall posts.
//
// https://vk.com/dev/notifications.markAsViewed
func (vk *VK) NotificationsMarkAsViewed(params Params) (response int, err error) {
err = vk.RequestUnmarshal("notifications.markAsViewed", &response, params)
return
}
// NotificationsSendMessageResponse struct.
type NotificationsSendMessageResponse []struct {
UserID int `json:"user_id"`
Status object.BaseBoolInt `json:"status"`
Error struct {
Code int `json:"code"`
Description string `json:"description"`
} `json:"error"`
}
// NotificationsSendMessage sends notification to the VK Apps user.
//
// https://vk.com/dev/notifications.sendMessage
func (vk *VK) NotificationsSendMessage(params Params) (response NotificationsSendMessageResponse, err error) {
err = vk.RequestUnmarshal("notifications.sendMessage", &response, params)
return
}

Some files were not shown because too many files have changed in this diff Show More