From 7fb10986bc21e60232231067c48a0212eeb3ee1d Mon Sep 17 00:00:00 2001 From: andreyMalyshkin <87826990+andreyMalyshkin@users.noreply.github.com> Date: Fri, 10 Nov 2023 17:46:21 +0600 Subject: [PATCH 01/15] SW-2059: add getWaSettings --- pkg/categories/methods/account.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/categories/methods/account.go b/pkg/categories/methods/account.go index e81d21a..dd974f9 100644 --- a/pkg/categories/methods/account.go +++ b/pkg/categories/methods/account.go @@ -9,6 +9,11 @@ func (c AccountCategory) GetSettings() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "GetSettings", nil, "") } +// GetWaSettings is aimed to get information about the WhatsApp account +func (c AccountCategory) getWaSettings() (map[string]interface{}, error) { + return c.GreenAPI.Request("GET", "getWaSettings", nil, "") +} + // SetSettings is for setting the account settings func (c AccountCategory) SetSettings(parameters map[string]interface{}) (map[string]interface{}, error) { method := "GET" From aae9c2afaffcce6f9aa72332f08649dd4b2414b0 Mon Sep 17 00:00:00 2001 From: andreyMalyshkin <87826990+andreyMalyshkin@users.noreply.github.com> Date: Fri, 10 Nov 2023 17:52:56 +0600 Subject: [PATCH 02/15] SW-2059: add getWaSettings fix --- pkg/categories/methods/account.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/categories/methods/account.go b/pkg/categories/methods/account.go index dd974f9..7e21899 100644 --- a/pkg/categories/methods/account.go +++ b/pkg/categories/methods/account.go @@ -10,7 +10,7 @@ func (c AccountCategory) GetSettings() (map[string]interface{}, error) { } // GetWaSettings is aimed to get information about the WhatsApp account -func (c AccountCategory) getWaSettings() (map[string]interface{}, error) { +func (c AccountCategory) GetWaSettings() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "getWaSettings", nil, "") } From 0d004ab5193becbfbbc79ace1d819aa138e30180 Mon Sep 17 00:00:00 2001 From: Jibek100 Date: Sun, 12 Nov 2023 18:06:45 +0600 Subject: [PATCH 03/15] SW-2544: Added sendPoll request and example --- examples/sendPoll/main.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/sendPoll/main.go diff --git a/examples/sendPoll/main.go b/examples/sendPoll/main.go new file mode 100644 index 0000000..d3734f7 --- /dev/null +++ b/examples/sendPoll/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "fmt" + "log" + + "github.com/green-api/whatsapp-api-client-golang/pkg/api" +) + +func main() { + GreenAPI := api.GreenAPI{ + IDInstance: "1101000001", + APITokenInstance: "d75b3a66374942c5b3c019c698abc2067e151558acbd412345", + } + + response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ + "chatId": "11001234567@c.us", + "message": "Please choose the color:", + "options": []map[string]interface{}{ + { + "optionName": "green", + }, + { + "optionName": "red", + }, + { + "optionName": "blue", + }, + }, + }) + if err != nil { + log.Fatal(err) + } + + fmt.Println(response) +} From c9305830a6c7ec91287c356bff8c3b759dca4da2 Mon Sep 17 00:00:00 2001 From: Jibek100 Date: Sun, 12 Nov 2023 18:07:32 +0600 Subject: [PATCH 04/15] SW-2544: Added sendPoll request and example --- README.md | 26 ++++++++++++++++++++++++++ docs/README_RU.md | 26 ++++++++++++++++++++++++++ pkg/categories/methods/sending.go | 5 +++++ 3 files changed, 57 insertions(+) diff --git a/README.md b/README.md index d658d4d..5ecf0a3 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,30 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) { }) ``` +### How to send a message with a poll + +If an API method has optional parameters, you have to pass JSON to the library method (`map[string]interface{}`). + +Link to example: [sendPoll/main.go](examples/sendPoll/main.go). + +``` +response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ + "chatId": "11001234567@c.us", + "message": "Please choose the color:", + "options": []map[string]interface{}{ + { + "optionName": "green", + }, + { + "optionName": "red", + }, + { + "optionName": "blue", + }, + }, +}) +``` + ## List of examples | Description | Link to example | @@ -129,6 +153,7 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) { | How to send a file by URL | [sendFileByURL/main.go](examples/sendFileByURL/main.go) | | How to send a message | [sendMessage/main.go](examples/sendMessage/main.go) | | How to receive incoming notifications | [webhook/main.go](examples/webhook/main.go) | +| How to send a message with a poll | [sendPoll/main.go](examples/sendPoll/main.go) | ## List of all library methods @@ -173,6 +198,7 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) { | `Sending().SendContact` | The method is for sending a message with a contact | [SendContact](https://green-api.com/en/docs/api/sending/SendContact/) | | `Sending().SendLink` | The method is designed to send a message with a link that will add an image preview, title and description | [SendLink](https://green-api.com/en/docs/api/sending/SendLink/) | | `Sending().ForwardMessages` | The method is designed for forwarding messages to a personal or group chat | [ForwardMessages](https://green-api.com/en/docs/api/sending/ForwardMessages/) | +| `Sending().SendPoll` | The method is designed for sending messages with a poll to a personal or group chat | [SendPoll](https://green-api.com/en/docs/api/sending/SendPoll/) | | `Service().CheckWhatsapp` | The method checks if there is a WhatsApp account on the phone number | [CheckWhatsapp](https://green-api.com/en/docs/api/service/CheckWhatsapp/) | | `Service().GetAvatar` | The method returns the avatar of the correspondent or group chat | [GetAvatar](https://green-api.com/en/docs/api/service/GetAvatar/) | | `Service().GetContacts` | The method is designed to get a list of contacts of the current account | [GetContacts](https://green-api.com/en/docs/api/service/GetContacts/) | diff --git a/docs/README_RU.md b/docs/README_RU.md index 8cc6d7f..296bf0c 100644 --- a/docs/README_RU.md +++ b/docs/README_RU.md @@ -119,6 +119,30 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) { }) ``` +### Как отправить сообщение с опросом + +Если у метода API есть необязательные параметры, то в метод библиотеки нужно передавать JSON (`map[string]interface{}`). + +Ссылка на пример: [sendPoll/main.go](../examples/sendPoll/main.go). + +``` +response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ + "chatId": "11001234567@c.us", + "message": "Please choose the color:", + "options": []map[string]interface{}{ + { + "optionName": "green", + }, + { + "optionName": "red", + }, + { + "optionName": "blue", + }, + }, +}) +``` + ## Список примеров | Описание | Ссылка на пример | @@ -128,6 +152,7 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) { | Как отправить файл по ссылке | [sendFileByURL/main.go](../examples/sendFileByURL/main.go) | | Как отправить сообщение | [sendMessage/main.go](../examples/sendMessage/main.go) | | Как получать входящие уведомления | [webhook/main.go](../examples/webhook/main.go) | +| Как отправить сообщение с опросом | [sendPoll/main.go](../examples/sendPoll/main.go) | ## Список всех методов библиотеки @@ -173,6 +198,7 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) { | `Sending().SendLink` | Метод предназначен для отправки сообщения со ссылкой, по которой будут добавлены превью изображения, заголовок и описание | [SendLink](https://green-api.com/docs/api/sending/SendLink/) | | `Sending().ForwardMessages` | Метод предназначен для пересылки сообщений в личный или групповой чат | [ForwardMessages](https://green-api.com/docs/api/sending/ForwardMessages/) | | `Sending().UploadFile` | Метод позволяет выгружать файл из локальной файловой системы, который позднее можно отправить методом SendFileByUrl | [UploadFile](https://green-api.com/docs/api/sending/UploadFile/) | +| `Sending().SendPoll` | Метод предназначен для отправки сообщения с опросом в личный или групповой чат | [SendPoll](https://green-api.com/docs/api/sending/SendPoll/) | | `Service().CheckWhatsapp` | Метод проверяет наличие аккаунта WhatsApp на номере телефона | [CheckWhatsapp](https://green-api.com/docs/api/service/CheckWhatsapp/) | | `Service().GetAvatar` | Метод возвращает аватар корреспондента или группового чата | [GetAvatar](https://green-api.com/docs/api/service/GetAvatar/) | | `Service().GetContacts` | Метод предназначен для получения списка контактов текущего аккаунта | [GetContacts](https://green-api.com/docs/api/service/GetContacts/) | diff --git a/pkg/categories/methods/sending.go b/pkg/categories/methods/sending.go index 9881dc1..58e3034 100644 --- a/pkg/categories/methods/sending.go +++ b/pkg/categories/methods/sending.go @@ -62,3 +62,8 @@ func (c SendingCategory) ForwardMessages(chatId, chatIdFrom string, messages []s func (c SendingCategory) UploadFile(filePath string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "UploadFile", nil, filePath) } + +// SendPoll is designed to send a message with poll to a personal or group chat +func (c SendingCategory) SendPoll(parameters map[string]interface{}) (map[string]interface{}, error) { + return c.GreenAPI.Request("POST", "sendPoll", parameters, "") +} From 40b7aa10e344513e3360d4caaa2e6984e12d4684 Mon Sep 17 00:00:00 2001 From: Jibek100 Date: Mon, 20 Nov 2023 00:23:24 +0600 Subject: [PATCH 05/15] Added method getAuthorizationCode --- README.md | 1 + docs/README_RU.md | 1 + pkg/categories/methods/account.go | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/README.md b/README.md index d658d4d..4a9571e 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) { | `Account().Logout` | The method is designed to unlogin the account | [Logout](https://green-api.com/en/docs/api/account/Logout/) | | `Account().QR` | The method is designed to get a QR code | [QR](https://green-api.com/en/docs/api/account/QR/) | | `Account().SetProfilePicture` | The method is designed to set the avatar of the account | [SetProfilePicture](https://green-api.com/en/docs/api/account/SetProfilePicture/) | +| `Account().GetAuthorizationCode` | The method is designed to authorize an instance by phone number | [GetAuthorizationCode](https://green-api.com/en/docs/api/account/GetAuthorizationCode/) | | `Device().GetDeviceInfo` | The method is designed to get information about the device (phone) on which the WhatsApp Business application is running | [GetDeviceInfo](https://green-api.com/en/docs/api/phone/GetDeviceInfo/) | | `Groups().CreateGroup` | The method is designed to create a group chat | [CreateGroup](https://green-api.com/en/docs/api/groups/CreateGroup/) | | `Groups().UpdateGroupName` | The method changes the name of the group chat | [UpdateGroupName](https://green-api.com/en/docs/api/groups/UpdateGroupName/) | diff --git a/docs/README_RU.md b/docs/README_RU.md index 8cc6d7f..1ae70ff 100644 --- a/docs/README_RU.md +++ b/docs/README_RU.md @@ -141,6 +141,7 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) { | `Account().Logout` | Метод предназначен для разлогинивания аккаунта | [Logout](https://green-api.com/docs/api/account/Logout/) | | `Account().QR` | Метод предназначен для получения QR-кода | [QR](https://green-api.com/docs/api/account/QR/) | | `Account().SetProfilePicture` | Метод предназначен для установки аватара аккаунта | [SetProfilePicture](https://green-api.com/docs/api/account/SetProfilePicture/) | +| `Account().GetAuthorizationCode` | Метод предназначен для для авторизации инстанса по номеру телефона | [GetAuthorizationCode](https://green-api.com/docs/api/account/GetAuthorizationCode/) | | `Device().GetDeviceInfo` | Метод предназначен для получения информации об устройстве (телефоне), на котором запущено приложение WhatsApp Business | [GetDeviceInfo](https://green-api.com/docs/api/phone/GetDeviceInfo/) | | `Groups().CreateGroup` | Метод предназначен для создания группового чата | [CreateGroup](https://green-api.com/docs/api/groups/CreateGroup/) | | `Groups().UpdateGroupName` | Метод изменяет наименование группового чата | [UpdateGroupName](https://green-api.com/docs/api/groups/UpdateGroupName/) | diff --git a/pkg/categories/methods/account.go b/pkg/categories/methods/account.go index e81d21a..403715f 100644 --- a/pkg/categories/methods/account.go +++ b/pkg/categories/methods/account.go @@ -48,3 +48,10 @@ func (c AccountCategory) QR() (map[string]interface{}, error) { func (c AccountCategory) SetProfilePicture(filePath string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "setProfilePicture", nil, filePath) } + +// GetAuthorizationCode is designed to authorize an instance by phone number +func (c ServiceCategory) GetAuthorizationCode(phoneNumber int) (map[string]interface{}, error) { + return c.GreenAPI.Request("POST", "GetAuthorizationCode", map[string]interface{}{ + "phoneNumber": phoneNumber, + }, "") +} From 76b8ec1c004365f7ec670d7961beb70287c46b92 Mon Sep 17 00:00:00 2001 From: Amele9 Date: Sat, 16 Dec 2023 19:57:23 +0600 Subject: [PATCH 06/15] Fixed GetAuthorizationCode method --- docs/README_RU.md | 2 +- pkg/categories/methods/account.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/README_RU.md b/docs/README_RU.md index 1ae70ff..565f564 100644 --- a/docs/README_RU.md +++ b/docs/README_RU.md @@ -141,7 +141,7 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) { | `Account().Logout` | Метод предназначен для разлогинивания аккаунта | [Logout](https://green-api.com/docs/api/account/Logout/) | | `Account().QR` | Метод предназначен для получения QR-кода | [QR](https://green-api.com/docs/api/account/QR/) | | `Account().SetProfilePicture` | Метод предназначен для установки аватара аккаунта | [SetProfilePicture](https://green-api.com/docs/api/account/SetProfilePicture/) | -| `Account().GetAuthorizationCode` | Метод предназначен для для авторизации инстанса по номеру телефона | [GetAuthorizationCode](https://green-api.com/docs/api/account/GetAuthorizationCode/) | +| `Account().GetAuthorizationCode` | Метод предназначен для авторизации инстанса по номеру телефона | [GetAuthorizationCode](https://green-api.com/docs/api/account/GetAuthorizationCode/) | | `Device().GetDeviceInfo` | Метод предназначен для получения информации об устройстве (телефоне), на котором запущено приложение WhatsApp Business | [GetDeviceInfo](https://green-api.com/docs/api/phone/GetDeviceInfo/) | | `Groups().CreateGroup` | Метод предназначен для создания группового чата | [CreateGroup](https://green-api.com/docs/api/groups/CreateGroup/) | | `Groups().UpdateGroupName` | Метод изменяет наименование группового чата | [UpdateGroupName](https://green-api.com/docs/api/groups/UpdateGroupName/) | diff --git a/pkg/categories/methods/account.go b/pkg/categories/methods/account.go index 403715f..f9d33bd 100644 --- a/pkg/categories/methods/account.go +++ b/pkg/categories/methods/account.go @@ -50,8 +50,8 @@ func (c AccountCategory) SetProfilePicture(filePath string) (map[string]interfac } // GetAuthorizationCode is designed to authorize an instance by phone number -func (c ServiceCategory) GetAuthorizationCode(phoneNumber int) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "GetAuthorizationCode", map[string]interface{}{ +func (c AccountCategory) GetAuthorizationCode(phoneNumber int) (map[string]interface{}, error) { + return c.GreenAPI.Request("POST", "getAuthorizationCode", map[string]interface{}{ "phoneNumber": phoneNumber, }, "") } From 96ee258ad8044cefc4917bb860e9c4d4ce34e34a Mon Sep 17 00:00:00 2001 From: Amele9 Date: Sat, 16 Dec 2023 20:05:38 +0600 Subject: [PATCH 07/15] Fixed GetWaSettings method --- docs/README_RU.md | 1 + pkg/categories/methods/account.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/README_RU.md b/docs/README_RU.md index e464a83..3fedad4 100644 --- a/docs/README_RU.md +++ b/docs/README_RU.md @@ -159,6 +159,7 @@ response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ | Метод API | Описание | Documentation link | |-----------------------------------|---------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------| | `Account().GetSettings` | Метод предназначен для получения текущих настроек аккаунта | [GetSettings](https://green-api.com/docs/api/account/GetSettings/) | +| `Account().GetWaSettings` | Метод предназначен для получения информации о аккаунте WhatsApp | [GetWaSettings](https://green-api.com/docs/api/account/GetWaSettings/) | | `Account().SetSettings` | Метод предназначен для установки настроек аккаунта | [SetSettings](https://green-api.com/docs/api/account/SetSettings/) | | `Account().GetStateInstance` | Метод предназначен для получения состояния аккаунта | [GetStateInstance](https://green-api.com/docs/api/account/GetStateInstance/) | | `Account().GetStatusInstance` | Метод предназначен для получения состояния сокета соединения инстанса аккаунта с WhatsApp | [GetStatusInstance](https://green-api.com/docs/api/account/GetStatusInstance/) | diff --git a/pkg/categories/methods/account.go b/pkg/categories/methods/account.go index 9d875a1..99297f0 100644 --- a/pkg/categories/methods/account.go +++ b/pkg/categories/methods/account.go @@ -9,7 +9,7 @@ func (c AccountCategory) GetSettings() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "GetSettings", nil, "") } -// GetWaSettings is aimed to get information about the WhatsApp account +// GetWaSettings is designed to get information about the WhatsApp account func (c AccountCategory) GetWaSettings() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "getWaSettings", nil, "") } From c04cd6d590070707c0ebbb303bb39a76d8f3595a Mon Sep 17 00:00:00 2001 From: Amele9 Date: Sat, 16 Dec 2023 20:07:46 +0600 Subject: [PATCH 08/15] Fixed GetWaSettings docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 74a862f..e624c4a 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ | API method | Description | Documentation link | |-----------------------------------|---------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------| | `Account().GetSettings` | The method is designed to get the current settings of the account | [GetSettings](https://green-api.com/en/docs/api/account/GetSettings/) | +| `Account().GetWaSettings` | The method is designed to get information about the WhatsApp account | [GetSettings](https://green-api.com/en/docs/api/account/GetWaSettings/) | | `Account().SetSettings` | The method is designed to set the account settings | [SetSettings](https://green-api.com/docs/api/account/SetSettings/) | | `Account().GetStateInstance` | The method is designed to get the state of the account | [GetStateInstance](https://green-api.com/en/docs/api/account/GetStateInstance/) | | `Account().GetStatusInstance` | The method is designed to get the socket connection state of the account instance with WhatsApp | [GetStatusInstance](https://green-api.com/en/docs/api/account/GetStatusInstance/) | From 0a6079dbd9d2c1460e90be43f6e625c798bb6d3f Mon Sep 17 00:00:00 2001 From: Amele9 Date: Sat, 16 Dec 2023 20:18:24 +0600 Subject: [PATCH 09/15] Fixed SendPoll method --- README.md | 28 ++++++++++++++-------------- docs/README_RU.md | 26 +++++++++++++------------- examples/sendPoll/main.go | 8 ++++---- pkg/categories/methods/sending.go | 2 +- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index e624c4a..c3c67a5 100644 --- a/README.md +++ b/README.md @@ -128,19 +128,19 @@ Link to example: [sendPoll/main.go](examples/sendPoll/main.go). ``` response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ - "chatId": "11001234567@c.us", - "message": "Please choose the color:", - "options": []map[string]interface{}{ - { - "optionName": "green", - }, - { - "optionName": "red", - }, - { - "optionName": "blue", - }, - }, + "chatId": "11001234567@c.us", + "message": "Please choose a color:", + "options": []map[string]interface{}{ + { + "optionName": "Red", + }, + { + "optionName": "Green", + }, + { + "optionName": "Blue", + }, + }, }) ``` @@ -200,7 +200,7 @@ response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ | `Sending().SendContact` | The method is for sending a message with a contact | [SendContact](https://green-api.com/en/docs/api/sending/SendContact/) | | `Sending().SendLink` | The method is designed to send a message with a link that will add an image preview, title and description | [SendLink](https://green-api.com/en/docs/api/sending/SendLink/) | | `Sending().ForwardMessages` | The method is designed for forwarding messages to a personal or group chat | [ForwardMessages](https://green-api.com/en/docs/api/sending/ForwardMessages/) | -| `Sending().SendPoll` | The method is designed for sending messages with a poll to a personal or group chat | [SendPoll](https://green-api.com/en/docs/api/sending/SendPoll/) | +| `Sending().SendPoll` | The method is designed for sending messages with a poll to a private or group chat | [SendPoll](https://green-api.com/en/docs/api/sending/SendPoll/) | | `Service().CheckWhatsapp` | The method checks if there is a WhatsApp account on the phone number | [CheckWhatsapp](https://green-api.com/en/docs/api/service/CheckWhatsapp/) | | `Service().GetAvatar` | The method returns the avatar of the correspondent or group chat | [GetAvatar](https://green-api.com/en/docs/api/service/GetAvatar/) | | `Service().GetContacts` | The method is designed to get a list of contacts of the current account | [GetContacts](https://green-api.com/en/docs/api/service/GetContacts/) | diff --git a/docs/README_RU.md b/docs/README_RU.md index 3fedad4..b045b50 100644 --- a/docs/README_RU.md +++ b/docs/README_RU.md @@ -127,19 +127,19 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) { ``` response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ - "chatId": "11001234567@c.us", - "message": "Please choose the color:", - "options": []map[string]interface{}{ - { - "optionName": "green", - }, - { - "optionName": "red", - }, - { - "optionName": "blue", - }, - }, + "chatId": "11001234567@c.us", + "message": "Please choose a color:", + "options": []map[string]interface{}{ + { + "optionName": "Red", + }, + { + "optionName": "Green", + }, + { + "optionName": "Blue", + }, + }, }) ``` diff --git a/examples/sendPoll/main.go b/examples/sendPoll/main.go index d3734f7..ce44795 100644 --- a/examples/sendPoll/main.go +++ b/examples/sendPoll/main.go @@ -15,16 +15,16 @@ func main() { response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ "chatId": "11001234567@c.us", - "message": "Please choose the color:", + "message": "Please choose a color:", "options": []map[string]interface{}{ { - "optionName": "green", + "optionName": "Red", }, { - "optionName": "red", + "optionName": "Green", }, { - "optionName": "blue", + "optionName": "Blue", }, }, }) diff --git a/pkg/categories/methods/sending.go b/pkg/categories/methods/sending.go index 58e3034..c99266d 100644 --- a/pkg/categories/methods/sending.go +++ b/pkg/categories/methods/sending.go @@ -63,7 +63,7 @@ func (c SendingCategory) UploadFile(filePath string) (map[string]interface{}, er return c.GreenAPI.Request("POST", "UploadFile", nil, filePath) } -// SendPoll is designed to send a message with poll to a personal or group chat +// SendPoll is designed for sending messages with a poll to a private or group chat func (c SendingCategory) SendPoll(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendPoll", parameters, "") } From e69be896af29f7d33094fff1e1194ab94a043932 Mon Sep 17 00:00:00 2001 From: Amele9 Date: Sat, 16 Dec 2023 22:26:49 +0600 Subject: [PATCH 10/15] Fixed docs --- README.md | 4 ++-- docs/README_RU.md | 2 +- pkg/categories/methods/account.go | 21 +++++++++---------- pkg/categories/methods/device.go | 3 ++- pkg/categories/methods/groups.go | 18 ++++++++--------- pkg/categories/methods/journals.go | 9 +++++---- pkg/categories/methods/queues.go | 5 +++-- pkg/categories/methods/read_mark.go | 2 +- pkg/categories/methods/receiving.go | 8 +++++--- pkg/categories/methods/sending.go | 31 ++++++++++++++++++----------- pkg/categories/methods/service.go | 17 ++++++++-------- 11 files changed, 67 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index c3c67a5..21e832a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # whatsapp-api-client-golang -- [Документация на русском языке](docs/README_RU.md) +- [Документация на русском языке](docs/README_RU.md). whatsapp-api-client-golang is a library for integration with WhatsApp messenger using the API service [green-api.com](https://green-api.com/en/). You should get a registration token and an account ID in @@ -214,7 +214,7 @@ response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ ## Service methods documentation -[Service methods documentation](https://green-api.com/en/docs/api/) +[Service methods documentation](https://green-api.com/en/docs/api/). ## License diff --git a/docs/README_RU.md b/docs/README_RU.md index b045b50..337f55e 100644 --- a/docs/README_RU.md +++ b/docs/README_RU.md @@ -214,7 +214,7 @@ response, err := GreenAPI.Methods().Sending().SendPoll(map[string]interface{}{ ## Документация по методам сервиса -[Документация по методам сервиса](https://green-api.com/docs/api/) +[Документация по методам сервиса](https://green-api.com/docs/api/). ## Лицензия diff --git a/pkg/categories/methods/account.go b/pkg/categories/methods/account.go index 99297f0..f4bb481 100644 --- a/pkg/categories/methods/account.go +++ b/pkg/categories/methods/account.go @@ -4,17 +4,17 @@ type AccountCategory struct { GreenAPI GreenAPIInterface } -// GetSettings is designed to get the current settings of the account +// GetSettings is designed to get the current settings of the account. func (c AccountCategory) GetSettings() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "GetSettings", nil, "") } -// GetWaSettings is designed to get information about the WhatsApp account +// GetWaSettings is designed to get information about the WhatsApp account. func (c AccountCategory) GetWaSettings() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "getWaSettings", nil, "") } -// SetSettings is for setting the account settings +// SetSettings is for setting the account settings. func (c AccountCategory) SetSettings(parameters map[string]interface{}) (map[string]interface{}, error) { method := "GET" if parameters != nil { @@ -24,37 +24,38 @@ func (c AccountCategory) SetSettings(parameters map[string]interface{}) (map[str return c.GreenAPI.Request(method, "SetSettings", parameters, "") } -// GetStateInstance is designed to get the state of the account +// GetStateInstance is designed to get the state of the account. func (c AccountCategory) GetStateInstance() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "getStateInstance", nil, "") } -// GetStatusInstance is designed to get the socket connection state of the account instance with WhatsApp +// GetStatusInstance is designed to get the socket connection state +// of the account instance with WhatsApp. func (c AccountCategory) GetStatusInstance() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "getStatusInstance", nil, "") } -// Reboot is designed to restart the account +// Reboot is designed to restart the account. func (c AccountCategory) Reboot() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "Reboot", nil, "") } -// Logout is designed to unlogin the account +// Logout is designed to unlogin the account. func (c AccountCategory) Logout() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "Logout", nil, "") } -// QR is designed to get a QR code +// QR is designed to get a QR code. func (c AccountCategory) QR() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "qr", nil, "") } -// SetProfilePicture is designed to set the avatar of the account +// SetProfilePicture is designed to set the avatar of the account. func (c AccountCategory) SetProfilePicture(filePath string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "setProfilePicture", nil, filePath) } -// GetAuthorizationCode is designed to authorize an instance by phone number +// GetAuthorizationCode is designed to authorize an instance by phone number. func (c AccountCategory) GetAuthorizationCode(phoneNumber int) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "getAuthorizationCode", map[string]interface{}{ "phoneNumber": phoneNumber, diff --git a/pkg/categories/methods/device.go b/pkg/categories/methods/device.go index 7ae9176..62ef8f4 100644 --- a/pkg/categories/methods/device.go +++ b/pkg/categories/methods/device.go @@ -4,7 +4,8 @@ type DeviceCategory struct { GreenAPI GreenAPIInterface } -// GetDeviceInfo is designed to get information about the device (phone) on which the WhatsApp Business application is running +// GetDeviceInfo is designed to get information about the device (phone) +// on which the WhatsApp Business application is running. func (c DeviceCategory) GetDeviceInfo() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "GetDeviceInfo", nil, "") } diff --git a/pkg/categories/methods/groups.go b/pkg/categories/methods/groups.go index 3dbc8f0..5ed7c98 100644 --- a/pkg/categories/methods/groups.go +++ b/pkg/categories/methods/groups.go @@ -4,7 +4,7 @@ type GroupsCategory struct { GreenAPI GreenAPIInterface } -// CreateGroup is designed to create a group chat +// CreateGroup is designed to create a group chat. func (c GroupsCategory) CreateGroup(groupName string, chatIds []string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "CreateGroup", map[string]interface{}{ "groupName": groupName, @@ -12,7 +12,7 @@ func (c GroupsCategory) CreateGroup(groupName string, chatIds []string) (map[str }, "") } -// UpdateGroupName changes the name of the group chat +// UpdateGroupName changes the name of the group chat. func (c GroupsCategory) UpdateGroupName(groupId, groupName string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "UpdateGroupName", map[string]interface{}{ "groupId": groupId, @@ -20,14 +20,14 @@ func (c GroupsCategory) UpdateGroupName(groupId, groupName string) (map[string]i }, "") } -// GetGroupData gets group chat data +// GetGroupData gets group chat data. func (c GroupsCategory) GetGroupData(groupId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "GetGroupData", map[string]interface{}{ "groupId": groupId, }, "") } -// AddGroupParticipant adds a participant to the group chat +// AddGroupParticipant adds a participant to the group chat. func (c GroupsCategory) AddGroupParticipant(groupId, participantChatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "AddGroupParticipant", map[string]interface{}{ "groupId": groupId, @@ -35,7 +35,7 @@ func (c GroupsCategory) AddGroupParticipant(groupId, participantChatId string) ( }, "") } -// RemoveGroupParticipant removes the participant from the group chat +// RemoveGroupParticipant removes the participant from the group chat. func (c GroupsCategory) RemoveGroupParticipant(groupId, participantChatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "RemoveGroupParticipant", map[string]interface{}{ "groupId": groupId, @@ -43,7 +43,7 @@ func (c GroupsCategory) RemoveGroupParticipant(groupId, participantChatId string }, "") } -// SetGroupAdmin designates a member of a group chat as an administrator +// SetGroupAdmin designates a member of a group chat as an administrator. func (c GroupsCategory) SetGroupAdmin(groupId, participantChatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "SetGroupAdmin", map[string]interface{}{ "groupId": groupId, @@ -51,7 +51,7 @@ func (c GroupsCategory) SetGroupAdmin(groupId, participantChatId string) (map[st }, "") } -// RemoveAdmin deprives the participant of group chat administration rights +// RemoveAdmin deprives the participant of group chat administration rights. func (c GroupsCategory) RemoveAdmin(groupId, participantChatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "RemoveAdmin", map[string]interface{}{ "groupId": groupId, @@ -59,14 +59,14 @@ func (c GroupsCategory) RemoveAdmin(groupId, participantChatId string) (map[stri }, "") } -// SetGroupPicture sets the avatar of the group +// SetGroupPicture sets the avatar of the group. func (c GroupsCategory) SetGroupPicture(filePath, groupId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "setGroupPicture", map[string]interface{}{ "groupId": groupId, }, filePath) } -// LeaveGroup logs the user of the current account out of the group chat +// LeaveGroup logs the user of the current account out of the group chat. func (c GroupsCategory) LeaveGroup(groupId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "LeaveGroup", map[string]interface{}{ "groupId": groupId, diff --git a/pkg/categories/methods/journals.go b/pkg/categories/methods/journals.go index 1acc820..7c31f07 100644 --- a/pkg/categories/methods/journals.go +++ b/pkg/categories/methods/journals.go @@ -4,12 +4,12 @@ type JournalsCategory struct { GreenAPI GreenAPIInterface } -// GetChatHistory returns the chat message history +// GetChatHistory returns the chat message history. func (c JournalsCategory) GetChatHistory(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "GetChatHistory", parameters, "") } -// GetMessage returns a chat message +// GetMessage returns a chat message. func (c JournalsCategory) GetMessage(chatId, idMessage string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "getMessage", map[string]interface{}{ "chatId": chatId, @@ -17,12 +17,13 @@ func (c JournalsCategory) GetMessage(chatId, idMessage string) (map[string]inter }, "") } -// LastIncomingMessages returns the most recent incoming messages of the account +// LastIncomingMessages returns the most recent incoming messages +// of the account. func (c JournalsCategory) LastIncomingMessages(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "lastIncomingMessages", parameters, "") } -// LastOutgoingMessages returns the last sent messages of the account +// LastOutgoingMessages returns the last sent messages of the account. func (c JournalsCategory) LastOutgoingMessages(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "LastOutgoingMessages", parameters, "") } diff --git a/pkg/categories/methods/queues.go b/pkg/categories/methods/queues.go index 039048b..e0afc0b 100644 --- a/pkg/categories/methods/queues.go +++ b/pkg/categories/methods/queues.go @@ -4,12 +4,13 @@ type QueuesCategory struct { GreenAPI GreenAPIInterface } -// ShowMessagesQueue is designed to get the list of messages that are in the queue to be sent +// ShowMessagesQueue is designed to get the list of messages +// that are in the queue to be sent. func (c QueuesCategory) ShowMessagesQueue() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "ShowMessagesQueue", nil, "") } -// ClearMessagesQueue is designed to clear the queue of messages to be sent +// ClearMessagesQueue is designed to clear the queue of messages to be sent. func (c QueuesCategory) ClearMessagesQueue() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "ClearMessagesQueue", nil, "") } diff --git a/pkg/categories/methods/read_mark.go b/pkg/categories/methods/read_mark.go index 742d96e..f4eafb5 100644 --- a/pkg/categories/methods/read_mark.go +++ b/pkg/categories/methods/read_mark.go @@ -4,7 +4,7 @@ type ReadMarkCategory struct { GreenAPI GreenAPIInterface } -// ReadChat is designed to mark chat messages as read +// ReadChat is designed to mark chat messages as read. func (c ReadMarkCategory) ReadChat(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "ReadChat", parameters, "") } diff --git a/pkg/categories/methods/receiving.go b/pkg/categories/methods/receiving.go index 3b5d6b3..bc9be47 100644 --- a/pkg/categories/methods/receiving.go +++ b/pkg/categories/methods/receiving.go @@ -4,19 +4,21 @@ type ReceivingCategory struct { GreenAPI GreenAPIInterface } -// ReceiveNotification is designed to receive a single incoming notification from the notification queue +// ReceiveNotification is designed to receive a single incoming notification +// from the notification queue. func (c ReceivingCategory) ReceiveNotification() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "ReceiveNotification", nil, "") } -// DeleteNotification is designed to remove an incoming notification from the notification queue +// DeleteNotification is designed to remove an incoming notification +// from the notification queue. func (c ReceivingCategory) DeleteNotification(receiptId int) (map[string]interface{}, error) { return c.GreenAPI.Request("DELETE", "DeleteNotification", map[string]interface{}{ "receiptId": receiptId, }, "") } -// DownloadFile is for downloading received and sent files +// DownloadFile is for downloading received and sent files. func (c ReceivingCategory) DownloadFile(chatId, idMessage string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "downloadFile", map[string]interface{}{ "chatId": chatId, diff --git a/pkg/categories/methods/sending.go b/pkg/categories/methods/sending.go index c99266d..b028fbd 100644 --- a/pkg/categories/methods/sending.go +++ b/pkg/categories/methods/sending.go @@ -4,52 +4,57 @@ type SendingCategory struct { GreenAPI GreenAPIInterface } -// SendMessage is designed to send a text message to a personal or group chat +// SendMessage is designed to send a text message to a personal or group chat. func (c SendingCategory) SendMessage(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "SendMessage", parameters, "") } -// SendButtons is designed to send a message with buttons to a personal or group chat +// SendButtons is designed to send a message with buttons +// to a personal or group chat. func (c SendingCategory) SendButtons(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "SendButtons", parameters, "") } -// SendTemplateButtons is designed to send a message with interactive buttons from the list of templates in a personal or group chat +// SendTemplateButtons is designed to send a message with interactive buttons +// from the list of templates in a personal or group chat. func (c SendingCategory) SendTemplateButtons(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendTemplateButtons", parameters, "") } -// SendListMessage is designed to send a message with a selection button from a list of values to a personal or group chat +// SendListMessage is designed to send a message with a selection button +// from a list of values to a personal or group chat. func (c SendingCategory) SendListMessage(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "SendListMessage", parameters, "") } -// SendFileByUpload is designed to send a file loaded through a form (form-data) +// SendFileByUpload is designed to send a file loaded through a form (form-data). func (c SendingCategory) SendFileByUpload(filePath string, parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "SendFileByUpload", parameters, filePath) } -// SendFileByUrl is designed to send a file downloaded via a link +// SendFileByUrl is designed to send a file downloaded via a link. func (c SendingCategory) SendFileByUrl(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "SendFileByUrl", parameters, "") } -// SendLocation is designed to send a geolocation message +// SendLocation is designed to send a geolocation message. func (c SendingCategory) SendLocation(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendLocation", parameters, "") } -// SendContact is for sending a message with a contact +// SendContact is for sending a message with a contact. func (c SendingCategory) SendContact(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendContact", parameters, "") } -// SendLink is designed to send a message with a link that will add an image preview, title and description +// SendLink is designed to send a message with a link +// that will add an image preview, title and description. func (c SendingCategory) SendLink(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendLink", parameters, "") } -// ForwardMessages is designed for forwarding messages to a personal or group chat +// ForwardMessages is designed for forwarding messages +// to a personal or group chat. func (c SendingCategory) ForwardMessages(chatId, chatIdFrom string, messages []string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "forwardMessages", map[string]interface{}{ "chatId": chatId, @@ -58,12 +63,14 @@ func (c SendingCategory) ForwardMessages(chatId, chatIdFrom string, messages []s }, "") } -// UploadFile allows you to upload a file from the local file system, which can later be sent using the SendFileByUrl method +// UploadFile allows you to upload a file from the local file system, +// which can later be sent using the SendFileByUrl method. func (c SendingCategory) UploadFile(filePath string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "UploadFile", nil, filePath) } -// SendPoll is designed for sending messages with a poll to a private or group chat +// SendPoll is designed for sending messages with a poll +// to a private or group chat. func (c SendingCategory) SendPoll(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendPoll", parameters, "") } diff --git a/pkg/categories/methods/service.go b/pkg/categories/methods/service.go index 76c7af7..721ef00 100644 --- a/pkg/categories/methods/service.go +++ b/pkg/categories/methods/service.go @@ -4,33 +4,33 @@ type ServiceCategory struct { GreenAPI GreenAPIInterface } -// CheckWhatsapp checks if there is a WhatsApp account on the phone number +// CheckWhatsapp checks if there is a WhatsApp account on the phone number. func (c ServiceCategory) CheckWhatsapp(phoneNumber int) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "CheckWhatsapp", map[string]interface{}{ "phoneNumber": phoneNumber, }, "") } -// GetAvatar returns the avatar of the correspondent or group chat +// GetAvatar returns the avatar of the correspondent or group chat. func (c ServiceCategory) GetAvatar(chatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "GetAvatar", map[string]interface{}{ "chatId": chatId, }, "") } -// GetContacts is designed to get a list of contacts of the current account +// GetContacts is designed to get a list of contacts of the current account. func (c ServiceCategory) GetContacts() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "GetContacts", nil, "") } -// GetContactInfo is designed to obtain information about the contact +// GetContactInfo is designed to obtain information about the contact. func (c ServiceCategory) GetContactInfo(chatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "getContactInfo", map[string]interface{}{ "chatId": chatId, }, "") } -// DeleteMessage deletes the message from chat +// DeleteMessage deletes the message from chat. func (c ServiceCategory) DeleteMessage(chatId, idMessage string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "deleteMessage", map[string]interface{}{ "chatId": chatId, @@ -38,21 +38,22 @@ func (c ServiceCategory) DeleteMessage(chatId, idMessage string) (map[string]int }, "") } -// ArchiveChat archives the chat +// ArchiveChat archives the chat. func (c ServiceCategory) ArchiveChat(chatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "archiveChat", map[string]interface{}{ "chatId": chatId, }, "") } -// UnarchiveChat unarchives the chat +// UnarchiveChat unarchives the chat. func (c ServiceCategory) UnarchiveChat(chatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "unarchiveChat", map[string]interface{}{ "chatId": chatId, }, "") } -// SetDisappearingChat is designed to change the settings of disappearing messages in chats +// SetDisappearingChat is designed to change the settings +// of disappearing messages in chats. func (c ServiceCategory) SetDisappearingChat(parameters map[string]interface{}) (map[string]interface{}, error) { method := "GET" if parameters != nil { From 91dd95633d81bd9d2c26eec2f331256eafc1d859 Mon Sep 17 00:00:00 2001 From: Amele9 Date: Sat, 16 Dec 2023 22:41:05 +0600 Subject: [PATCH 11/15] Fixed API method names --- pkg/categories/methods/account.go | 8 ++++---- pkg/categories/methods/device.go | 2 +- pkg/categories/methods/groups.go | 16 ++++++++-------- pkg/categories/methods/journals.go | 4 ++-- pkg/categories/methods/queues.go | 4 ++-- pkg/categories/methods/read_mark.go | 2 +- pkg/categories/methods/receiving.go | 4 ++-- pkg/categories/methods/sending.go | 12 ++++++------ pkg/categories/methods/service.go | 6 +++--- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/pkg/categories/methods/account.go b/pkg/categories/methods/account.go index f4bb481..b5b054d 100644 --- a/pkg/categories/methods/account.go +++ b/pkg/categories/methods/account.go @@ -6,7 +6,7 @@ type AccountCategory struct { // GetSettings is designed to get the current settings of the account. func (c AccountCategory) GetSettings() (map[string]interface{}, error) { - return c.GreenAPI.Request("GET", "GetSettings", nil, "") + return c.GreenAPI.Request("GET", "getSettings", nil, "") } // GetWaSettings is designed to get information about the WhatsApp account. @@ -21,7 +21,7 @@ func (c AccountCategory) SetSettings(parameters map[string]interface{}) (map[str method = "POST" } - return c.GreenAPI.Request(method, "SetSettings", parameters, "") + return c.GreenAPI.Request(method, "setSettings", parameters, "") } // GetStateInstance is designed to get the state of the account. @@ -37,12 +37,12 @@ func (c AccountCategory) GetStatusInstance() (map[string]interface{}, error) { // Reboot is designed to restart the account. func (c AccountCategory) Reboot() (map[string]interface{}, error) { - return c.GreenAPI.Request("GET", "Reboot", nil, "") + return c.GreenAPI.Request("GET", "reboot", nil, "") } // Logout is designed to unlogin the account. func (c AccountCategory) Logout() (map[string]interface{}, error) { - return c.GreenAPI.Request("GET", "Logout", nil, "") + return c.GreenAPI.Request("GET", "logout", nil, "") } // QR is designed to get a QR code. diff --git a/pkg/categories/methods/device.go b/pkg/categories/methods/device.go index 62ef8f4..8a00511 100644 --- a/pkg/categories/methods/device.go +++ b/pkg/categories/methods/device.go @@ -7,5 +7,5 @@ type DeviceCategory struct { // GetDeviceInfo is designed to get information about the device (phone) // on which the WhatsApp Business application is running. func (c DeviceCategory) GetDeviceInfo() (map[string]interface{}, error) { - return c.GreenAPI.Request("GET", "GetDeviceInfo", nil, "") + return c.GreenAPI.Request("GET", "getDeviceInfo", nil, "") } diff --git a/pkg/categories/methods/groups.go b/pkg/categories/methods/groups.go index 5ed7c98..1046724 100644 --- a/pkg/categories/methods/groups.go +++ b/pkg/categories/methods/groups.go @@ -6,7 +6,7 @@ type GroupsCategory struct { // CreateGroup is designed to create a group chat. func (c GroupsCategory) CreateGroup(groupName string, chatIds []string) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "CreateGroup", map[string]interface{}{ + return c.GreenAPI.Request("POST", "createGroup", map[string]interface{}{ "groupName": groupName, "chatIds": chatIds, }, "") @@ -14,7 +14,7 @@ func (c GroupsCategory) CreateGroup(groupName string, chatIds []string) (map[str // UpdateGroupName changes the name of the group chat. func (c GroupsCategory) UpdateGroupName(groupId, groupName string) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "UpdateGroupName", map[string]interface{}{ + return c.GreenAPI.Request("POST", "updateGroupName", map[string]interface{}{ "groupId": groupId, "groupName": groupName, }, "") @@ -22,14 +22,14 @@ func (c GroupsCategory) UpdateGroupName(groupId, groupName string) (map[string]i // GetGroupData gets group chat data. func (c GroupsCategory) GetGroupData(groupId string) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "GetGroupData", map[string]interface{}{ + return c.GreenAPI.Request("POST", "getGroupData", map[string]interface{}{ "groupId": groupId, }, "") } // AddGroupParticipant adds a participant to the group chat. func (c GroupsCategory) AddGroupParticipant(groupId, participantChatId string) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "AddGroupParticipant", map[string]interface{}{ + return c.GreenAPI.Request("POST", "addGroupParticipant", map[string]interface{}{ "groupId": groupId, "participantChatId": participantChatId, }, "") @@ -37,7 +37,7 @@ func (c GroupsCategory) AddGroupParticipant(groupId, participantChatId string) ( // RemoveGroupParticipant removes the participant from the group chat. func (c GroupsCategory) RemoveGroupParticipant(groupId, participantChatId string) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "RemoveGroupParticipant", map[string]interface{}{ + return c.GreenAPI.Request("POST", "removeGroupParticipant", map[string]interface{}{ "groupId": groupId, "participantChatId": participantChatId, }, "") @@ -45,7 +45,7 @@ func (c GroupsCategory) RemoveGroupParticipant(groupId, participantChatId string // SetGroupAdmin designates a member of a group chat as an administrator. func (c GroupsCategory) SetGroupAdmin(groupId, participantChatId string) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "SetGroupAdmin", map[string]interface{}{ + return c.GreenAPI.Request("POST", "setGroupAdmin", map[string]interface{}{ "groupId": groupId, "participantChatId": participantChatId, }, "") @@ -53,7 +53,7 @@ func (c GroupsCategory) SetGroupAdmin(groupId, participantChatId string) (map[st // RemoveAdmin deprives the participant of group chat administration rights. func (c GroupsCategory) RemoveAdmin(groupId, participantChatId string) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "RemoveAdmin", map[string]interface{}{ + return c.GreenAPI.Request("POST", "removeAdmin", map[string]interface{}{ "groupId": groupId, "participantChatId": participantChatId, }, "") @@ -68,7 +68,7 @@ func (c GroupsCategory) SetGroupPicture(filePath, groupId string) (map[string]in // LeaveGroup logs the user of the current account out of the group chat. func (c GroupsCategory) LeaveGroup(groupId string) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "LeaveGroup", map[string]interface{}{ + return c.GreenAPI.Request("POST", "leaveGroup", map[string]interface{}{ "groupId": groupId, }, "") } diff --git a/pkg/categories/methods/journals.go b/pkg/categories/methods/journals.go index 7c31f07..ba23750 100644 --- a/pkg/categories/methods/journals.go +++ b/pkg/categories/methods/journals.go @@ -6,7 +6,7 @@ type JournalsCategory struct { // GetChatHistory returns the chat message history. func (c JournalsCategory) GetChatHistory(parameters map[string]interface{}) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "GetChatHistory", parameters, "") + return c.GreenAPI.Request("POST", "getChatHistory", parameters, "") } // GetMessage returns a chat message. @@ -25,5 +25,5 @@ func (c JournalsCategory) LastIncomingMessages(parameters map[string]interface{} // LastOutgoingMessages returns the last sent messages of the account. func (c JournalsCategory) LastOutgoingMessages(parameters map[string]interface{}) (map[string]interface{}, error) { - return c.GreenAPI.Request("GET", "LastOutgoingMessages", parameters, "") + return c.GreenAPI.Request("GET", "lastOutgoingMessages", parameters, "") } diff --git a/pkg/categories/methods/queues.go b/pkg/categories/methods/queues.go index e0afc0b..5da5bf2 100644 --- a/pkg/categories/methods/queues.go +++ b/pkg/categories/methods/queues.go @@ -7,10 +7,10 @@ type QueuesCategory struct { // ShowMessagesQueue is designed to get the list of messages // that are in the queue to be sent. func (c QueuesCategory) ShowMessagesQueue() (map[string]interface{}, error) { - return c.GreenAPI.Request("GET", "ShowMessagesQueue", nil, "") + return c.GreenAPI.Request("GET", "showMessagesQueue", nil, "") } // ClearMessagesQueue is designed to clear the queue of messages to be sent. func (c QueuesCategory) ClearMessagesQueue() (map[string]interface{}, error) { - return c.GreenAPI.Request("GET", "ClearMessagesQueue", nil, "") + return c.GreenAPI.Request("GET", "clearMessagesQueue", nil, "") } diff --git a/pkg/categories/methods/read_mark.go b/pkg/categories/methods/read_mark.go index f4eafb5..a8763dc 100644 --- a/pkg/categories/methods/read_mark.go +++ b/pkg/categories/methods/read_mark.go @@ -6,5 +6,5 @@ type ReadMarkCategory struct { // ReadChat is designed to mark chat messages as read. func (c ReadMarkCategory) ReadChat(parameters map[string]interface{}) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "ReadChat", parameters, "") + return c.GreenAPI.Request("POST", "readChat", parameters, "") } diff --git a/pkg/categories/methods/receiving.go b/pkg/categories/methods/receiving.go index bc9be47..d07aca7 100644 --- a/pkg/categories/methods/receiving.go +++ b/pkg/categories/methods/receiving.go @@ -7,13 +7,13 @@ type ReceivingCategory struct { // ReceiveNotification is designed to receive a single incoming notification // from the notification queue. func (c ReceivingCategory) ReceiveNotification() (map[string]interface{}, error) { - return c.GreenAPI.Request("GET", "ReceiveNotification", nil, "") + return c.GreenAPI.Request("GET", "receiveNotification", nil, "") } // DeleteNotification is designed to remove an incoming notification // from the notification queue. func (c ReceivingCategory) DeleteNotification(receiptId int) (map[string]interface{}, error) { - return c.GreenAPI.Request("DELETE", "DeleteNotification", map[string]interface{}{ + return c.GreenAPI.Request("DELETE", "deleteNotification", map[string]interface{}{ "receiptId": receiptId, }, "") } diff --git a/pkg/categories/methods/sending.go b/pkg/categories/methods/sending.go index b028fbd..03059b8 100644 --- a/pkg/categories/methods/sending.go +++ b/pkg/categories/methods/sending.go @@ -6,13 +6,13 @@ type SendingCategory struct { // SendMessage is designed to send a text message to a personal or group chat. func (c SendingCategory) SendMessage(parameters map[string]interface{}) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "SendMessage", parameters, "") + return c.GreenAPI.Request("POST", "sendMessage", parameters, "") } // SendButtons is designed to send a message with buttons // to a personal or group chat. func (c SendingCategory) SendButtons(parameters map[string]interface{}) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "SendButtons", parameters, "") + return c.GreenAPI.Request("POST", "sendButtons", parameters, "") } // SendTemplateButtons is designed to send a message with interactive buttons @@ -24,17 +24,17 @@ func (c SendingCategory) SendTemplateButtons(parameters map[string]interface{}) // SendListMessage is designed to send a message with a selection button // from a list of values to a personal or group chat. func (c SendingCategory) SendListMessage(parameters map[string]interface{}) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "SendListMessage", parameters, "") + return c.GreenAPI.Request("POST", "sendListMessage", parameters, "") } // SendFileByUpload is designed to send a file loaded through a form (form-data). func (c SendingCategory) SendFileByUpload(filePath string, parameters map[string]interface{}) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "SendFileByUpload", parameters, filePath) + return c.GreenAPI.Request("POST", "sendFileByUpload", parameters, filePath) } // SendFileByUrl is designed to send a file downloaded via a link. func (c SendingCategory) SendFileByUrl(parameters map[string]interface{}) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "SendFileByUrl", parameters, "") + return c.GreenAPI.Request("POST", "sendFileByUrl", parameters, "") } // SendLocation is designed to send a geolocation message. @@ -66,7 +66,7 @@ func (c SendingCategory) ForwardMessages(chatId, chatIdFrom string, messages []s // UploadFile allows you to upload a file from the local file system, // which can later be sent using the SendFileByUrl method. func (c SendingCategory) UploadFile(filePath string) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "UploadFile", nil, filePath) + return c.GreenAPI.Request("POST", "uploadFile", nil, filePath) } // SendPoll is designed for sending messages with a poll diff --git a/pkg/categories/methods/service.go b/pkg/categories/methods/service.go index 721ef00..6b70fa7 100644 --- a/pkg/categories/methods/service.go +++ b/pkg/categories/methods/service.go @@ -6,21 +6,21 @@ type ServiceCategory struct { // CheckWhatsapp checks if there is a WhatsApp account on the phone number. func (c ServiceCategory) CheckWhatsapp(phoneNumber int) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "CheckWhatsapp", map[string]interface{}{ + return c.GreenAPI.Request("POST", "checkWhatsapp", map[string]interface{}{ "phoneNumber": phoneNumber, }, "") } // GetAvatar returns the avatar of the correspondent or group chat. func (c ServiceCategory) GetAvatar(chatId string) (map[string]interface{}, error) { - return c.GreenAPI.Request("POST", "GetAvatar", map[string]interface{}{ + return c.GreenAPI.Request("POST", "getAvatar", map[string]interface{}{ "chatId": chatId, }, "") } // GetContacts is designed to get a list of contacts of the current account. func (c ServiceCategory) GetContacts() (map[string]interface{}, error) { - return c.GreenAPI.Request("GET", "GetContacts", nil, "") + return c.GreenAPI.Request("GET", "getContacts", nil, "") } // GetContactInfo is designed to obtain information about the contact. From 6be47ae5839e051df3d7e1eabafb88f1461e1ddd Mon Sep 17 00:00:00 2001 From: Amele9 Date: Sat, 16 Dec 2023 23:01:13 +0600 Subject: [PATCH 12/15] Added workflows --- .github/workflows/go.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..b967eaf --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,30 @@ +name: Go + +on: + push: + branches: + - "master" + pull_request: + branches: + - "master" + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ "1.19", "1.20", "1.21" ] + + steps: + - uses: actions/checkout@v4 + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... From 0d629fd516a5c900301eda19fb6433762411eef8 Mon Sep 17 00:00:00 2001 From: Amele9 Date: Sat, 16 Dec 2023 23:35:10 +0600 Subject: [PATCH 13/15] Fixed #12 --- pkg/api/api.go | 6 ++++- pkg/api/http.go | 61 ++++++++++++++++++++++++---------------------- pkg/api/webhook.go | 16 +++++++++--- 3 files changed, 50 insertions(+), 33 deletions(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index 24e9e48..cda8bc7 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -18,7 +18,11 @@ func (a GreenAPI) Methods() categories.GreenAPICategories { } func (a GreenAPI) Webhook() GreenAPIWebhook { - return GreenAPIWebhook{GreenAPI: a} + return GreenAPIWebhook{ + GreenAPI: a, + + ErrorChannel: make(chan error), + } } func (a GreenAPI) Request(method, APIMethod string, data map[string]interface{}, filePath string) (map[string]interface{}, error) { diff --git a/pkg/api/http.go b/pkg/api/http.go index 969bc61..2e801c0 100644 --- a/pkg/api/http.go +++ b/pkg/api/http.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "log" "mime/multipart" "net/http" "os" @@ -16,43 +15,47 @@ import ( func executeRequest(method, url string, data map[string]interface{}, filePath string) (map[string]interface{}, error) { client := &http.Client{} - req := getRequest(method, url, data, filePath) - if strings.Contains(url, "UploadFile") { - req = getUploadFileRequest(method, url, filePath) + req, err := getRequest(method, url, data, filePath) + if strings.Contains(url, "uploadFile") { + req, err = getUploadFileRequest(method, url, filePath) + } + + if err != nil { + return nil, err } resp, err := client.Do(req) if err != nil { - log.Fatal(err) + return nil, err } return getResponse(resp) } -func getRequest(method, url string, data map[string]interface{}, filePath string) *http.Request { +func getRequest(method, url string, data map[string]interface{}, filePath string) (*http.Request, error) { if method == http.MethodGet || method == http.MethodDelete { req, err := http.NewRequest(method, url, nil) if err != nil { - log.Fatal(err) + return nil, err } - return req + return req, nil } if filePath == "" { buf, err := json.Marshal(data) if err != nil { - log.Fatal(err) + return nil, err } req, err := http.NewRequest(method, url, bytes.NewBuffer(buf)) if err != nil { - log.Fatal(err) + return nil, err } - req.Header.Add("Content-Type", "application/json") + req.Header.Set("Content-Type", "application/json") - return req + return req, nil } buffer := &bytes.Buffer{} @@ -63,71 +66,71 @@ func getRequest(method, url string, data map[string]interface{}, filePath string for key, value := range data { err := writer.WriteField(key, value.(string)) if err != nil { - log.Fatal(err) + return nil, err } } } file, err := os.Open(filePath) if err != nil { - log.Fatal(err) + return nil, err } part, err := writer.CreateFormFile("file", filePath) if err != nil { - log.Fatal(err) + return nil, err } _, err = io.Copy(part, file) if err != nil { - log.Fatal(err) + return nil, err } err = file.Close() if err != nil { - log.Fatal(err) + return nil, err } err = writer.Close() if err != nil { - log.Fatal(err) + return nil, err } req, err := http.NewRequest(method, url, buffer) if err != nil { - log.Fatal(err) + return nil, err } - req.Header.Add("Content-Type", writer.FormDataContentType()) + req.Header.Set("Content-Type", writer.FormDataContentType()) - return req + return req, nil } -func getUploadFileRequest(method, url string, filePath string) *http.Request { +func getUploadFileRequest(method, url string, filePath string) (*http.Request, error) { buf, err := os.ReadFile(filePath) if err != nil { - log.Fatal(err) + return nil, err } req, err := http.NewRequest(method, url, bytes.NewBuffer(buf)) if err != nil { - log.Fatal(err) + return nil, err } - req.Header.Add("Content-Type", http.DetectContentType(buf)) + req.Header.Set("Content-Type", http.DetectContentType(buf)) - return req + return req, nil } func getResponse(resp *http.Response) (map[string]interface{}, error) { body, err := io.ReadAll(resp.Body) if err != nil { - log.Fatal(err) + return nil, err } err = resp.Body.Close() if err != nil { - log.Fatal(err) + return nil, err } if resp.StatusCode != http.StatusOK { @@ -138,7 +141,7 @@ func getResponse(resp *http.Response) (map[string]interface{}, error) { err = json.Unmarshal(body, &data) if err != nil { - log.Fatal(err) + return nil, err } return data, nil diff --git a/pkg/api/webhook.go b/pkg/api/webhook.go index fe97c96..954b5fc 100644 --- a/pkg/api/webhook.go +++ b/pkg/api/webhook.go @@ -1,9 +1,11 @@ package api -import "log" +import "time" type GreenAPIWebhook struct { GreenAPI GreenAPI + + ErrorChannel chan error } var running = true @@ -12,7 +14,11 @@ func (w GreenAPIWebhook) Start(handler func(map[string]interface{})) { for running { response, err := w.GreenAPI.Methods().Receiving().ReceiveNotification() if err != nil { - log.Fatal(err) + w.ErrorChannel <- err + + time.Sleep(time.Second * 5) + + continue } if response == nil { @@ -24,7 +30,11 @@ func (w GreenAPIWebhook) Start(handler func(map[string]interface{})) { receiptId := int(response["receiptId"].(float64)) response, err = w.GreenAPI.Methods().Receiving().DeleteNotification(receiptId) if err != nil { - log.Fatal(err) + w.ErrorChannel <- err + + time.Sleep(time.Second * 5) + + continue } } } From 8500b5a8549d844d5495735e5ee9e65afa9e29fb Mon Sep 17 00:00:00 2001 From: Amele9 Date: Sat, 16 Dec 2023 23:36:56 +0600 Subject: [PATCH 14/15] Added dependabot --- .github/dependabot.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e9ba1cc --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" + allow: + - dependency-type: "all" From e59282b934097d7817637e57eb2fe1a8dc267f60 Mon Sep 17 00:00:00 2001 From: Amele9 Date: Sat, 16 Dec 2023 23:45:03 +0600 Subject: [PATCH 15/15] Updated MIMEType detection --- go.mod | 4 ++++ go.sum | 4 ++++ pkg/api/http.go | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 go.sum diff --git a/go.mod b/go.mod index f901845..43a1f1f 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,7 @@ module github.com/green-api/whatsapp-api-client-golang go 1.19 + +require github.com/gabriel-vasile/mimetype v1.4.3 + +require golang.org/x/net v0.19.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a691820 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= diff --git a/pkg/api/http.go b/pkg/api/http.go index 2e801c0..491f09c 100644 --- a/pkg/api/http.go +++ b/pkg/api/http.go @@ -10,6 +10,8 @@ import ( "net/http" "os" "strings" + + "github.com/gabriel-vasile/mimetype" ) func executeRequest(method, url string, data map[string]interface{}, filePath string) (map[string]interface{}, error) { @@ -117,7 +119,9 @@ func getUploadFileRequest(method, url string, filePath string) (*http.Request, e return nil, err } - req.Header.Set("Content-Type", http.DetectContentType(buf)) + MIMEType := mimetype.Detect(buf).String() + + req.Header.Set("Content-Type", MIMEType) return req, nil }