Skip to content

Commit

Permalink
Merge pull request #10 from green-api/dev
Browse files Browse the repository at this point in the history
Added new methods
  • Loading branch information
Amele9 committed Dec 16, 2023
2 parents 8d13379 + e59282b commit e29e714
Show file tree
Hide file tree
Showing 19 changed files with 302 additions and 112 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-type: "all"
30 changes: 30 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 a color:",
"options": []map[string]interface{}{
{
"optionName": "Red",
},
{
"optionName": "Green",
},
{
"optionName": "Blue",
},
},
})
```

## List of examples

| Description | Link to example |
Expand All @@ -129,19 +153,22 @@ 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

| 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/) |
| `Account().Reboot` | The method is designed to restart the account | [Reboot](https://green-api.com/en/docs/api/account/Reboot/) |
| `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/) |
Expand Down Expand Up @@ -173,6 +200,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 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/) |
Expand All @@ -186,7 +214,7 @@ GreenAPIWebhook.Start(func(body 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

Expand Down
30 changes: 29 additions & 1 deletion docs/README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 a color:",
"options": []map[string]interface{}{
{
"optionName": "Red",
},
{
"optionName": "Green",
},
{
"optionName": "Blue",
},
},
})
```

## Список примеров

| Описание | Ссылка на пример |
Expand All @@ -128,19 +152,22 @@ 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) |

## Список всех методов библиотеки

| Метод 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/) |
| `Account().Reboot` | Метод предназначен для перезапуска аккаунта | [Reboot](https://green-api.com/docs/api/account/Reboot/) |
| `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/) |
Expand Down Expand Up @@ -173,6 +200,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/) |
Expand All @@ -186,7 +214,7 @@ GreenAPIWebhook.Start(func(body map[string]interface{}) {

## Документация по методам сервиса

[Документация по методам сервиса](https://green-api.com/docs/api/)
[Документация по методам сервиса](https://green-api.com/docs/api/).

## Лицензия

Expand Down
36 changes: 36 additions & 0 deletions examples/sendPoll/main.go
Original file line number Diff line number Diff line change
@@ -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 a color:",
"options": []map[string]interface{}{
{
"optionName": "Red",
},
{
"optionName": "Green",
},
{
"optionName": "Blue",
},
},
})
if err != nil {
log.Fatal(err)
}

fmt.Println(response)
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
6 changes: 5 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit e29e714

Please sign in to comment.