WhatsApp - HomeMadePy/messages GitHub Wiki
The whatsapp module provides an easy and intuitive interface to construct and send WhatsApp messages. Currently this feature is only implemented via the Twilio-WhatsApp API, thus you need a Twilio number and account to use.
WhatsApp API
WhatsApp(**from_**=None, to=None, auth=None, body='', attachments=None, verbose=False)
- from_: (str) The phone number the message will originate from, i.e. '+16195553232'.
- to: (str) [required] The destination phone number.
- body: (str) [optional] The body text of the message to send. Use body text from a file by setting body=file.read().
- auth: (list or tuple) Twilio api credentials: (acct_sid, auth_token). May use environment variables to pull auth credentials or whatever means you feel necessary.
- attachments: (str) [optional] a url, who's content you wish to attach in the message, such as a url for a picture.
- verbose: (bool) [optional] print verbose output.
Usage
After instantiating a WhatsApp object, using the API above, the following method can be used to send the message:
- send(): sends the message synchronously
Example
Script/REPL
>>> from messages import WhatsApp
>>> w = WhatsApp(
from_='+16195553232',
to='+16198675309',
auth=('ACjfkldjl', 'asdjfklsdfianfd'),
body='TestMessage',
attachments='https://imgs.xkcd.com/comics/python.png',
)
>>> w.send()
Message sent...
Twilio Service
In order to use this service, you must register with twilio, purchase a from_ number, get the required API credentials, and register the from_ number for the WhatsApp API sandbox. This is a paid service.