Giter Site home page Giter Site logo

go-whatsapp-rest's Introduction

Go WhatsApp Implementation in REST API

This repository contains example of implementation Rhymen/go-whatsapp package. This example is using a codebase from dimaskiddo/codebase-go-rest-lite.

Warning

Since WhatsApp is migrating to Multi-Device support then this repository might be unusable in the future. For Go WhatsApp REST with Multi-Device support please visit the new repository dimaskiddo/go-whatsapp-multidevice-rest

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Prequisites package:

  • Go (Go Programming Language)
  • Dep (Go Dependencies Management Tool)
  • Make (Automated Execution using Makefile)

Optional package:

  • GoReleaser (Go Automated Binaries Build)
  • Docker (Application Containerization)

Installing

Below is the instructions to make this codebase running:

  • Create a Go Workspace directory and export it as the extended GOPATH directory
cd <your_go_workspace_directory>
export GOPATH=$GOPATH:"`pwd`"
  • Under the Go Workspace directory create a source directory
mkdir -p src/github.com/dimaskiddo/go-whatsapp-rest
  • Move to the created directory and pull codebase
cd src/github.com/dimaskiddo/go-whatsapp-rest
git clone -b master https://github.com/dimaskiddo/go-whatsapp-rest.git .
  • Run following command to pull dependecies package
make vendor
  • Until this step you already can run this code by using this command
make run

Running The Tests

Currently the test is not ready yet :)

Deployment

To build this code to binaries for distribution purposes you can run following command:

make release

The build result will shown in build directory Or use Docker Images available in dimaskiddo/go-whatsapp-rest

API Access

You can access any endpoint under ROUTER_BASE_PATH configuration by default located at /api/v1/whatsapp. Configuration files are located in share/etc directory.

Built With

  • Go - Go Programming Languange
  • Dep - Go Dependency Management Tool
  • GoReleaser - Go Automated Binaries Build
  • Make - GNU Make Automated Execution
  • Docker - Application Containerization

Authors

  • Dimas Restu Hidayanto - Initial Work - DimasKiddo

See also the list of contributors who participated in this project

Annotation

You can seek more information for the make command parameters in the Makefile

go-whatsapp-rest's People

Contributors

dimaskiddo avatar rosseti avatar sicenul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-whatsapp-rest's Issues

akses api

mas sy mau tanya,
ketika sudah di make run, sy coba akses https://localhost:3000
nah untuk akses api nya bagai mana ya? hehe
sy coba /login
/ auth
statusnya not found..

Receive and echo using WAMessageText Helper

I a newbie in go so, please bear with me.
I would really appreciate if we can add the message handler in the helper, like how he does with this one #1 cause, I was confused when there's an incoming message how can I trace if It is in the specific JWT Claims.

Problems getting chats

With the Chats func (contact.go - Chats()) I was able to get the list of chats with contact names etc. but it works only with iOS, when I log in using Android, it returns "null".
Does anyone know how can I get the chat list on all platforms?

panic: interface conversion: interface {} is nil, not map[string]interface {}

got panic after scanning the barcode

wac.SetClientVersion(2,2147,16)

panic code snippet

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 14 [running]:
github.com/Rhymen/go-whatsapp.newInfoFromReq(0xc000098990, 0x38)
	/home/x/play/src/github.com/zainul/kasir/vendor/github.com/Rhymen/go-whatsapp/session.go:63 +0xc5e
github.com/Rhymen/go-whatsapp.(*Conn).Login(0xc000152f00, 0xc0000b23c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/x/play/src/github.com/zainul/kasir/vendor/github.com/Rhymen/go-whatsapp/session.go:268 +0x1002

Error, I can not send the picture.

Hi!
Trying to send a picture,
'Content-Type: multipart/form-data'

$fields = [
    'msisdn'=> $_REQUEST['msisdn'] . '@s.whatsapp.net',
    'message'=> $_REQUEST['message'],
    'image' => new \CurlFile('C__fakepath_shampinony-7.png', 'image/png', 'filename.png')
];
$cURLConnection = curl_init('http://172.16.0.101:3000/api/v1/whatsapp/send/image');
curl_setopt($cURLConnection, CURLOPT_POST, 1);
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $fields);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, $header);

in response I get

[status] =>
[code] => 500
[message] => Internal Server Error
[error] => image upload failed: upload responsed with %!d(float64=404)

Login error

{
"status": false,
"code": 500,
"message": "Internal Server Error",
"error": "error decoding login resp: json: cannot unmarshal array into Go value of type map[string]interface {}\n"
}

Always logout

so after trying and running, it seems every 3 days need to scan barcode
how to make session never expired?

i try using cronjob, every 1 hour will send message, and still logout every 2-3 days

stuck at /go-whatsapp-rest/api/seed/seeder.go:56

(/go-whatsapp-rest/api/seed/seeder.go:56)
[2020-10-16 18:28:59] [1.12ms] INSERT INTO users (email,password,created_at,updated_at) VALUES ('[email protected]','$2a$10$2/VNwnFSNizBDNdu6APuLeKTi8RFsDCNCqPUoOioDVGWmylbodqba','2020-10-16 18:28:59','2020-10-16 18:28:59')
[1 rows affected or returned ]

Method API

Hello,

What method swagger ui test api ?

Using modified Rhymen go-whatsapp

Hi Dimas,

I tried to use the modified Rhymen whatsapp library, but it always refers to the released version.
how do if i want to use the modified WhatsApp library?

Nuhun ah, kamu keren

Connection automatically lost after an hour

from last 2-3 months i have experienced strange issue that once scanned QR Code and sending message works till 1-2 hours perfectly but after that it does not works we need to scan again, there is no internet issue there.

whatsapp failed to write message: invalid websocket

{
"status": false,
"code": 500,
"message": "Internal Server Error",
"error": "connection is invalid"
}

Unable to install

I a trying to do this on my machine but somehow the documentation is not clear to me. I am completely new to GoLang and I also intend on improving the docs for further usage.
Help me run this on my local machine. Thanks

Error send first message

Hello. I see the WASendWithMutex() method use a scope assignment which is not correct:

Original

func WASendWithMutex(jid string, content interface{}) (string, error) {
	mutex, ok := wacMutex[jid]

	if !ok {
		mutex := &sync.Mutex{} // <-- FIX?
		wacMutex[jid] = mutex
	}

	mutex.Lock() // <-- error if ok is false

	// ...
}

Proposal:

func WASendWithMutex(jid string, content interface{}) (string, error) {
	mutex, ok := wacMutex[jid]

	if !ok {
		mutex = &sync.Mutex{} // <-- CHANGE
		wacMutex[jid] = mutex
	}

	mutex.Lock() // <-- work is ok is false

	// ...
}

I am right?

undefined: routesInit

i tried to run with: go run main.go and get this error

# command-line-arguments
./main.go:18:2: undefined: routesInit

if i run with make run, there's no error showed, but every route show 404 URI not found

I can not send a message via rest, example?

Hi!
How do i:
Send GET /api/v1/whatsapp/auth
Authorization Basic

I get a token

Send Post
/api/v1/whatsapp/login
Authorization Bearer
I get a QR pic, scan QR on mobile app

Send Post
POST http://172.16.0.101:3000/api/v1/whatsapp/send/[email protected]&message=test&quotedid=0&quotedmsg=0&delay=10
Accept: application/json
Cache-Control: no-cache
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiNzk2Mjg3MTYwNDlAcy53aGF0c2FwcC5uZXQiLCJleHAiOjE1ODkyMDEyNjd9.UFSxFYiTxllDNhOL9oZaE-x8_07FVJqIpubT_VMy4gUG88Y_NOrYerhVUgaV0jsZJJ9jt9s8gV_Wjr-4MUheSbG_wCMSaKXaOk50lTwEGkkt-lWjuiLECZ3SoHk4VwfF3GDe-vLXuKnJ4iGfP4MLFSogMDqf8ty-oShHvsBflXci351_qaBtzWMb3RQ4rV72JlCJT_rNi1WmvMhJ-QAzEbpD2V5CwRpFPvlj9PjSwsABD9-NGBzO7Bj_GrQNZSaz05mWy_Pf0MYyFU79HUyxfRYkVfmVv1mCdD0yAH0_F-YzJQD7RprvwXmjDmPucgA6tYXNl0S14VSsu5wA4B8D9w

Return
{"status":false,"code":500,"message":"Internal Server Error","error":"connection is invalid"}

Two days I can’t understand what the problem is ... There are no errors, and will not authorize :(
Maybe something else needs to be done in advance?

Can't send image

Hello mas @dimaskiddo , I'm having issue that i can't send images through the endpoint send image.
Got timeout error when post to https://mmh.whatsapp.net/mms/image

here is the error log :

send image upload failed: Post "https://mmh.whatsapp.net/mms/image/oe0QfWAk_hk3BTVDpkXvO9wGyicJ58J3R_Y_LS2wPQA=?auth=AWSzkeJZKt6eLarpXISRavMOmksci9p2GggXFmg03Bpbq8QKHqzviNZqz2c&token=oe0QfWAk_hk3BTVDpkXvO9wGyicJ58J3R_Y_LS2wPQA%3D": net/http: TLS handshake timeout {"label":"http-access","level":"error","msg":"image upload failed: post \"https://mmh.whatsapp.net/mms/image/oe0qfwak_hk3btvdpkxvo9wgyicj58j3r_y_ls2wpqa=?auth=awszkejzkt6elarpxisravmomksci9p2gggxfmg03bpbq8qkhqzvinzqz2c\u0026token=oe0qfwak_hk3btvdpkxvo9wgyicj58j3r_y_ls2wpqa%3d\": net/http: tls handshake timeout","service":"go-whatsapp-rest","time":"2020-10-13T15:51:22.904043384+07:00"}

Set proxy

Hello! It is possible to set proxy to handle multiple WhatsApp Instances in the same server?

Connection is Invalid

Hello, So first i have done a GET request at : api/v1/whatsapp/auth.
Authorization Bearer:
Username : 92xxxxxxxxxx
Password: AUTH_BASIC_PASSWORD

I received the JWT token in response, Then i used that token in Authorization Bearer in : api/v1/whatsapp/login,
I received a QR Code, I scanned it from my whatsapp, and it was fine.
Then i tried POST Request to : api/v1/whatsapp/send/text
Header using : application/x-www-form-urlencoded
Also Header : Bearer TOKEN
Inside Body added:

{
msisdn:[email protected]
message:test
quotedid:1
quotedmsg:test
}

So irrespective of whichever msisdn or quoteid whether added or not , i still receive same error response.

{
    "status": false,
    "code": 500,
    "message": "Internal Server Error",
    "error": "connection is invalid"
}

Can you guide me where i am wrong in this approach ?

Error Send Message

{"label":"whatsapp-error-handler","level":"error","msg":"id axxxx caught an error, message type not implemented","service":"go-whatsapp-rest","time":"2021-09-04T20:38:18.9456114+07:00"}

{"label":"whatsapp-error-handler","level":"error","msg":"id axxxx caught an error, message type not implemented","service":"go-whatsapp-rest","time":"2021-09-04T20:38:19.0144961+07:00"}

{"label":"whatsapp-error-handler","level":"error","msg":"id axxxx caught an error, message type not implemented","service":"go-whatsapp-rest","time":"2021-09-04T20:38:19.0148555+07:00"}

{"label":"whatsapp-error-handler","level":"error","msg":"id axxxx caught an error, message type not implemented","service":"go-whatsapp-rest","time":"2021-09-04T20:38:19.0148649+07:00"}

{"label":"whatsapp-error-handler","level":"error","msg":"id axxxx caught an error, message type not implemented","service":"go-whatsapp-rest","time":"2021-09-04T20:38:19.0148933+07:00"}

{"label":"whatsapp-error-handler","level":"error","msg":"id axxxx caught an error, message type not implemented","service":"go-whatsapp-rest","time":"2021-09-04T20:38:19.1168347+07:00"}

{"label":"whatsapp-error-handler","level":"error","msg":"id axxxx caught an error, message type not implemented","service":"go-whatsapp-rest","time":"2021-09-04T20:38:19.1172436+07:00"}

Error in Sending Message

error processing data: received invalid data

The error above shows whenever I tried to send a message though, It's successful

Persistence docker volume

Hello,

  1. Which path should I use to make persistence data when I use docker version?
  2. Which path can be use to persistence the session, so I don't have to re-login when the docker restart?

Thanks in advance

couldn't dial whatsapp web websocket: websocket: bad handshake

Hi anyone have facing same issue like this?

{"label":"server-http","level":"info","msg":"server master started at pid 13635","service":"go-whatsapp-rest","time":2022-04-12T10:59:53.042902018+07:00"}
{"label":"server-http","level":"info","msg":"server worker started at pid 13635 listening on 0.0.0.0:3000","service":"go-whatsapp-rest","time":2022-04-12T10:59:53.043223705+07:00"}
{"label":"http-access","level":"error","msg":"connection is invalid","service":"go-whatsapp-rest","time":"2022-04-12T11:00:03.265141021+07:00"}
{"label":"whatsapp-session-init","level":"info","msg":"whatsapp version 2.2147.16","service":"go-whatsapp-rest","time":"2022-04-12T11:00:52.442825304+07:00"}
{"label":"http-access","level":"error","msg":"couldn't dial whatsapp web websocket: websocket: bad handshake","service":"go-whatsapp-rest","time":"2022-04-12T11:00:57.874909569+07:00"}

How can I use this in production?

How can I use this in production? Another question, is it possible to connect more than one device with this API?

Do you have any documentation to use?

panic: runtime error: invalid memory address or nil pointer dereference

Halo mas, saya belum belajar banyak di golang, mohon bantuannya, ada kejadian error saat memanggil route login beberapa kali secara cepat berurutan

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x7bb286]

goroutine 1833 [running]:
github.com/Rhymen/go-whatsapp.(*Conn).AdminTest(0x0, 0x30, 0xc0004820c0, 0x12)
       ~/go/pkg/mod/github.com/!rhymen/[email protected]/conn.go:222 +0x26
github.com/dimaskiddo/go-whatsapp-rest/pkg/whatsapp.WATestPing(0x0, 0xc00018cde0, 0xc00028a300)
        ~/go-whatsapp-rest/pkg/whatsapp/whatsapp.go:127 +0x2f
github.com/dimaskiddo/go-whatsapp-rest/pkg/whatsapp.WASessionConnect(0xc00028a300, 0xd, 0x2, 0x7f3, 0xf, 0x5, 0xc000280240, 0x21, 0x1e, 0xc0003b0300, ...)
        ~/go-whatsapp-rest/pkg/whatsapp/whatsapp.go:242 +0x32e
github.com/dimaskiddo/go-whatsapp-rest/internal/whatsapp.WhatsAppLogin.func1(0xc00028a300, 0xd, 0xa9b770, 0x4, 0x1e, 0x5, 0x2, 0x7f3, 0xf, 0xc000280240, ...)
       ~/go-whatsapp-rest/internal/whatsapp/whatsapp.go:138 +0xae
created by github.com/dimaskiddo/go-whatsapp-rest/internal/whatsapp.WhatsAppLogin
       ~/go-whatsapp-rest/internal/whatsapp/whatsapp.go:137 +0x592
exit status 2

sample of working?

How to make it work ?
I startup the port 3000 , seems installation completed.
But what's next? it's suppose a websocket server or web server to trigger login Scan QRCODE event ?
I am new to it . sorry for silly question I raised!

healthcheck is unhealthy

Hello,
My docker status is unhealthy, but I can send message successfully and without any problem.
Why is it unhealthy?

"go-whatsapp-rest"       About a minute ago   Up About a minute (unhealthy)   0.0.0.0:3000->3000/tcp

Disconnecting the device and the lifetime of the token

@dimaskiddo,

Sign in successfully

I retrieved the qrcode and read it with the mobile device.

I sent the message successfully!

But then I was disconnected.

My question is:
How do I not get disconnected?

What is the lifetime of the token, where can I set a time for it?

Another question is how do I change the customer's name, which appears in the device's Whatsapp settings.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.