Hanan
Hanan

Reputation: 1445

Twilio whatsapp message fails even when matches the approved template

I am trying to send a whatsapp message via Twilio Business Account, from a number my company has registered via twilio and configured to be a sender. In the Twilio logs, I see error 63016 message not in template, even though I double-checked every word and spacing to see that my message matches the approved template

some code to help:

def send_message(phone, template_message):
try:
    message = twilio_client.messages.create(
        body=template_message,
        from_=f'whatsapp:{MY_SENDER_NUMBER}',
        to=f'whatsapp:{phone}'
    )
except TwilioRestException as e:
    return False, e.msg
return True, ''

this completes with no error and results in this log line in twilio

From,To,Body,Status,SentDate,ApiVersion,NumSegments,ErrorCode,AccountSid,Sid,Direction,Price,PriceUnit

"whatsapp:+XXXXXXXXXXXX","whatsapp:+XXXXXXXXXXXX","MY MESSAGE THAT MATCHES THE TEMPLATE, WITH SOME NEWLINES! AND some characters like '' and , ",UNDELIVERED,2021-04-11T07:58:32Z,"2010-04-01",1,63016,XXXXXXXXXXXXXXXXXXXXXXXXXXXXx,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx," outbound-api",0.0,USD

note: if I open my whatsapp and sends the sender a message, then if I run this code again it will work and I will see that message (as that message does not have to match a template for a 24-hr window).

Upvotes: 4

Views: 6620

Answers (4)

Tushar Niras
Tushar Niras

Reputation: 3873

A slight change in WhatsApp template can cause this error. I would recommend below mentioned guidelines.

  1. Copy Template as it is from "Message text" column of WhatsApp Template

  2. Carefully use "\n" for newline.

  3. Careful with whitespaces.

  4. If you are using Python, here is an example:

    import os from twilio.rest import Client account_sid = 'account_id' auth_token = 'auth_token' client = Client(account_sid, auth_token)

    body = "Hello Rakesh,\nThe amount of rupees 45000 is received by Kaveri Enterprise for 1BHK.\n\nOutstanding Amount: 12000.\n\nThanks,\nKaveri Enterprise"

    message = client.messages.create( body=body, from_='whatsapp:+193939992323', to='whatsapp:+910099038393' ) print(message.sid)

Upvotes: 0

Max
Max

Reputation: 1548

In our case, the white space was replaced by a special character which was a looking like a whitespace.

enter image description here

Upvotes: 1

Cristian Rennella
Cristian Rennella

Reputation: 727

I had the same problem, but was due to just a simple whitespace.

Upvotes: 1

Hanan
Hanan

Reputation: 1445

After help from Twilio support, it was a missing '\n' in the message that I was trying to send, that caused the message not to match the template.

Upvotes: 1

Related Questions