Skip to main content

Django app to make sending transactional messages to Semaphore a breeze!

Project description

Jsmsgr

An easy way to publish transactional messages (SMS, EMAIL, etc.) to Semaphore for their publication!

Requirements

This app requires two other apps to work properly:

  • jsm-user-services;
  • django-stomp.

Both apps must have been configured properly. Their configs are as follows, including jsmsgr lib:

########################
# Django settings file #
########################
import os

INSTALLED_APPS = [
    "...",
    "django_stomp",
    "jsm_user_services",
    "jsmsgr",  # add this lib to the INSTALLED_APPS
]

# django-stomp config
STOMP_SERVER_HOST = os.getenv("STOMP_SERVER_HOST")
STOMP_SERVER_PORT = os.getenv("STOMP_SERVER_PORT")
STOMP_SERVER_USER = os.getenv("STOMP_SERVER_USER")
STOMP_SERVER_PASSWORD = os.getenv("STOMP_SERVER_PASSWORD")
STOMP_USE_SSL = os.getenv("STOMP_USE_SSL", "True")
LISTENER_CLIENT_ID = os.getenv("STOMP_CONSUMPTION_QUEUE")

# jsm-user-services config
USER_API_HOST = os.environ.get("USER_API_HOST")

Installing

pip install jsmsgr   

Setup

In order to use the lib, add the following env variable which sets the final semaphore destination name:

import os

JSMSGR_DESTINATION=os.getenv("JSMSGR_DESTINATION")

Using the lib

Publishing a single message

from jsmsgr.api import send_msg_to_user

msg_dict = {
    "msg": "Hello, there, ###_USER_NAME_###",
    "type": "sms",
    "external_id": "external123",
    "callback_mo_destination": "/queue/mo",
    "to_user_id": "a58c4853-2fa5-4891-80c7-f48287dbf403",  # user_id to send the msg to
}

send_msg_to_user(msg_dict)  # creates a publisher internally
send_msg_to_user(msg_dict, semaphore_publisher=your_publisher)  # user your publisher

Publishing a list of messages

from jsmsgr.api import send_msgs_to_user

msgs_dict = {
    "msgs": [
        {
            "msg": "Hello, there, ###_USER_NAME_###",
            "type": "sms",
            "external_id": "external123",
            "callback_mo_destination": "/queue/mo",
            "to_user_id": "a58c4853-2fa5-4891-80c7-f48287dbf403",  # user_id to send the msg to
        },
        {
            "msg": "<strong>Hello world there, ###_USER_NAME_###</strong>",
            "subject": "sub1",
            "type": "email",
            "to_user_id": "a58c4853-2fa5-4891-80c7-f48287dbf403",
        },
        {
            "msg": "<strong>Hello world there once again, ###_USER_NAME_###</strong>",
            "subject": "sub1",
            "type": "email",
            "to_user_id": "a58c4853-2fa5-4891-80c7-f48287dbf403",
        }            
    ]
}

send_msgs_to_user(msgs_dict)  # creates a publisher internally
send_msgs_to_user(msgs_dict, semaphore_publisher=your_publisher) # user your publisher

Replacing tags in the original message

Some tags are used to perform string replacements, such as the user name, in the original message. Some tags are the following:

###_USER_NAME_###: Replaced by user name (name of the user with the given to_user_id parameter value).

Example:

"Hello there, ###_USER_NAME### !"

Is sent as:

"Hello there, Igor !"

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

testing-pypi-abxsantos-0.0.5.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

testing_pypi_abxsantos-0.0.5-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file testing-pypi-abxsantos-0.0.5.tar.gz.

File metadata

  • Download URL: testing-pypi-abxsantos-0.0.5.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.3

File hashes

Hashes for testing-pypi-abxsantos-0.0.5.tar.gz
Algorithm Hash digest
SHA256 07498147f4ad6d9be504240c90f7f1b3f25687052d9de12da80a8178df4369d5
MD5 4d219868b57725c2a623f10a1f88504e
BLAKE2b-256 7db467a8d6562876f9a1de55961e057d61faacaee2b53633527ddf6907d5edb7

See more details on using hashes here.

File details

Details for the file testing_pypi_abxsantos-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: testing_pypi_abxsantos-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.3

File hashes

Hashes for testing_pypi_abxsantos-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d44d3e6f76b183b311e398cbf965b32e56a3cd3eedc42ebeddc998e4fee52ac4
MD5 05d20987e0caf89eaf2f791ccfeecffd
BLAKE2b-256 77bc0bae0374fc2d6f353179f4abaa5e92d04e8353e80f2cc128946da984c819

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