How to send SMS using Python/Django application? - python

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 :-)

Related

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.

Trying to make a whatsapp bot

I am trying to make a WhatsApp bot inspired by the functioning of Discord bots, the bot will work in WhatsApp groups.
I have looked up the official WhatsApp Business API but I am not sure that they will not approve my number as it is just a hobby project and not a proper "business".
There is an alternative though and that is the Twilio WhatsApp API. However, they provide you with a sandbox. I can interact with it in DMs but as the sandbox number is a business account, I cannot add it to a group like discord.
I intend to write a server in python or node.
Can anyone share a solution or workaround? Only if I could add the Twilio number to a group my problem will be solved. Though I am ready to use any other API/Solutions for this.
There is actually a Python solution for this. It is a pain to set it up, but it still works. Check it out:
https://github.com/mukulhase/WebWhatsapp-Wrapper
It uses the webdriver Selenium to send/retrieve messages through Web-WhatsApp.
Be aware that it is against their rules, so your phone number might get banned!

Tell a friend in django

I am looking for a generic Tell a Friend application in django which will allow my website users to invite and tell about website features to one's mail or social networking friends by sending invitation email to join the website....
Any suggestion will help...
Thanks in advance...
This isn't Django, but you might consider a remotely-hosted application like ShareThis.
Otherwise, you could make use of this code, and add parameters (such as name and email address) into the URL where possible / necessary. In any case, I'm not aware of a Django-specific solution that integrates with the CMS out of the box - you might have to do it yourself, at least partly.
There's a reusable app at github called django-tellafriend.
Haven't used it myself. In the essence however it shouldn't be to hard to roll your own app for this if you have special requirements. Basically you need a form and send out an email if it's valid. If you want to keep track of the you can store the information using a simple model.
Connecting to social networks might be a little trickier, but there are also a few django apps for this like django-facebook and django-social-auth.

XMPP intregration with Facebook Chat, using Python

I'm starting a project using the XMPP protocol and haven't done anything with it thus far. I would like some advice/direction in regards to my questions below.
At the present moment, I know Facebook's Chat API says to use PyXMPP and pyFacebook, which is what I will be using initially. However can someone give me an idea as to how to connect Facebook chat with Gtalk; using their example script, located here:: http://developers.facebook.com/docs/chat/
I see that they mention API keys, where exactly do I retrieve the API keys from? Thanks.
You need to register your application at http://developers.facebook.com/apps and get the API keys. Both Gtalk and Facebook chat are built on XMPP protocol. So you can set up an XMPP chat client which will connect to both.
Refer to the book written by Jack Mofitt: http://professionalxmpp.com/
It talks about setting up the chat client. Also the documentation in the Developers forum is bad. Check out this thread from the old forum http://forum.developers.facebook.net/viewtopic.php?id=51892
Yes you can connect using digest MD5, where you need to pass the username and password. Go through the XMPP protocol to get a better understanding on digest MD5.

How do I enable SMS notifications in my web apps?

I have a web application and I would like to enable real time SMS notifications to the users of the applications.
Note: I currently cannot use the Twitter API because I live in West Africa, and Twitter doesn't send SMS to my country.
Also email2sms is not an option because the mobile operators don't allow that in my country.
There are a couple of options.
Get some kind of SMS modem or connectivity and use your own cell phone using smslib. I am sorry I don't provide python interfaces but my experience is Java. The downside is that you will pay the full consumer rate. And you will have to put a cell phone on your data center.
Connect to SMPP gateway. You will have to talk to the mobile operator in order to make this work. There is a library called jsmpp here. Again, I am sorry it is not python.
If it is too much of a hassle you could use an intermediary, which provides HTTP-SMS gateways, like this one. That's easy because you don't need to use SMPP and your system administrators wont bark at you for putting cell phones in the datacenter.
What about using a proper sms gateway. These guys got APIs for several languages:
http://www.clickatell.com/developers/php.php
There is an unofficial Python API too
http://www.arnebrodowski.de/projects/clickatell/
Another SMS gateway with a Python interface is TextMagic. Their Python API is available from the Google Code project textmagic-sms-api-python. They have libraries available for other languages as well; all wrapping a simple HTTPS API.
Code samples from the project website:
How to send an SMS:
import textmagic.client
client = textmagic.client.TextMagicClient('your_username', 'your_api_password')
result = client.send("Hello, World!", "1234567890")
message_id = result['message_id'].keys()[0]
And retrieve its delivery status:
response = client.message_status(message_id)
status = response[message_id]['status']
(Full disclosure: I am the author of the Python wrapper library)
The easiest way to accomplish this is by using a third party API. Some I know that work well are:
restSms.me
Twilio.com
Clicatell.com
I have used all of them and they easiest/cheapest one to implement was restSms.me
Hope that helps.
I don't have any knowledge in this area. But I think you'll have to talk to the mobile operators, and see if they have any API for sending SMS messages.
You'll probably have to pay them, or have some scheme for customers to pay them. Alternatively there might be some 3rd party that implements this functionality.
Warning: extremely elegant solution ahead! (Android app)
If you want to send SMS to any number in as simple of a manner as sending an e-mail:
mail('configuredEMail#configuredDomain', '0981122334', 'SMS message'); // PHP
or even:
echo 'SMS message' | mail -s '0981234567' configuredEMail#configuredDomain.com
or even from a GUI mail client, then read on.
To skip explanations google Evorion SMS Gateway.
What does it do? It forwards e-mail to SMS with a built-in battery saver.
In order to send an SMS you simply send an email to 'configuredEMail#configuredDomain.com' with Subject 'phoneNumberToForwardTo'.
Code contributions welcome.
If your country is in this list, Twilio is an extremely easy API to use :)

Categories

Resources