+ query := whatsappFold(name)
+ if query == "" {
+ return "", errors.New("name is empty: give a part of the name of the contact or the group")
+ }
+
+ contacts, err := device.Contacts.GetAllContacts(ctx)
+ if err != nil {
+ return "", fmt.Errorf("read the contacts: %s", w.redact(err.Error()))
+ }
+
+ read := !stale || w.readGroups(ctx)
+ w.mutex.Lock()
+ groups := maps.Clone(w.groupNames)
+ w.mutex.Unlock()
+
+ if len(contacts) == 0 && len(groups) == 0 {
+ if !read {
+ return "The names are not known yet, and WhatsApp is disconnected, so the groups cannot be read. Try again later.", nil
+ }
+
+ return whatsappNamesNotReady, nil
+ }
+
+ var matches []WhatsAppMatch
+ for jid, contact := range contacts {
+ names := []string{contact.FullName, contact.FirstName, contact.BusinessName, contact.PushName}
+ shown := slices.IndexFunc(names, func(name string) bool {
+ return name != ""
+ })
+
+ if slices.Contains(own, jid.User) || shown < 0 || !slices.ContainsFunc(names, func(name string) bool {
+ return strings.Contains(whatsappFold(name), query)
+ }) {
+ continue
+ }
+
+ matches = append(matches, WhatsAppMatch{
+ id: jid.ToNonAD().String(),
+ name: names[shown],
+ kind: "contact",
+ })
+ }
+
+ for id, group := range groups {
+ if strings.Contains(whatsappFold(group), query) {
+ matches = append(matches, WhatsAppMatch{
+ id: id,
+ name: group,
+ kind: "group",
+ })
+ }
+ }
+
+ return whatsappFindAnswer(name, matches, read || len(groups) > 0), nil