{ "info": { "author": "renaud gaudin", "author_email": "rgaudin@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication", "License :: Public Domain", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5" ], "description": "orangeapisms\n=========================\n\n.. image:: https://img.shields.io/pypi/v/orangeapisms.svg\n :target: https://pypi.python.org/pypi/orangeapisms\n.. image:: https://api.travis-ci.org/rgaudin/django-orangeapisms.svg\n :target: https://travis-ci.org/rgaudin/django-orangeapisms\n\nDjango app to add support for Orange API SMS-MO and SMS-MT (with DR)\n\nInstall\n--------\n\n* `pip install orangeapisms`\n* Edit your `settings.py` file and add: \n\n.. code-block:: python\n\n INSTALLED_APPS = list(INSTALLED_APPS) + ['orangeapisms', 'django_forms_bootstrap']\n\n* Configure your `orangeapi.json` file (place it next to your `settings.py` file): \n\n.. code-block:: json\n\n {\n \"handler_module\": \"myapp.orange_handler\",\n \"use_db\": true,\n \"sender_address\": \"+22300000000\",\n \"sender_name\": \"POTUS\",\n \"client_id\": \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\n \"client_secret\": \"xxxxxxxxxxxxxxxx\",\n \"enable_tester\": true,\n \"default_sender_name\": \"sender_address\"\n }\n\n* Setup Database with `./manage.py migrate`\n\nThat's it ! Test it by accessing `/oapi/` and playing with the tester.\n\n:**client_id**: Your Client ID (mandatory)\n:**client_secret**: Your Client Secret (mandatory)\n:**handler_module**: python path to your module handling messages (mandatory)\n:use_db: whether to store SMS in DB (SMSMessage Model)\n:smsmt_url: URL of your API (might change depending on your plan)\n:oauth_url: OAuth URL for Orange API\n:sender_address: Your subscribed phone number\n:sender_name: Your custom sender name (can be number or string)\n:enable_tester: To enable tester & logs WebUI on /oapi/\n:default_sender_name: What to use as default sender name\n:send_async: whether to deffer SMS sending to celery\n:celery_module: python path to your celery tasks module\n:country: ISO 3166-1 code for your country (used for balance checking)\n:fix_msisdn: whether to fix SMS-MT destination without prefix\n:country_prefix: MSISDN numeric prefix for your country (to fix SMS-MT without prefix)\n\n\nUsage\n--------\n\nAfter installation (previous step), you are able to send & receive individual SMS.\nTo automatically process incoming SMS, you will have to customise the *handler module* which you specified in `ORANGE_API['handler_module']`.\n\nThe module would call three different functions based on events:\n\n* `smsmo(message)` on an incoming SMS-MO\n* `smsmt(message)` on an outgoing (sent by you) SMS-MT\n* `smsdr(message)` on an incoming delivery-receipt notification. The passed message is the SMS-MT which received the DR. \n\n\n\n**Sample handler module:**\n\n.. code-block:: python\n\n import datetime\n import logging \n\n from orangeapisms.utils import send_sms\n from myapp.models import UserModel \n\n logger = logging.getLogger(__name__) \n \n\n def handle_smsmo(message):\n logger.info(\"Received an SMS-MO: {}\".format(message)) \n\n def register_user(message, keyword, text):\n # break-down the formatted SMS into variables\n try:\n name, sex, dob = text.split()\n except:\n return message.reply('Invalid format') \n\n # valid user entries\n if sex not in ['m', 'f']:\n return message.reply('Unable to understand sex') \n\n # reuse input into different data structure\n try:\n d = dob.split('-')\n birthdate = datetime.datetime(d[3], d[2], d[1])\n except:\n return message.reply('Unable to understand date of birth') \n\n # make use of the data including message metadata\n user = UserModel.objects.create(\n name=name, sex=sex, dob=birthdate,\n phone=message.sender_address) \n\n return message.reply(\"Congratulations, you're registered as #{}\"\n .format(user.id)) \n\n def broadcast_to_users(message, keyword, text):\n # loop on all Users in DB\n for user in UserModel.objects.all():\n # send a custom message to that user\n send_sms(user.phone, \"Hey {u}, {c}\".format(u=user.name, c=text)) \n\n keywords = {\n 'register': register_user,\n 'broadcast': broadcast_to_users,\n } \n\n # find the proper keyword\n keyword, text = message.content.split(' ', 1)\n if keyword in keywords.keys():\n return keywords.get(keyword)(message, keyword, text.strip().lower()) \n\n # fallback on error\n return message.reply('Unknown request') \n \n\n def handle_smsmt(message):\n logger.info(\"Sent an SMS-MT: {}\".format(message)) \n \n\n def handle_smsdr(message):\n logger.info(\"Received an SMS-DR: {}\".format(message))\n\nUsing a broker to send SMS-MT\n-----------------------------\n\nBy default, SMS-MT are sent synchronously meaning your request is stalled until the API call is complete.\n\nIf you need to send multiple SMS-MT while not blocking the request thread, you will want to defer sending to a broker.\n\nThis library integrates easily with `celery` so you can do just that in a breeze.\n\nTo use Asynchronous SMS-MT sending, you will need to :\n\n* Install and configure celery onto your project (see instructions bellow if needed)\n* Edit your `settings.py` to include the following options\n\n.. code-block:: python\n\n # wether to send asynchronously or not\n 'send_async': True,\n # python path of your celery module containing the task\n 'celery_module': 'myproject.celery'\n\n* Add a custom task to your celery module\n\n.. code-block:: python\n\n\t@app.task()\n\tdef submit_sms_mt_request_task(payload, message):\n\t from orangeapisms.utils import do_submit_sms_mt_request\n\t return do_submit_sms_mt_request(payload, message)\n\nThat's it. Now every SMS-MT will be deferred to celery and processed by your broker.\n\nLaunch a `celery` worker to test it!\n\nBasic celery configuration\n--------------------------\n\nIf you are not familiar with celery and want to quickly test the async feature, follow this steps:\n\n* Install redis on your computer and start it\n\n.. code-block:: bash\n\n sudo apt-get install redis\n service redis start\n\n* Install celery and redis with ```pip install celery redis```\n\n* Add the celery configuration to your `settings.py`:\n\n.. code-block:: python\n\n BROKER_URL = 'redis://localhost:6379/0'\n CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'\n\n* Create a module in your project for `celery`:\n\n.. code-block:: python\n\n import os \n\n from celery import Celery \n\n os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')\n app = Celery('project')\n app.config_from_object('django.conf:settings') \n \n\n @app.task()\n def submit_sms_mt_request_task(payload, message):\n from orangeapisms.utils import do_submit_sms_mt_request\n return do_submit_sms_mt_request(payload, message)\n\n* Launch a worker\n\n.. code-block:: python\n\n celery -A project worker -l info", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/rgaudin/django-orangeapisms", "keywords": "orange api sms", "license": "Public Domain", "maintainer": null, "maintainer_email": null, "name": "orangeapisms", "package_url": "https://pypi.org/project/orangeapisms/", "platform": "any", "project_url": "https://pypi.org/project/orangeapisms/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/rgaudin/django-orangeapisms" }, "release_url": "https://pypi.org/project/orangeapisms/0.28/", "requires_dist": null, "requires_python": null, "summary": "Django app to add support for Orange API SMS-MO, SMS-MT/DR", "version": "0.28" }, "last_serial": 2493448, "releases": { "0.28": [ { "comment_text": "", "digests": { "md5": "200a3f047c0a305762a5a7660d212553", "sha256": "c9aa5f4a117bbecaec2d0fd4a994556327ebe0e4dd6aa0b85b810cadc3b9ceb7" }, "downloads": -1, "filename": "orangeapisms-0.28.tar.gz", "has_sig": false, "md5_digest": "200a3f047c0a305762a5a7660d212553", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17791, "upload_time": "2016-12-01T10:44:29", "url": "https://files.pythonhosted.org/packages/c4/5a/f3b7863dd50eb1042ae5899972146e3cefe6869d65f64ba85916d8e3b802/orangeapisms-0.28.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "200a3f047c0a305762a5a7660d212553", "sha256": "c9aa5f4a117bbecaec2d0fd4a994556327ebe0e4dd6aa0b85b810cadc3b9ceb7" }, "downloads": -1, "filename": "orangeapisms-0.28.tar.gz", "has_sig": false, "md5_digest": "200a3f047c0a305762a5a7660d212553", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17791, "upload_time": "2016-12-01T10:44:29", "url": "https://files.pythonhosted.org/packages/c4/5a/f3b7863dd50eb1042ae5899972146e3cefe6869d65f64ba85916d8e3b802/orangeapisms-0.28.tar.gz" } ] }