Export contacts #175
Answered
by
hajsf
abbasudo
asked this question in
WhatsApp protocol Q&A
Export contacts
#175
Replies: 1 comment 2 replies
-
// import "encoding/csv"
client.FetchAppState(appstate.WAPatchCriticalUnblockLow, true, false)
contacts, err := client.Store.Contacts.GetAllContacts()
if err != nil {
fmt.Println("Error reading contacts:", err)
}
fmt.Println("You have:", len(contacts), "contacts")
file, err := os.Create("contacts.csv")
if err != nil {
log.Fatalln("failed to open file", err)
}
// defer file.Close()
w := csv.NewWriter(file)
// defer w.Flush()
// Using Write
for jid, info := range contacts {
row := []string{
jid.User,
info.FirstName,
info.FullName,
info.PushName,
info.BusinessName,
strconv.FormatBool(info.Found),
}
if err := w.Write(row); err != nil {
log.Fatal("error writing record to file", err)
}
}
w.Flush()
file.Close() |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
abbasudo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there any way to export all contacts ? Or search them
Beta Was this translation helpful? Give feedback.
All reactions