I have created multiple WhatsApp templates, but I am unsure of how to access them from the Twilio backend. Is there a way to access these templates?
Asked
Active
Viewed 37 times
0
-
Can you specify what you mean by access? Reading them programmatically or sending a message based on the templates? – IObert Jun 19 '23 at 08:55
-
@IObert Sending messages based on the templates. – Usman Afridi Jul 20 '23 at 06:05
1 Answers
1
You can send pre-approved template with the following code:
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client
import json
# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
message = client.messages.create(
content_sid='HXXXXXXXXX',
from_='MGXXXXXXXX',
content_variables=json.dumps({
'1': 'Name'
}),
to='whatsapp:+18551234567'
)
print(message.sid)
Go here for the full docs.

IObert
- 2,118
- 1
- 10
- 17
-
1Thank you so much. This is exactly what I was looking for. Never found it in the documentation at that time. Once again, thank you and really appreciate that! – Usman Afridi Jul 20 '23 at 07:36