Getting started

A common use case for the f451 Communications module is in applications that send (usually programmatically generated) messages via one or more channels. The module assumes that you provide all necessary keys and secrets required to verify your credentials with the services linked to the channels that you want to use.

It is recommended that you store these keys and secrets in a separate file (e.g. secrets.ini). However, it is also possible to submit them – for example during testing – in the form of a so-called dict structure.

from configparser import ConfigParser, ExtendedInterpolation
from f451_comms.comms import Comms

secrets = ConfigParser(interpolation=ExtendedInterpolation())
secrets.read("_PATH_TO_YOUR_SECRETS_FILE_")

comms = Comms(secrets)
comms.send_message("Hello world!", "all")

The basic sequence is to first initialize the Comms object with the keys and secrets required to authenticate with the services that you want to use. After that you can send messages to one or more channels with a single method call to the Comms object.

The send_message() method also has a 3rd argument that allows you to include additional attributes using a dict structure. These attributes can contain a wide variety of items. For example, you can include the HTML version of an email, or Slack blocks for more complex Slack messages. You can also include references to images to be included with the message, or files to be attached to emails, and so on.

The Comms object will initialize all communications channels listed in the secrets variable which is of type ConfigParser. One convenient option to manage the settings for communication services is to store the values in .ini configuration files.

See section “Configuration files” for more information.