I am trying to send sms using python and twilio. I am actually sending 1000-2000 sms. so while sending I get errors like :
30032 - Toll-Free Number Has Not Been Verified
21610 - Attempt to send to unsubscribed recipient
so here what I am trying. I have a form inside my dashboard. When I will press send button it will start sending message to every one. when someone blocks my number from there side the whole process get closed and I had to send messages or remove them from my list again and again.
Here is views.py
class AdminIndex(View):
template_name = "AdminPage/index.html"
def get(self, request):
contents = ContentTemplate.objects.all()
numbers = NumberGroup.objects.all()
groups = Group.objects.all()
args = {
"contents": contents,
"numbers": numbers,
"groups": groups
}
return render(request, self.template_name, args)
def post(self, request):
content = request.POST.get("content")
number = request.POST.get("number")
groups = request.POST.get("group")
if request.method == "POST":
message = SendMessageModel(
content=ContentTemplate.objects.get(id=content),
number=NumberGroup.objects.get(id=number),
group=Group.objects.get(id=groups)
)
message.save()
for n in message.group.customers.all():
account_sid = "AC2b0cc7c783ccc1e82f3771636dda5e73"
auth_token = "bdb32f3656485e868270f68a1b3024ee"
client = Client(
account_sid, auth_token
)
send_message = client.messages.create(
body=message.content.content,
from_=f"+{message.number.number}",
to=n.phone_number,
)
n.is_sent = True
print(str(n.phone_number))
n.save()
return HttpResponse("All Sent")
So, How can I ignore these errors and keep sending messages to the users without interruption?