Notifications
- class terminusgps.aws.notifications.AsyncNotificationManager(origin_pool_arn: str | None = None, configuration_set: str | None = None, max_sms_price: str = '0.20', max_voice_price: str = '0.20', region_name: str = 'us-east-1', debug_enabled: bool = False, logger_level: int = 10, logger_days: int = 10)[source]
Asyncronously delivers notifications using AWS End User Messaging.
Public Data Attributes:
An AWS region name.
The configuration set to use for messaging.
The origination pool to use for messaging.
The max allowed price per sms message.
The max allowed price per voice message.
Whether or not debug mode is enabled.
Public Methods:
__init__([origin_pool_arn, ...])Sets attributes on the notification manager.
__aenter__()Creates asyncronous clients.
__aexit__(exc_type, exc_val, exc_tb)Destroys asyncronous clients.
send_sms(phone, message[, ttl, dry_run, ...])Texts
messagetophonevia sms.send_voice(phone, message[, ttl, voice_id, ...])Calls
phoneand readsmessagealoud.batch_send_sms(phones, message, **kwargs)Sends
messageto all phone numbers inphonesvia sms.batch_send_voice(phones, message, **kwargs)Calls each number in
phonesand readsmessagealoud.
- async batch_send_sms(phones: Sequence[str], message: str, **kwargs) list[dict[str, str]][source]
Sends
messageto all phone numbers inphonesvia sms.- Parameters:
phones (
Sequence) – A sequence of phone numbers.message (
str) – A message body.kwargs – Additional keyword arguments passed to
send_sms().
- Raises:
AssertionError – If
_pinpoint_clientwasn’t set.- Returns:
A list of sms message responses.
- Return type:
See also
send_sms()for details on available keyword arguments.
- async batch_send_voice(phones: Sequence[str], message: str, **kwargs) list[dict[str, str]][source]
Calls each number in
phonesand readsmessagealoud.- Parameters:
phone (
Sequence) – A sequence of phone numbers.message (
str) – A message body.kwargs – Additional keyword arguments passed to
send_voice().
- Raises:
AssertionError – If
_pinpoint_clientwasn’t set.- Returns:
A voice message response.
- Return type:
See also
send_voice()for details on available keyword arguments.
- async send_sms(phone: str, message: str, ttl: int = 300, dry_run: bool = False, feedback: bool = False) dict[str, str][source]
Texts
messagetophonevia sms.- Parameters:
phone (
str) – A destination phone number.message (
str) – A message body.ttl (
int) – Time to live in ms. Default is300.dry_run (
bool) – Whether or not to execute the message as a dry run. Default isFalse.feedback (
bool) – Whether or not to include message feedback in the response. Default isFalse.
- Raises:
AssertionError – If
_pinpoint_clientwasn’t set.- Returns:
An sms message response.
- Return type:
- async send_voice(phone: str, message: str, ttl: int = 300, voice_id: str = 'Joanna', dry_run: bool = False, feedback: bool = False) dict[str, str][source]
Calls
phoneand readsmessagealoud.- Parameters:
phone (
str) – A destination phone number.message (
str) – A message body.ttl (
int) – Time to live in ms. Default is300.voice_id (
str) – A voice id to use for speech synthesis. Default is"Joanna".dry_run (
bool) – Whether or not to execute the message as a dry run. Default isFalse.feedback (
bool) – Whether or not to include message feedback in the response. Default isFalse.
- Raises:
AssertionError – If
_pinpoint_clientwasn’t set.- Returns:
A voice message response.
- Return type:
Usage
With an AsyncNotificationManager, you can asyncronously dispatch sms messages or voice calls.
Within an asyncronous event loop, i.e. main(), open an asyncronous context manager with async with.
Within the context manager, await the send_sms() or send_voice() methods to dispatch your message.
import asyncio
from terminusgps.aws.notifications import AsyncNotificationManager
async def main() -> None:
async with AsyncNotificationManager() as manager:
# This is the message we will dispatch in this example
message: str = "We know where ours are... do you?"
# Send the message via sms to a single phone number
await manager.send_sms("+15555555555", message)
# Send the message via voice to a single phone number
await manager.send_voice("+15555555555", message)
# Send the message via sms to multiple phone numbers
await manager.batch_send_sms(["+17135555555", "+15555555555"], message)
# Send the message via sms to a single phone number with feedback
await manager.send_sms("+15555555555", message, feedback=True)
# Send the message via sms to a single phone number as a dry run
await manager.send_sms("+15555555555", message, dry_run=True)
return
if __name__ == "__main__":
asyncio.run(main())