From 4fd0a7672777f0ed15692ae2ba47838208537558 Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 27 Nov 2022 00:42:16 +0100 Subject: Update dependencies (#1929) --- vendor/go.mau.fi/whatsmeow/user.go | 70 +++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'vendor/go.mau.fi/whatsmeow/user.go') diff --git a/vendor/go.mau.fi/whatsmeow/user.go b/vendor/go.mau.fi/whatsmeow/user.go index 454a7b37..fe7b0971 100644 --- a/vendor/go.mau.fi/whatsmeow/user.go +++ b/vendor/go.mau.fi/whatsmeow/user.go @@ -21,7 +21,9 @@ import ( ) const BusinessMessageLinkPrefix = "https://wa.me/message/" +const ContactQRLinkPrefix = "https://wa.me/qr/" const BusinessMessageLinkDirectPrefix = "https://api.whatsapp.com/message/" +const ContactQRLinkDirectPrefix = "https://api.whatsapp.com/qr/" // ResolveBusinessMessageLink resolves a business message short link and returns the target JID, business name and // text to prefill in the input field (if any). @@ -34,7 +36,7 @@ func (cli *Client) ResolveBusinessMessageLink(code string) (*types.BusinessMessa resp, err := cli.sendIQ(infoQuery{ Namespace: "w:qr", - Type: "get", + Type: iqGet, // WhatsApp android doesn't seem to have a "to" field for this one at all, not sure why but it works Content: []waBinary.Node{{ Tag: "qr", @@ -71,6 +73,72 @@ func (cli *Client) ResolveBusinessMessageLink(code string) (*types.BusinessMessa return &target, ag.Error() } +// ResolveContactQRLink resolves a link from a contact share QR code and returns the target JID and push name. +// +// The links look like https://wa.me/qr/ or https://api.whatsapp.com/qr/. You can either provide +// the full link, or just the part. +func (cli *Client) ResolveContactQRLink(code string) (*types.ContactQRLinkTarget, error) { + code = strings.TrimPrefix(code, ContactQRLinkPrefix) + code = strings.TrimPrefix(code, ContactQRLinkDirectPrefix) + + resp, err := cli.sendIQ(infoQuery{ + Namespace: "w:qr", + Type: iqGet, + Content: []waBinary.Node{{ + Tag: "qr", + Attrs: waBinary.Attrs{ + "code": code, + }, + }}, + }) + if errors.Is(err, ErrIQNotFound) { + return nil, wrapIQError(ErrContactQRLinkNotFound, err) + } else if err != nil { + return nil, err + } + qrChild, ok := resp.GetOptionalChildByTag("qr") + if !ok { + return nil, &ElementMissingError{Tag: "qr", In: "response to contact link query"} + } + var target types.ContactQRLinkTarget + ag := qrChild.AttrGetter() + target.JID = ag.JID("jid") + target.PushName = ag.OptionalString("notify") + target.Type = ag.String("type") + return &target, ag.Error() +} + +// GetContactQRLink gets your own contact share QR link that can be resolved using ResolveContactQRLink +// (or scanned with the official apps when encoded as a QR code). +// +// If the revoke parameter is set to true, it will ask the server to revoke the previous link and generate a new one. +func (cli *Client) GetContactQRLink(revoke bool) (string, error) { + action := "get" + if revoke { + action = "revoke" + } + resp, err := cli.sendIQ(infoQuery{ + Namespace: "w:qr", + Type: iqSet, + Content: []waBinary.Node{{ + Tag: "qr", + Attrs: waBinary.Attrs{ + "type": "contact", + "action": action, + }, + }}, + }) + if err != nil { + return "", err + } + qrChild, ok := resp.GetOptionalChildByTag("qr") + if !ok { + return "", &ElementMissingError{Tag: "qr", In: "response to own contact link fetch"} + } + ag := qrChild.AttrGetter() + return ag.String("code"), ag.Error() +} + // SetStatusMessage updates the current user's status text, which is shown in the "About" section in the user profile. // // This is different from the ephemeral status broadcast messages. Use SendMessage to types.StatusBroadcastJID to send -- cgit v1.2.3