Socket
Socket
Sign inDemoInstall

github.com/drizzef/whatsapp-api-go

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/drizzef/whatsapp-api-go


Version published

Readme

Source

whatsapp

A Whatsapp's Official API helper for Golang

Disclaimers

  1. 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

Last updated on 28 Jul 2022

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc