šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

github.com/drizzef/whatsapp-api-go

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/drizzef/whatsapp-api-go

v0.0.0-20220728231435-cc0a40299aa8
Source
Go
Version published
Created
Source

whatsapp

A Whatsapp's Official API helper for Golang

Disclaimers

  • Whatsapp's Official API is now generally available. To get started, you can follow this steps.

Set up

First, you need a Facebook app with the Whatsapp API activated. You can create your first app following this steps. Get the API token, either a temporal or a permanent one.

In your server you can install the module using :

go get github.com/yagizzcann/whatsapp-api-go

Now you can write code like this:

import (
"github.com/yagizzcann/whatsapp-api-go"
)

Token := "YOUR_TOKEN";

api := whatsapp.API{
URI:     whatsapp.DefaultURI,
Version: whatsapp.DefaultVersion,
Token:   Token,
WebHookVerification:"custom webhook verify token ",
}

t := api.NewText("MESSAGE_CONTENT", false)
res, err := t.Send("YOUR_PHONE_ID", "TO_PHONE_NUMBER")

m := api.NewMediaLink("https://img_url", "image")
res, err := m.Send("YOUR_PHONE_ID", "TO_PHONE_NUMBER")


To recieve the post requests on message, you must setup the webhook at your Facebook app. While setting up, you will be asked a Verify Token. This can be any string you want.

The app also has a GET wizard for the webhook authentication:

cq := make(chan whatsapp.WebhookMessage, 100)
r := mux.NewRouter()
r.HandleFunc("/webhook", func(w http.ResponseWriter, r *http.Request) { whatsapp.WebhookVerificationHandler(w, r, cq) }).Methods("GET")
r.HandleFunc("/webhook", func(w http.ResponseWriter, r *http.Request) { whatsapp.WebhookEventHandler(w, r, cq) }).Methods("POST")

And that's it! Now you have a functioning Whatsapp Bot connected to your server.

FAQs

Package last updated on 28 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts