Sending a Message From NAE to LINE

In this tutorial, we'll write a script that sends an alert message to team members using their mobile devices through the LINE App.

Instructions for using the LINE API can be found here.

To prepare, we import the necessary libraries that are not already part of NAE.
For example:

form request import POST

Adding the parameters

In order to send messages with the LINE API, an authorization token is needed. A token can be generated from your LINE account by following the instructions on the page linked above.
For example:

'LINE_token': {
        'Name': 'LINE app Authorization Bearer token',
        'Description': 'Generated token, go to https://notify-bot.line.me/my/',
        'Type': 'string',
        'Required': True,
        'Encrypted': True
    }

Building the message

Secondly, we'll build the message. This is the message NAE will send to LINE. The message would typically contain information collected when the alert was triggered.
For example:

msg = "route decrease rate of {} for {}".format(route_rate, host_name)

Defining the API call function

Finally, we make the request to the LINE API endpoint, information about which can be found at the link above. Defining a function for each message is recommended.
For example:

def post_LINE_message(token, msg, proxies):
    headers = {'Authorization': 'Bearer {}'.format(token)}
    payload = {'message': msg}
    URL = 'https://notify-api.line.me/api/notify'
    requests.post(URL, proxies=proxies, headers=headers, params=payload)

And that's it!


Did this page help you?