Skip to main content

clearskies bindings for working with Twilio

Project description

clearskies-twilio

clearskies bindings for working with Twilio. 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 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(
            path_to_api_key="/path/to/twilio/api_key",
            path_to_api_secret="/path/to/twilio/api_secret",
            path_to_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}!"
                        ),
                    ],
                ),
            ]
        )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clear_skies_twilio-0.9.4.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

clear_skies_twilio-0.9.4-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file clear_skies_twilio-0.9.4.tar.gz.

File metadata

  • Download URL: clear_skies_twilio-0.9.4.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/6.5.0-44-generic

File hashes

Hashes for clear_skies_twilio-0.9.4.tar.gz
Algorithm Hash digest
SHA256 3e448fcc6d62092999b1641b7c564ca9bad958c621ba4c5adfea2556313af009
MD5 2304fc2fce0dfc54587bc39067b4cd9e
BLAKE2b-256 c7c0f0b6ccdb05fa0e0ab1a203d664f2526e64ebb9b2d813ae8120481dff06b9

See more details on using hashes here.

File details

Details for the file clear_skies_twilio-0.9.4-py3-none-any.whl.

File metadata

File hashes

Hashes for clear_skies_twilio-0.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fe06cc71a62774ec19adea2129815e7529137eba628589d2ff2dc8ef85c0b052
MD5 3a1083cd4ef9a06560a272e64561f292
BLAKE2b-256 0ef0170087f3b037a3b131e684890a09d878a45ed06f2b30aafd590a4a28dbc2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page