clear-skies-twilio


Nameclear-skies-twilio JSON
Version 0.9.0 PyPI version JSON
download
home_pagehttps://github.com/cmancone/clearskies-twilio
Summaryclearskies bindings for working with Twilio
upload_time2024-04-25 17:33:30
maintainerNone
docs_urlNone
authorConor Mancone
requires_python<4.0,>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # clearskies-twilio

clearskies bindings for working with [Twilio](https://twilio.com/).  At the moment it's just an action to send an SMS.

# Installation

To install:

```
pip install clear-skies-twilio
```

# Usage

## Authentication

Before you can use this you need to setup authentication to Twilio.  This only works with [API keys](https://www.twilio.com/docs/iam/api-keys/api-key) from Twilio - **not** your auth token(s). Also, this module assumes that your authentication details are stored in your secret manager, so you provide paths to secrets in your secret manager.

**IMPORTANT**: This module is designed to fetch your Twilio credentials only when needed and will automatically re-fetch them from the secrets manager in the event of an authentication failure.  As a result, you can rotate your Twilio credentials at anytime: just drop the new credentials in your secret manager and your running processes will automatically find it and use it without needing to restart/rebuild/relaunch the application.  There are three "pieces" to authentication with Twilio:

 1. API Key
 2. API Secret
 3. Account SID

You have to tell the twilio module where these live in the secret manager.  We do that in the below example and also point clearskies to AWS Secrets Manager:

```
import clearskies
import clearskies_twilio
import clearskies_aws

application = clearskies.Application(
    SomeHandler,
    {
        "your": "application config",
    },
    bindings={
        "twilio": clearskies_twilio.di.twilio(
            api_key="/path/to/twilio/api_key",
            api_secret="/path/to/twilio/api_secret",
            account_sid="/path/to/twilio/account_sid",
        ),
        "secrets": clearskies_aws.secrets.SecretsManager,
    },
)
```

## Actions

Currently the only option available is an Action for sending SMS messages.  It accepts a message that should be a string or a callable that returns the SMS message and which can accept `model` (the model that triggered the action) as well as any other configured dependencies.  You must provide `from_number` and `to_number` which can be either a phone number, the name of one of the columns in the model, or callables which return the phone number.  Simple example:

```
import clearskies
from clearskies.column_types import uuid, string, created
from collections import OrderedDict
from clearskies_twilio.actions import sms

class User(clearskies.Model):
    def __init__(self, cursor_backend, columns):
        super().__init__(cursor_backend, columns)

    def columns_configuration(self):
        return OrderedDict(
            [
                uuid("id"),
                string("phone"),
                string("name"),
                created(
                    "created_at",
                    on_change=[
                        sms(
                            from_number="+15551234567",
                            to_number="phone",
                            message=lambda model: f"Welcome {model.name}!"
                        ),
                    ],
                ),
            ]
        )

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cmancone/clearskies-twilio",
    "name": "clear-skies-twilio",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Conor Mancone",
    "author_email": "cmancone@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/82/63/b37e325302a4b7f0f5613199fc4e4cd27118ca004b6ac745d323d23ad14b/clear_skies_twilio-0.9.0.tar.gz",
    "platform": null,
    "description": "# clearskies-twilio\n\nclearskies bindings for working with [Twilio](https://twilio.com/).  At the moment it's just an action to send an SMS.\n\n# Installation\n\nTo install:\n\n```\npip install clear-skies-twilio\n```\n\n# Usage\n\n## Authentication\n\nBefore you can use this you need to setup authentication to Twilio.  This only works with [API keys](https://www.twilio.com/docs/iam/api-keys/api-key) from Twilio - **not** your auth token(s). Also, this module assumes that your authentication details are stored in your secret manager, so you provide paths to secrets in your secret manager.\n\n**IMPORTANT**: This module is designed to fetch your Twilio credentials only when needed and will automatically re-fetch them from the secrets manager in the event of an authentication failure.  As a result, you can rotate your Twilio credentials at anytime: just drop the new credentials in your secret manager and your running processes will automatically find it and use it without needing to restart/rebuild/relaunch the application.  There are three \"pieces\" to authentication with Twilio:\n\n 1. API Key\n 2. API Secret\n 3. Account SID\n\nYou have to tell the twilio module where these live in the secret manager.  We do that in the below example and also point clearskies to AWS Secrets Manager:\n\n```\nimport clearskies\nimport clearskies_twilio\nimport clearskies_aws\n\napplication = clearskies.Application(\n    SomeHandler,\n    {\n        \"your\": \"application config\",\n    },\n    bindings={\n        \"twilio\": clearskies_twilio.di.twilio(\n            api_key=\"/path/to/twilio/api_key\",\n            api_secret=\"/path/to/twilio/api_secret\",\n            account_sid=\"/path/to/twilio/account_sid\",\n        ),\n        \"secrets\": clearskies_aws.secrets.SecretsManager,\n    },\n)\n```\n\n## Actions\n\nCurrently the only option available is an Action for sending SMS messages.  It accepts a message that should be a string or a callable that returns the SMS message and which can accept `model` (the model that triggered the action) as well as any other configured dependencies.  You must provide `from_number` and `to_number` which can be either a phone number, the name of one of the columns in the model, or callables which return the phone number.  Simple example:\n\n```\nimport clearskies\nfrom clearskies.column_types import uuid, string, created\nfrom collections import OrderedDict\nfrom clearskies_twilio.actions import sms\n\nclass User(clearskies.Model):\n    def __init__(self, cursor_backend, columns):\n        super().__init__(cursor_backend, columns)\n\n    def columns_configuration(self):\n        return OrderedDict(\n            [\n                uuid(\"id\"),\n                string(\"phone\"),\n                string(\"name\"),\n                created(\n                    \"created_at\",\n                    on_change=[\n                        sms(\n                            from_number=\"+15551234567\",\n                            to_number=\"phone\",\n                            message=lambda model: f\"Welcome {model.name}!\"\n                        ),\n                    ],\n                ),\n            ]\n        )\n\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "clearskies bindings for working with Twilio",
    "version": "0.9.0",
    "project_urls": {
        "Homepage": "https://github.com/cmancone/clearskies-twilio",
        "Repository": "https://github.com/cmancone/clearskies-twilio"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e900e105f65cef316c1469f709b1e5412f92c94167ccfb6b129c72fb14c1dc73",
                "md5": "2b2757b887117c4e815a29675e8b5639",
                "sha256": "1630f08594caf203c010523710421288768ff6ba0c4e7c005fdf03fa927c3922"
            },
            "downloads": -1,
            "filename": "clear_skies_twilio-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2b2757b887117c4e815a29675e8b5639",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 7345,
            "upload_time": "2024-04-25T17:33:29",
            "upload_time_iso_8601": "2024-04-25T17:33:29.134868Z",
            "url": "https://files.pythonhosted.org/packages/e9/00/e105f65cef316c1469f709b1e5412f92c94167ccfb6b129c72fb14c1dc73/clear_skies_twilio-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8263b37e325302a4b7f0f5613199fc4e4cd27118ca004b6ac745d323d23ad14b",
                "md5": "fa33c7eb9afb4af9911311470cd07699",
                "sha256": "18709208f4a82468db074142856ff66dfd1b19933e1b82dad5cedf57809a2fe0"
            },
            "downloads": -1,
            "filename": "clear_skies_twilio-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fa33c7eb9afb4af9911311470cd07699",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 5786,
            "upload_time": "2024-04-25T17:33:30",
            "upload_time_iso_8601": "2024-04-25T17:33:30.920552Z",
            "url": "https://files.pythonhosted.org/packages/82/63/b37e325302a4b7f0f5613199fc4e4cd27118ca004b6ac745d323d23ad14b/clear_skies_twilio-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-25 17:33:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cmancone",
    "github_project": "clearskies-twilio",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "clear-skies-twilio"
}
        
Elapsed time: 0.23118s