easywhatsapp is whatsapp library for Go to make easy implement package from Rhymen/go-whatsapp.
Big thanks to sigalor/whatsapp-web-reveng and all contributors who made it.
go get github.com/yudhasubki/easywhatsapp
- Login
- Send Message
- Retrieve All Message
- Retrieve Message By JID
- Get All JID
- Create Group
- Search Message
- Get Group ID
init struct
wa, err := easywhatsapp.New(5, true)
if err != nil {
log.Printf("err : %v", err)
}
// then you need to send qrcode with Pusher.
client := make(map[string]string)
client["APP_ID"] = "YOUR_APP_ID"
client["APP_KEY"] = "YOUR_APP_KEY"
client["APP_SECRET"] = "YOUR_APP_SECRET"
client["CLUSTER"] = "YOUR_CLIENT_CLUSTER"
// or print in terminal console
wa.Streamer.Console.EnableConsole = true
// Add handler to retrieve message, jids, or related with messages
wa.AddHandler()
pusherClient := wa.Client(client)
wa.Streamer.Pusher.Client = pusherClient
err = wa.Login()
if err != nil {
log.Printf("err : %v", err)
}
//use time.After if relate with message, contacts, chats
fmt.Println("Waiting for chats info...")
<-time.After(5 * time.Second)
Send Message
msgId, err := wa.SendText(jid@s.whatsapp.net, "hello world!")
if err != nil {
log.Printf("err : %v", err)
}
log.Printf("Message ID : %v", msgId)
Search Message
exist, messages, err := wa.SearchMessage("Input your message key")
if err != nil {
log.Printf("err : %v", err)
}
log.Printf("Message available : %v", exist)
for _, m := range messages {
log.Printf("%v \n", m)
}
Create Group
group, err := wa.CreateGroup("Group Name", []string{"participants@s.whatsapp.net, ..."})
if err != nil {
log.Printf("err : %v", err)
}
log.Printf("%v", group)
Get All JID
for _, j := range wa.Message.RemoteJID {
log.Printf("jid : %v \n", j)
}
Get Group JID
groupJids := wa.GetGroupJID()
for _, g := range groupJids {
log.Printf("%v \n", g)
}
Get Chat by JID
chats := wa.GetChatByJID("62812000000@s.whatsapp.net", 100)
for _, c := range chats {
log.Printf("chats : %v", c)
}
Get All Chats
chats := wa.GetChats(100)
for _, c := range chats {
log.Printf("chats : %v", c)
}
Get All only Group Chats
chats := wa.GetGroupChats(100)
for _, c := range chats {
log.Printf("chats : %v", c)
}
This project is still under maintenance.