green-api / whatsapp-api-webhook-server-golang

Create a golang server endpoint to get WhatsApp messages webhooks

Home Page:https://green-api.com/en/docs/sdk/golang/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

whatsapp-api-webhook-server-golang

whatsapp-api-webhook-server-golang is a library for integration with WhatsApp messenger using the API service green-api.com. You should get a registration token and an account ID in your personal cabinet to use the library. There is a free developer account tariff.

API

The documentation for the REST API can be found at the link. The library is a wrapper for the REST API, so the documentation at the link above also applies.

Authorization

To send a message or perform other Green API methods, the WhatsApp account in the phone app must be authorized. To authorize the account, go to your cabinet and scan the QR code using the WhatsApp app.

Example of preparing the environment for Ubuntu Server

Go Installation

Go must be installed on the server. Go installation instructions.

Updating the system

Update the system:

sudo apt update
sudo apt upgrade -y

Firewall

Set up the firewall:

Allow the SSH connection:

sudo ufw allow ssh

Base rules:

sudo ufw default deny incoming
sudo ufw default allow outgoing

Allow HTTP and HTTPS connections:

sudo ufw allow http
sudo ufw allow https

Enable the firewall:

sudo ufw enable

How to run the web server

Installation

Do not forget to create a module:

go mod init example

Installation:

go get github.com/green-api/whatsapp-api-webhook-server-golang

Import

import (
	"github.com/green-api/whatsapp-api-webhook-server-golang/pkg"
)

Examples

How to initialize an object

The WebhookToken attribute is optional.

webhook := pkg.Webhook{
    Address:      ":80",
    Pattern:      "/",
}

How to run the web server

The StartServer function takes a handler function. The handler function must have 1 parameter (body map[string]interface{}). When a new notification is received, your handler function will be executed.

Link to example: main.go.

_ := webhook.StartServer(func(body map[string]interface{}) {
    fmt.Println(body)
})

Running the application

go run main.go

Service methods documentation

Service methods documentation

License

Licensed under Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) terms. Please see file LICENSE.

About

Create a golang server endpoint to get WhatsApp messages webhooks

https://green-api.com/en/docs/sdk/golang/

License:Other


Languages

Language:Go 100.0%