Any way to retrieve phone number from incoming sms in autopilot - python

I am creating a Twilio Autopilot program that works on the SMS channel. Currently, I set up the sms channel using the messaging URL and webhooks according to the instructions in the SMS setup section here: https://www.twilio.com/docs/autopilot/guides/how-to-build-a-chatbot.
This works, but I am trying to find a way to retrieve the phone number from the incoming SMS to try and match it to a user to provide context to the bot ahead of time. Is there any way to accomplish this?
I am coding this in Python but any advice would be appreciated regardless of language.

The Autopilot webhook request is documented here and shows the parameters that are sent with each request.
In this case, you are looking for the UserIdentifier parameter in the incoming request, which, in the case of voice or SMS channels, will be the user's phone number.
Note that the request is made in the application/x-www-form-urlencoded format.

Related

Can a telebot be able to send sms to its user?

I'm trying to make a telegram not which at some point is like to send an SMS to the user or verify something through SMS but I'm not sure if the telegram API allows for that. If it is possible, please his can I utilize it?
Note:I'm just a beginner in python so some things might seem unclear to me so please be easy on me
Firstly, Telegram bot API has nothing to do with user phone numbers. Due to a variety of security reasons, it doesn't give bots access to such information and if we just suppose that, why should it send SMS? It's not the responsibility of a messenger like Telegram.
You can just send users notifications on Telegram or asks them for their numbers, then send SMS by another service.

Add twilio webhooks dynamically from a multi-tenant django application with subdomains for twiml

I have tested twilio's twiML api for sending and receiving text messages in application and it worked well.
However I had to ngrok the specific test sub-domain I was testing from as the receiving Webhook on Twilio panel. In real use case, because it's a multi-tenant application, this needs to be dynamic, not just a single Webhook endpoint e.g www.first.mysite.com/sms-chat-bot, www.second.mysite.com/sms-chat-bot etc etc.
The question is, how do I achieve this either via twiml or twilio rest api (couldn't find a single documentation on this, as everything seems to favour Webhooks).
Twilio developer evangelist here.
You can dynamically set the incoming webhook URL for a number using the Incoming Phone Number resource through the REST API.
I'm not sure if this is what you're asking, but numbers can only have one webhook URL per SMS or Voice. So, if you need to fan out incoming requests to different URLs, you will need to write one webhook endpoint yourself, that can then send the requests on. But hopefully you're just looking for how to keep numbers up to date.

Check if number has opted out in twilio

I am building a web application that needs to be able to send SMS messages and check if a number has opted out of SMS. The only option that I have found is to use a web-hook for SMS replies and check there.
I am looking for an option where I can just ping the API and check if a number has been opted-out.
Opt-outs are handled on your side, so you will need to keep track when opt-out keywords are sent toward your application and if so, update your CRM to remove the consumers mobile number from receiving future SMS.
If you attempt to send an SMS to an opted-out consumer, you will receive an error message from Twilio.
ERROR - 21610 - Attempt to send to unsubscribed recipient
Twilio support for opt-out keywords (SMS STOP filtering)
"These messages will also be delivered to your Twilio account, and the defined web hook, so you can update your application logic."

Sending SMS texts in Python without the need for a 3rd party API?

Does anyone know what would go into sending text messages with Python WITHOUT the need for a 3rd party API? What knowledge do I need to have to achieve such a thing? I've only been coding for a few months, so I still consider myself fairly new and there's a lot I don't know about networking. I know there are services like Twilio that offer a python library for sending text messages, but if I wanted to type out my own script, from scratch, what would need to go into it. I'm willing to read some documentation if that's necessary as long as it's not hundreds of pages long. Being as detailed as possible in your response is greatly appreciated. Thanks!
This can be done by sending an email via SMTP to the SMS gateway of the carrier of the recipient phone number. Each carrier has a unique email address usually in the form of {number}#{host}. Within Python, you can use the builtin smptlib (or aiosmtplib) library to send the email. I wrote an example script here to send using GMail.
Please tell me if I did not understand your question correctly, then I will try to improve it or I'll delete it.
Sending an SMS requires something, that can send an SMS. Which is normally not your laptop / PC, except it has a SIM card and a mobile phone modem. So you need a mobile phone or a service, that offers sending SMS if you subscribe / pay.
Most professional available services allow to send an SMS with simple HTTP GET or POST requests, so you don't need a third party python module, but you must connect to a third party web API in most cases the python code is really simple, but first you need an SMS service provider
Some services also allow sending SMS via SMTP (sending emails) which
#acamso adresses in his response
If you have an Android device you could install shellms on it ( https://f-droid.org/en/packages/com.android.shellms/ ) connect it via USB to your PC and use adb to send SMS, which will be billed on your phone's bill / contract.
I am not aware of any SMS service, that is for free, so if you subscribe to an SMS provider it will provide you with an API, that can normally very easily be handled from python.

How to send SMS using Python/Django application?

I have to develop an application where I need to send SMS to the users on a particular action by the users.
I have heard of kannel with PHP, is there some help for the same in Python as well or is there any other better open source sms gateway which I can use with my application?
Please suggest.
Thanks in advance.
Typically you would use normal HTTP GET or POST requests against an SMS Gateway, such as Clickatell and many many others.
Twilio (where I work) has an OSS Python helper library which makes working with their SMS service really easy.
I was struggling with this for some time and really liked the Twilio option. But then I dug deeper and found that there is a Google Voice API called pygooglevoice that works. Clean, easy... No carrier lookup... For example, set up a virtualenv and install with pip:
pip install pygooglevoice
Then use something like this:
from googlevoice import Voice
from googlevoice.util import input
def send(number, message):
user = 'user#gmail.com'
password = 'password'
voice = Voice()
voice.login(user, password)
#number = input('Number to send message to: ') # use these for command method
#message = input('Message text: ')
voice.send_sms(number, message)
Please note that I have done limited testing with this so I'm not sure all the pros and cons. It's quite possible that there are limitations I haven't discovered yet. But in the time I've played around with it, I've been happy.
[Update] Since the email based solution won't work for you, check out Twilio. Clean APIs, and I hear good things about them.
If you know the carrier the user is on it might be easiest to use the email-to-sms services provided by just about all of the mobile carriers. Here's an article on addresses for many providers.
If that works for you (eg. if you know the number/carrier beforehand or you can ask the user for the carrier as well as their number), then all you have to do is send email to the appropriate address and it'll be sent as an SMS to the user.
Take a look at django-smsgate (BSD licensed) application for working with SMS through SMS gateways.
I just wrote a basic Twilio demo app using Django, which sends SMS messages to users and also processes the SMS responses. I posted the code to github and wrote some explanatory blog posts.
The top level post is here but you can just grab all the code from GitHub. Note that my particular example uses LinkedIn for authentication, but the second and third blog posts cover twilio specific methods. That way you can see if this is an option that'll work for you.
Hope this helps :-)

Categories

Resources