I'm using whatsmeow from golang package https://pkg.go.dev/go.mau.fi/whatsmeow
I try the example and run without problem, but I'm curious, is there a way to get sender's live location from the message??
this is my log :
05:57:27.711 [Client/Recv DEBUG] <message from="[email protected]" id="974EEAED36D9D7B9354CF31D78BBE2A8" notify="Rolly Maulana Awangga" t="1663801047" type="media"><enc duration="3599" mediatype="livelocation" type="pkmsg" v="2"><!-- 3415 bytes --></enc></message>
05:57:27.712 [Client DEBUG] Decrypting 1 messages from [email protected]
05:57:27.712 [Client/Send DEBUG] <ack id="974EEAED36D9D7B9354CF31D78BBE2A8" to="[email protected]"/>
GetConversation :
Sender : [email protected]
Sender Number : 6281312000300
IsGroup : false
MessageSource : {[email protected] [email protected] false false }
ID : 974EEAED36D9D7B9354CF31D78BBE2A8
PushName : Rolly Maulana Awangga
BroadcastListOwner :
Category :
Chat : [email protected]
DeviceSentMeta : <nil>
IsFromMe : false
MediaType : livelocation
Multicast : false
Info.Chat.Server : s.whatsapp.net
05:57:27.773 [Client/Send DEBUG] <receipt id="974EEAED36D9D7B9354CF31D78BBE2A8" to="[email protected]" type="inactive"/>
The sender sends the live location to the receiver. the receiver can look up Medyatype is livelocation from whatsmeow go package. so there is a way to get the live location coordinate? and this is my code :
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
_ "github.com/mattn/go-sqlite3"
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/store/sqlstore"
"go.mau.fi/whatsmeow/types/events"
waLog "go.mau.fi/whatsmeow/util/log"
)
var client *whatsmeow.Client
func eventHandler(evt interface{}) {
switch v := evt.(type) {
case *events.Message:
if !v.Info.IsFromMe {
fmt.Println("GetConversation : ", v.Message.GetConversation())
fmt.Println("Sender : ", v.Info.Sender)
fmt.Println("Sender Number : ", v.Info.Sender.User)
fmt.Println("IsGroup : ", v.Info.IsGroup)
fmt.Println("MessageSource : ", v.Info.MessageSource)
fmt.Println("ID : ", v.Info.ID)
fmt.Println("PushName : ", v.Info.PushName)
fmt.Println("BroadcastListOwner : ", v.Info.BroadcastListOwner)
fmt.Println("Category : ", v.Info.Category)
fmt.Println("Chat : ", v.Info.Chat)
fmt.Println("DeviceSentMeta : ", v.Info.DeviceSentMeta)
fmt.Println("IsFromMe : ", v.Info.IsFromMe)
fmt.Println("MediaType : ", v.Info.MediaType)
fmt.Println("Multicast : ", v.Info.Multicast)
fmt.Println("Info.Chat.Server : ", v.Info.Chat.Server)
if v.Info.Chat.Server == "g.us" {
groupInfo, err := client.GetGroupInfo(v.Info.Chat)
fmt.Println("error GetGroupInfo : ", err)
fmt.Println("Nama Group : ", groupInfo.GroupName.Name)
}
}
}
}
func main() {
dbLog := waLog.Stdout("Database", "DEBUG", true)
// Make sure you add appropriate DB connector imports, e.g. github.com/mattn/go-sqlite3 for SQLite
container, err := sqlstore.New("sqlite3", "file:gowa.db?_foreign_keys=on", dbLog)
if err != nil {
panic(err)
}
// If you want multiple sessions, remember their JIDs and use .GetDevice(jid) or .GetAllDevices() instead.
deviceStore, err := container.GetFirstDevice()
if err != nil {
panic(err)
}
clientLog := waLog.Stdout("Client", "DEBUG", true)
client = whatsmeow.NewClient(deviceStore, clientLog)
client.AddEventHandler(eventHandler)
if client.Store.ID == nil {
// No ID stored, new login
qrChan, _ := client.GetQRChannel(context.Background())
err = client.Connect()
if err != nil {
panic(err)
}
for evt := range qrChan {
if evt.Event == "code" {
// Render the QR code here
// e.g. qrterminal.GenerateHalfBlock(evt.Code, qrterminal.L, os.Stdout)
// or just manually `echo 2@... | qrencode -t ansiutf8` in a terminal
fmt.Println("QR code:", evt.Code)
} else {
fmt.Println("Login event:", evt.Event)
}
}
} else {
// Already logged in, just connect
err = client.Connect()
if err != nil {
panic(err)
}
}
// Listen to Ctrl C (you can also do something else that prevents the program from exiting)
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
client.Disconnect()
}
CodePudding user response:
The actual data of the message in a go.mau.fi/whatsmeow/types/events.Message
is in a field called Message
, which is of type go.mau.fi/whatsmeow/types/binary/proto.Message
.
That is a generated Go struct, generated by the protobuf compiler.
The struct has fields for each type of message.
If the mediatype of the event is "livelocation", then you should expect the livelocation data to be in v.Message.LiveLocationMessage
CodePudding user response:
big thanks. You save me time. this is actually I hope for
fmt.Println("livelocation : ", v.Message.LiveLocationMessage.DegreesLatitude)