Hello Team Below is my code for sending WhatsApp chat messages using a CSV file it works for some time, then suddenly it stops to iterate through all and it stops at only row one or hangs to iterate through the CSV am not sure if it's the Facebook endpoint with an issue or limit
import csv
import http.client
import json
# Open the CSV file and read it line by line
with open('chat_messages.csv', 'r') as csv_file:
reader = csv.reader(csv_file)
# Skip the header row
next(reader)
for row in reader:
chat_number = int(row[0])
chat_message = row[1]
chat_channel = row[2]
chat_response = row[3]
chat_expiry_method = row[4]
chat_expiry_date = row[5]
# Send Chat
conn = http.client.HTTPSConnection("graph.facebook.com")
payload = json.dumps({
"messaging_product": "whatsapp",
"to": chat_number,
"type": "template",
"template": {
"name": "hello_world",
"language": {
"code": "en_US"
}
}
})
headers = {
'Authorization': 'Bearer xxxxxyyyyyyy',
'Content-Type': 'application/json'
}
conn.request("POST", "/v15.0/3335355343232/messages", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Here is my CSV
chat_number,chat_message ,channel,response ,expiry_method,expiry_date
25677xxxxxxx,Your Message 2,whatsapp,1,Manual,08/02/2022
25471yyyyyyy,Your Message 3,whatsapp,1,Manual,06/02/2022
25575zzzzzzz,Your Message 1 ,whatsapp,1,Manual,09/02/2022
at some point when I stoped printing the repones from fakebook endpoint it worked for all lines int he CSV but after multiple executions it failed
I comment out this code
#res = conn.getresponse()
#data = res.read()
#print(data.decode("utf-8"))
after some time it start processing only one line and stops