Open tusharpl opened 6 years ago
This can be easily done using TextLocal. Create a Paid Account. Need an Email ID and Phone number. I think we can negotiate with them for this cause. Create an API Key. Call python API with the message, api key and numbers. Write Python script to receive the replies. If you have a contact I can work with for setting up accounts and integrating the scripts, please let me know I will work with that person. API to send messages
import urllib.request import urllib.parse
def sendSMS(apikey, numbers, sender, message): data = urllib.parse.urlencode({'apikey': apikey, 'numbers': numbers, 'message': message, 'sender': sender}) data = data.encode('utf-8') request = urllib.request.Request("https://api.textlocal.in/send/?") f = urllib.request.urlopen(request, data) fr = f.read() return (fr)
def main():
print("Sending messages") apiKey = 'xxxxx' numbers = 'xxxx' sender = 'TXTLCL' message = 'Please confirm if you are rescued' resp = sendSMS(apiKey,numbers,sender,message) print(resp) if name == 'main': main()
This seems to be a good idea about verifying through SMS . I am just testing some of the stuff on the website. You can reach one of devs probably @bobinson on slack.
All the sms make it as shared task using celery .
from celery import shared_task import requests @shared_task def send_sms_using_service(params): params['gateway'] = settings.SMS_GATEWAY headers = {'Authorization': settings.SMS_SERVICE_KEY} final_url = settings.SMS_SERVICE_URL try: resp = requests.post(final_url, data=json.dumps(params), headers=headers, timeout=5) return resp.text except requests.exceptions.Timeout: log.info("Sms attempt failed with timeout for {params}".format(params=params)) except Exception as e: log.info("Sms attempt failed with {e} for {params}".format(e=repr(e), params=params)) return "Sending SMS failed"
Write a model save function for the Request model . Here I am using sinfini sms gateway .
def save(self, *args, **kwargs):
#Confirmation SMS using SINFINI
if not self.id:
district = self.district
contact_numbers = Volunteer.objects.filter(district=district).values_list('phone', 'flat=True')
import requests
help_line = ",".join(contact_numbers)
message = "{district} district helpline numbers : {help_line} ".format(district=district, help_line=help_line)
params = {"message": message, "sender": settings.SMS_SENDER, "gateway":settings.SMS_GATEWAY,
"event": "rescure_request", }
headers = {'Authorization': settings.SMS_SERVICE_KEY}
final_url = settings.SMS_SERVICE_URL
try:
resp = requests.post(final_url, data=json.dumps(params), headers=headers, timeout=5)
return resp.text
except requests.exceptions.Timeout:
log.info("Sms attempt failed with timeout for {params}".format(params=params))
except Exception as e:
log.info("Sms attempt failed with {e} for {params}".format(e=repr(e), params=params))
return "Sending SMS failed"
super(Request, self).save(*args, **kwargs)
Subject of the issue
This is an enhancement.Now, once a request is raised on https://keralarescue.in/request/ , there is a web confirmation. However it will be more useful if there is also confirmation SMS which shows the contact numbers from the "Contact Info" page for the selected district. We know that not all people would be reaching out to all sources for help including this website. This will help them to try other numbers too while officials act on their request from https://keralarescue.in.
Your environment
Steps to reproduce
Log a request on https://keralarescue.in/request/ Submit it.
Expected behaviour
Currently a confirmation is shown on the web page.
Actual behaviour
An enhancement. An SMS could be sent with the relevant contact info numbers which would be useful.