|
|
@@ -162,6 +162,43 @@ func (cli *Client) SetStatusMessage(ctx context.Context, msg string) error {
|
|
|
})
|
|
|
return err
|
|
|
}
|
|
|
+func (cli *Client) Usync(ctx context.Context, phones []string) ([]types.IsOnWhatsAppResponse, error) {
|
|
|
+ jids := make([]types.JID, len(phones))
|
|
|
+ for i := range jids {
|
|
|
+ jids[i] = types.NewJID(phones[i], types.LegacyUserServer)
|
|
|
+ }
|
|
|
+ list, err := cli.usync(ctx, jids, "delta", "interactive", []waBinary.Node{
|
|
|
+ //{Tag: "business", Content: []waBinary.Node{{Tag: "verified_name"}}},
|
|
|
+ {Tag: "lid"},
|
|
|
+ {Tag: "status"},
|
|
|
+ {Tag: "contact"},
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ output := make([]types.IsOnWhatsAppResponse, 0, len(jids))
|
|
|
+ querySuffix := "@" + types.LegacyUserServer
|
|
|
+ for _, child := range list.GetChildren() {
|
|
|
+ jid, jidOK := child.Attrs["jid"].(types.JID)
|
|
|
+ if child.Tag != "user" || !jidOK {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ var info types.IsOnWhatsAppResponse
|
|
|
+ info.JID = jid
|
|
|
+ info.VerifiedName, err = parseVerifiedName(child.GetChildByTag("business"))
|
|
|
+ if err != nil {
|
|
|
+ cli.Log.Warnf("Failed to parse %s's verified name details: %v", jid, err)
|
|
|
+ }
|
|
|
+ status, _ := child.GetChildByTag("status").Content.([]byte)
|
|
|
+ info.Status = string(status)
|
|
|
+ contactNode := child.GetChildByTag("contact")
|
|
|
+ info.IsIn = contactNode.AttrGetter().String("type") == "in"
|
|
|
+ contactQuery, _ := contactNode.Content.([]byte)
|
|
|
+ info.Query = strings.TrimSuffix(string(contactQuery), querySuffix)
|
|
|
+ output = append(output, info)
|
|
|
+ }
|
|
|
+ return output, nil
|
|
|
+}
|
|
|
|
|
|
// IsOnWhatsApp checks if the given phone numbers are registered on WhatsApp.
|
|
|
// The phone numbers should be in international format, including the `+` prefix.
|