filmov
tv
Send Slack Messages with This Python Script! - Clearly explained | Slack API Bot

Показать описание
With this video we will use Python and the SlackAPI to send automated messages to a Slack channel. For this we will build a Python based Slack Bot which uses Webhook URL for a selected channel and send customized messages based on the logic defined in your Python script.
I suggest to use few #Python functions which you can easily leverage for your business needs:
- The main() function provides a logic how the messages should be sent. You can customize this function upon your business requirements and extend the functionality as you want.
- send_slack_message() executes the message sending action to the specified Slack channel using the generated Webhook ID, which together with the message variable are sent to Slack API.
The tutorial demonstrated how to specify a payload which must be put into the POST request for the API. It is a key-values string formatted payload, where you should pay your attention to.
This Python tutorial does not requires any third-party dependencies, and uses the requests package only as the critical one.
Also, I built this bot to be able to receive messages to be sent to Slack channel from a terminal. For this I used argument receiver functionality originally provided by standard Python package argparse.
This Bot was developed on Python 3.8, but I think it would work on other versions also.
Table of the tutorial:
- 0:00 - Intro
- 0:23 - Build a Slack App and Get Webhook Token
- 3:32 - Coding part: build a Slack message sender with Python
- 8:57 - Set-up a Slack API payload variable
- 11:18 - Testing Python script, and debug development errors
- 13:25 - Sending more messages and customize the Bot logic
#SlackAPI #SlackBot
I suggest to use few #Python functions which you can easily leverage for your business needs:
- The main() function provides a logic how the messages should be sent. You can customize this function upon your business requirements and extend the functionality as you want.
- send_slack_message() executes the message sending action to the specified Slack channel using the generated Webhook ID, which together with the message variable are sent to Slack API.
The tutorial demonstrated how to specify a payload which must be put into the POST request for the API. It is a key-values string formatted payload, where you should pay your attention to.
This Python tutorial does not requires any third-party dependencies, and uses the requests package only as the critical one.
Also, I built this bot to be able to receive messages to be sent to Slack channel from a terminal. For this I used argument receiver functionality originally provided by standard Python package argparse.
This Bot was developed on Python 3.8, but I think it would work on other versions also.
Table of the tutorial:
- 0:00 - Intro
- 0:23 - Build a Slack App and Get Webhook Token
- 3:32 - Coding part: build a Slack message sender with Python
- 8:57 - Set-up a Slack API payload variable
- 11:18 - Testing Python script, and debug development errors
- 13:25 - Sending more messages and customize the Bot logic
#SlackAPI #SlackBot
Комментарии