Python API

Notifier

class RPA.Notifier.Notifier

Bases: object

Notifier is a library interfacting with different notification providers.

Supported providers

  • email

  • gmail

  • pushover

  • slack

  • telegram

  • twilio

Providers not supported yet via specific keywords

  • gitter

  • join

  • mailgun

  • pagerduty

  • popcornnotify

  • pushbullet

  • simplepush

  • statuspage

  • zulip

There is a keyword Generic Notify which can be used to call above services, for example.

Generic Notify
    provider_name=gitter
    message=Hello from Robot
    token=TOKEN
    room_id=ID_OF_THE_GITTER_ROOM

Parameters for different providers can be read from the Notifiers documents (link below).

Read more at https://notifiers.readthedocs.io/en/latest/

About kwargs

The **kwargs is a term for any extra named parameters, which can be included in the same way as already named arguments, e.g. Notify Email could be called with subject=my email subject which will be passed through **kwargs.

Notifier documentation contains information about all possible arguments that different providers support.

Robot Framework

&{account}=    Create Dictionary
...    host=smtp.office365.com
...    username=ACCOUNT_USERNAME
...    password=ACCOUNT_PASSWORD
Notify Email
...    to=RECIPIENT_EMAIL
...    from_=SENDER_ADDRESS            # passed via kwargs
...    subject=Hello from the Robot    # passed via kwargs
...    message=Hello from the Robot
...    &{account}                      # passed via kwargs
notifier = Notifier()
account = {
    "host": "smtp.office365.com",
    "username": "EMAIL_USERNAME",
    "password": "EMAIL_PASSWORD"
}
notifier.email_notify(
    to="RECIPIENT_EMAIL",
    from_="SENDER_EMAIL",
    subject="Hello from the Python Robot",
    message="Hello from the Python RObot",
    **account
)

Examples

Robot Framework

*** Settings ***
Library  RPA.Notifier

*** Variables ***
${SLACK_WEBHOOK}   https://hooks.slack.com/services/WEBHOOKDETAILS
${CHANNEL}         notification-channel

*** Tasks ***
Lets notify
   Notify Slack   message from robot  channel=${CHANNEL}  webhook_url=${SLACK_WEBHOOK}

Python

from RPA.Notifier import Notifier

library = Notifier()

slack_attachments = [
   {
      "title": "attachment 1",
      "fallback": "liverpool logo",
      "image_url": "https://upload.wikimedia.org/wikipedia/fi/thumb/c/cd/Liverpool_FC-n_logo.svg/1200px-Liverpool_FC-n_logo.svg.png",
   }
]

library.notify_slack(
   message='message for the Slack',
   channel="notification-channel",
   webhook_url=slack_webhook_url,
   attachments=slack_attachments,
)
ROBOT_LIBRARY_DOC_FORMAT = 'REST'
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
generic_notify(provider_name: str, **kwargs)

Generic keyword to use with any notifier provider.

Parameters
  • provider_name – name of the notifier service

  • kwargs – see library documentation

Returns

True if notification was successful, False if not

notify_email(message: str = None, to: str = None, username: str = None, password: str = None, host: str = None, port: int = 587, tls: bool = True, **kwargs) → bool

Notify using email provider

Parameters
  • message – notification message

  • to – target of email message

  • username – email account username

  • password – email account password

  • host – email SMTP host name

  • port – email SMTP host port number

  • tls – should TLS be used (default True)

  • kwargs – see library documentation

Returns

True if notification was successful, False if not

Example.

# Notify with Outlook account
Notify Email
...   message=Message from the Robot
...   to=RECIPIENT_EMAIL_ADDRESS
...   username=OUTLOOK_USERNAME
...   password=OUTLOOK_PASSWORD
...   host=smtp.office365.com
...   subject=Subject of the Message
notify_gmail(message: str = None, to: str = None, username: str = None, password: str = None, **kwargs) → bool

Notify using Gmail provider

Parameters
  • message – notification message

  • to – target of email message

  • username – GMail account username

  • password – GMail account password

  • kwargs – see library documentation

Returns

True if notification was successful, False if not

notify_pushover(message: str = None, user: str = None, token: str = None, **kwargs) → bool

Notify using Pushover provider

Parameters
  • message – notification message

  • user – target user for the notification

  • token – service token

  • kwargs – see library documentation

Returns

True if notification was successful, False if not

notify_slack(message: str = None, channel: str = None, webhook_url: str = None, **kwargs) → bool

Notify using Slack provider

Parameters
  • message – notification message

  • channel – target channel for the notification

  • webhook_url – Slack webhook url

  • kwargs – see library documentation

Returns

True if notification was successful, False if not

notify_telegram(message: str = None, chat_id: str = None, token: str = None, **kwargs) → bool

Notify using Telegram provider

Parameters
  • message – notification message

  • chat_id – target chat id for the notification

  • token – service token

  • kwargs – see library documentation

Returns

True if notification was successful, False if not

notify_twilio(message: str = None, number_from: str = None, number_to: str = None, account_sid: str = None, token: str = None, **kwargs) → bool

Notify using Twilio provider

Parameters
  • message – notification message

  • number_from – number where the message comes from

  • number_to – number where the messages goes to

  • account_sid – Twilio account SID

  • token – Twilio account token

  • kwargs – see library documentation

Returns

True if notification was successful, False if not