Skip to main content

Python client for Puzzel SMS Gateway

Project description

Puzzel SMS Gateway Python Client

GitHub License Latest Version Supported Python versions Downloads Coverage GitHub issues GitHub last commit

Copyright 2024 Puzzel AS
Released under the MIT license.

Python client for the Puzzel SMS Gateway.

Contents

Prerequisites

python = "^3.10.5"
requests = "^2.28.1"
pydantic = "^1.9.1"
fastapi = "^0.78.0"

Please see pyproject.toml for the full citation information.

Installation

Using pip

python -m pip install puzzel_sms_gateway_client

Using Poetry

poetry add puzzel_sms_gateway_client

Usage

For all the following examples it is recommended to define the following needed variables as secrets in your repository, environment variables or as constants in the script.

Importing as a module

import puzzel_sms_gateway_client as smsgw

BASE_ADDRESS: str = "https://[YOUR_SERVER_ADDRESS]/gw/rs"
SERVICE_ID: int = [YOUR_SERVICE_ID]
USERNAME: str = "[YOUR_USERNAME]"
PASSWORD: str = "[YOUR_PASSWORD]"


client = smsgw.Client(
    service_id=SERVICE_ID,
    username=USERNAME,
    password=PASSWORD,
    base_address=BASE_ADDRESS,
)

response = client.send(
    messages=[
        smsgw.Message(
            recipient="+47xxxxxxxxx",  # Country code + phone number
            content="Hello World!",
        ),
    ]
)

Using classes directly

from puzzel_sms_gateway_client import (
    Client,
    GasSettings,
    Message,
    MessageSettings,
    OriginatorSettings,
    Parameter,
    SendWindow,
)


BASE_ADDRESS: str = "https://[YOUR_SERVER_ADDRESS]/gw/rs"
SERVICE_ID: int = [YOUR_SERVICE_ID]
USERNAME: str = "[YOUR_USERNAME]"
PASSWORD: str = "[YOUR_PASSWORD]"


client = Client(
    service_id=SERVICE_ID,
    username=USERNAME,
    password=PASSWORD,
    base_address=BASE_ADDRESS,
)

response = client.send(
    messages=[
        Message(
            recipient="+47xxxxxxxxx",  # Country code + phone number
            content="Hello World!",
            settings=MessageSettings(  # Optional
                send_window=SendWindow(
                    start_date="2022-07-13",
                    stop_date="2022-07-13", # Optional
                    start_time="15:20:00",
                    stop_time="15:30:00", # Optional
                ),
            ),
        ),
    ]
)

Using object instantiation

from puzzel_sms_gateway_client import (
    Client,
    GasSettings,
    Message,
    MessageSettings,
    OriginatorSettings,
    Parameter,
    SendWindow,
)

BASE_ADDRESS: str = "https://[YOUR_SERVER_ADDRESS]/gw/rs"
SERVICE_ID: int = [YOUR_SERVICE_ID]
USERNAME: str = "[YOUR_USERNAME]"
PASSWORD: str = "[YOUR_PASSWORD]"

gas_settings = GasSettings(
    service_code="02001",
    description="SMS",  # Optional
)

originator_settings = OriginatorSettings(
    originator_type="NETWORK",
    originator="1960",
)

send_window = SendWindow(
    start_date="2022-07-14",
    stop_date="2022-07-14",  # Optional
    start_time="09:20:00",
    stop_time="09:30:00",  # Optional
)

parameter = Parameter(  # All are optional
    business_model="contact center",
    dcs="F5",
    udh="0B0504158200000023AB0201",
    pid=65,
    flash=True,
    parsing_type="AUTO_DETECT",
    skip_customer_report_delivery=True,
    strex_verification_timeout="10",
    strex_merchant_sell_option="pin",
    strex_confirm_channel="sms",
    strex_authorization_token="some_token",
)

message_settings = MessageSettings(  # All are optional
    priority=1,
    validity=173,
    differentiator="sms group 1",
    invoice_node="marketing department",
    age=18,
    new_session=True,
    session_id="01bxmt7f8b8h3zkwe2vg",
    auto_detect_encoding=True,
    safe_remove_non_gsm_characters=True,  # Deprecated
    originator_settings=originator_settings,
    gas_settings=gas_settings,
    send_window=send_window,
    parameter=parameter,
)


client = Client(
    service_id=SERVICE_ID,
    username=USERNAME,
    password=PASSWORD,
    base_address=BASE_ADDRESS,
    batch_reference="some_batch_reference",  # Optional
)

message = Message(
    recipient="+47xxxxxxxxx",  # Country code + phone number
    content="Hello World!",
    price=100,  # Optional
    client_reference="some_client_reference",  # Optional
    settings=message_settings,  # Optional
)

response = client.send(messages=[message])

Sending message to multiple recipients

import json

from puzzel_sms_gateway_client import (
    Client,
    Message,
)

BASE_ADDRESS: str = "https://[YOUR_SERVER_ADDRESS]/gw/rs"
SERVICE_ID: int = [YOUR_SERVICE_ID]
USERNAME: str = "[YOUR_USERNAME]"
PASSWORD: str = "[YOUR_PASSWORD]"

recipients = [
    "+47xxxxxxxx1",  # Country code + phone number
    "+47xxxxxxxx2",  # Country code + phone number
]


client = Client(
    service_id=SERVICE_ID,
    username=USERNAME,
    password=PASSWORD,
    base_address=BASE_ADDRESS,
)

response = client.send(
    messages=[
        Message(
            content="Hello World!",
        )
    ],
    recipients=recipients,
)

print(json.dumps(response.json(), indent=4))

Output:

{
  "batchReference": "60908fdd-6da7-4658-b0f7-5685e513c19f",
  "messageStatus": [
    {
      "statusCode": 1,
      "statusMessage": "Message enqueued for sending",
      "clientReference": null,
      "recipient": "+47xxxxxxxx1",
      "messageId": "7a04egxihb00",
      "sessionId": null,
      "sequenceIndex": 1
    },
    {
      "statusCode": 1,
      "statusMessage": "Message enqueued for sending",
      "clientReference": null,
      "recipient": "+47xxxxxxxx2",
      "messageId": "7a04egxihc00",
      "sessionId": null,
      "sequenceIndex": 2
    }
  ]
}

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

puzzel_sms_gateway_client-2.0.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

puzzel_sms_gateway_client-2.0.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file puzzel_sms_gateway_client-2.0.1.tar.gz.

File metadata

  • Download URL: puzzel_sms_gateway_client-2.0.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.5 Darwin/23.0.0

File hashes

Hashes for puzzel_sms_gateway_client-2.0.1.tar.gz
Algorithm Hash digest
SHA256 fef0b801e115ab420cf1b8b7844c302e348dfbc5188177dcf98177ab22b920eb
MD5 46c922622c6d18b324f69328d20d03a5
BLAKE2b-256 682ec62e6b6c6fa195180765ad9b4d52760efac63b82166f265be2dcb17e37a7

See more details on using hashes here.

File details

Details for the file puzzel_sms_gateway_client-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for puzzel_sms_gateway_client-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 367fdda0af665764f2829d96407f38eef44145d245e14a43b0b3f644815295eb
MD5 7f4715189b6b20de2d30295dda26196e
BLAKE2b-256 c33966e78cbc356eb681c0f65dec2fa1edd9f75b3d621b7e73b0f4e1495b45a6

See more details on using hashes here.

Supported by

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