tulir / whatsmeow

Go library for the WhatsApp web multidevice API

Home Page:https://go.mau.fi/whatsmeow

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

show Typing while doing backend stuff

GonzalezAtWork opened this issue · comments

Hello guys,

I did not found any way to send/show a "typing" for the client while doing backend work.

Is there a way?

thanks!

You could call client.SendChatPrecence(chat, state, media) :

whatsmeow/presence.go

Lines 115 to 138 in 350073d

// SendChatPresence updates the user's typing status in a specific chat.
//
// The media parameter can be set to indicate the user is recording media (like a voice message) rather than typing a text message.
func (cli *Client) SendChatPresence(jid types.JID, state types.ChatPresence, media types.ChatPresenceMedia) error {
ownID := cli.getOwnID()
if ownID.IsEmpty() {
return ErrNotLoggedIn
}
content := []waBinary.Node{{Tag: string(state)}}
if state == types.ChatPresenceComposing && len(media) > 0 {
content[0].Attrs = waBinary.Attrs{
"media": string(media),
}
}
return cli.sendNode(waBinary.Node{
Tag: "chatstate",
Attrs: waBinary.Attrs{
"from": ownID,
"to": jid,
},
Content: content,
})
}

Awesome, worked like a charm:

to start typing:
mycli.WAClient.SendChatPresence(userJid, types.ChatPresenceComposing, "")

to stop it:
mycli.WAClient.SendChatPresence(userJid, types.ChatPresencePaused, "")