0

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?

Usman Afridi
  • 179
  • 1
  • 11

1 Answers1

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
  • 1
    Thank 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