Skip to main content

genesys notifications client

Project description

genesys-notifications client

This is a simple library for receiving genesys websocket notifications.

See https://developer.genesys.cloud/api/rest/v2/notifications/notification_service for background.

The library provides:

  • channel connection & topic subscriptions
  • async iterator for notifications
  • automatic channel reconnect on failure
  • helpful custom exceptions whenever recovery is not possible
  • automatic channel lifetime extension or rollover when expiring or closing for maintenance [^1]

The scope of the library is intentionally limited to making single notifications channel management more convenient by encapsulating the above features.

It does not:

  • refresh the access token
  • manage multiple channels[^2].
  • process received topic notifications[^3]
  • account for the max 20 channels limit
  • account for the 1000 topics per channel subscription limit
  • account for the one connection per channel limit

Usage:

First create the Genesys channel as instructed by the Genesys docs. Then:

  1. Import and instantiate a Channel, passing in URI and topics.
  2. Await the channel to connect and subscribe.
  3. Iterate over the result to receive notifications.

Example:

>>> uri = "wss://streaming.mypurecloud.com/channels/streaming-0-fmtdmf8cdis7jh14udg5p89t6z"
>>> topics = ["v2.analytics.queues.tdmf8cd-k3h43h-udg5p89.observations"]
>>> from genesys_notifications import Channel
>>> from genesys_notifications.exceptions import InitializationFailure, RecoveryFailure
>>> async def test(uri, topics):
...    try:
...       notifications = await Channel(uri, topics)
...    except InitializationFailure:
...       # Handle websocket connection opening and topic subscription failures;
...       # ConnectionFailure and SubscriptionFailure can be caught separately as well.
...    try:
...       async for n in notifications:
...    except RecoveryFailure:
...       # Handle cases when the channel is not able to automatically recover from issues:
...       # in case of problems, it will try once to reconnect & resubscibe before giving up, and
...       # in case of scheduled expiry or ad-hoc Genesys-side close notification, it will try to
          # extend its lifetime by resubscribing to topics.
...    else:
...       print(n)
>>>
>>> import asyncio
>>> asyncio.run(test(uri, topics)) 
{
    "topicName": "channel.metadata",
    "eventBody":{
        "message":"WebSocket Heartbeat"
    }
}

See the exceptions module for all the available exceptions. The reason for exception is always available in its reason attribute. See exceptions.REASON enum for possible reasons.

[^1]: Instantiate the Channel with extend=False to disable automatic lifetime extension & handle it manually by catching ChannelExpiring [^2]: Except when channel.rollover(uri) is called; under the hood, a new websocket connection is then initialized and transparently replaces the original [^3]: Except for the bare minimum required to support the provided features; subscription confirmations, channel close notifications etc.

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

genesys-notifications-1.1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

genesys_notifications-1.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file genesys-notifications-1.1.tar.gz.

File metadata

  • Download URL: genesys-notifications-1.1.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for genesys-notifications-1.1.tar.gz
Algorithm Hash digest
SHA256 93978ce8671b439c42c0dff8646ef27aed6c6aa2552827f7dc7125f2da3dc8ee
MD5 756edf60b3970175b0ed7b1a05c0e168
BLAKE2b-256 6869af9f0aa4ec2ff5acf1946eccc2e82448f47c782f9c9990d84f2b2d1e2eb1

See more details on using hashes here.

File details

Details for the file genesys_notifications-1.1-py3-none-any.whl.

File metadata

  • Download URL: genesys_notifications-1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for genesys_notifications-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ccd946a87ac12b112a376f3a0bcbb98a9765e8d746038462d2f8794364d767bc
MD5 2f9d6b3259892ea599cbb99dacc289c8
BLAKE2b-256 8889c31d494ee5e691ba6bea40f729a4c65f3d44b5fdeaa8fe62aa5c5f011c6b

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