Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EOF error #2

Closed
nuliknol opened this issue Jan 25, 2023 · 1 comment
Closed

EOF error #2

nuliknol opened this issue Jan 25, 2023 · 1 comment

Comments

@nuliknol
Copy link

when using this code I am getting EOF error:

err := godotenv.Load()
if err != nil {
	fmt.Printf("Can't load env: %v\n",err)
	os.Exit(1)
}
my_phone_id := os.Getenv("WHATSAPP_PHONE_ID")
token := os.Getenv("WHATSAPP_TOKEN")
fmt.Printf("Phone %v\n",my_phone_id)
fmt.Printf("token %v\n",token)
wa := whatsapp.NewWhatsapp(token,my_phone_id)
wa.APIVersion = "v15.0"

res, err := wa.SendText("XXXXXXXXXXXX", "your_message")

if err != nil {
	fmt.Printf("Error: %v\n",err)
	os.Exit(1)
}

fmt.Printf("Message sent successfuly\n")
fmt.Printf("res = %v\n",res)
os.Exit(0)

any idea of what to look for? I can send hello world message from terminal using curl so my dev account is set up correctly. If I send the message using template, I get an error of type Error: (#132001) Template name does not exist in the translation but that is probably because you hardcoded Indonesian language into createSendWithTemplateRequest() function

@nuliknol
Copy link
Author

found the error, the line

err = json.NewDecoder(resp.Body).Decode(&res)

must be changed for:

err = json.NewDecoder(bytes.NewReader(bodyBytes)).Decode(&res)

in helper.go, function sendMessage()
otherwise it won't work, and I wonder how did that work at all in the first place (never worked for me as the buffer is emptied after ReadAll().

and btw, the messages won't be sent because you need to initiate a conversation first with the test account that creates the messages (it is anti-spam measure from Meta). the messages will be silently discared without error if you don't initiate the conversation first

febriliankr added a commit that referenced this issue Mar 13, 2023
febriliankr added a commit that referenced this issue Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant