Skip to content

Instantly share code, notes, and snippets.

@jsdaniell
Created March 23, 2021 18:53
Show Gist options
  • Select an option

  • Save jsdaniell/5bd7143987cb2890761e0fa784fcc3a0 to your computer and use it in GitHub Desktop.

Select an option

Save jsdaniell/5bd7143987cb2890761e0fa784fcc3a0 to your computer and use it in GitHub Desktop.
func Connect(w http.ResponseWriter, r *http.Request) {
// create new WhatsApp connection
cmd := exec.Command("./whats-cli", "connect")
stdout, _ := cmd.StdoutPipe()
err := cmd.Start()
if err != nil {
responses.ERROR(w, http.StatusInternalServerError, err)
}
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
m := scanner.Text()
png, err := qrcode.Encode(m, qrcode.Medium, 256)
if err != nil {
responses.ERROR(w, http.StatusBadRequest, err)
}
w.Write(png)
return
}
cmd.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment