Send Message to Slack Channel

Intermediate This section will lead you step by step to send message to Slack channel via Slack App using Slack API with Pico LTE device.

Slack is a cloud-based business chat platform that links users to the data they require. Also, Slack changes how businesses communicate by uniting employees to work as a single cohesive team. The Slack API offers a user interface for retrieving information and making changes in a Slack workplace.

The Pico LTE device provides all the components needed to send messages to the Slack channel.

Before starting this Pico LTE tutorial, the Pico LTE SDK installation and configuration steps must be completed. Below are the system requirements for this tutorial. If you haven't followed the SDK installation steps, please refer to the page below before proceeding with the tutorial. The details of these steps will not be covered in this tutorial.

System Requirements

Hardware Requirements Software Requirements
• Sixfab Pico LTE
• Micro USB cable
• Thonny IDE

If you have completed all the requirements, you are ready to send a message to Slack with the Pico LTE device. Let's get started!

Preparing Coding Environment

  1. Download the Pico LTE SDK repository to your local machine. If you have already downloaded it, skip this step.
  2. Open script "examples → slack → send_message.py from the repository via Thonny IDE.
  3. If you haven't, create a config.json file in the root directory of Pico LTE device.

Create a Slack Workspace

Log in to Slack with your email address from the link. Then, click the “Create a New Workspace” button or continue with other workspaces you have created.

Continue the first step of the four-step process by entering your company or team name (ex. Sixfab).

Sixfab Pico LTE Send Message to Slack Channel

Adding your name and profile photo.

Sixfab Pico LTE Send Message to Slack Channel

Add coworker by email or skip this step.

Sixfab Pico LTE Send Message to Slack Channel

Type the team you are currently working on.

Sixfab Pico LTE Send Message to Slack Channel

Workspace has been successfully created!

Create an App

After creating the Workspace, the app that will send the message needs to be created. For this, go to the link in a separate tab. Click "Your apps" to view and use apps. Then, click "Create an app" to create a new app for sending messages.

Sixfab Pico LTE Send Message to Slack Channel

If you continue by Creating an App, select the "From scratch" option.

Sixfab Pico LTE Send Message to Slack Channel

Then enter the name of your App (ex. PicoLTE) and select the workspace to work in. You can choose the workspace you created in the previous step or a workspace you created earlier.

Sixfab Pico LTE Send Message to Slack Channel

Add Webhook Feature

On the screen that appears for editing the app, go to Incoming Webhooks from the Features section. You need to activate this feature.

Click "Add New Webhook to Workspace" after activation. Then select the channel to which the App will be added, that is, to which you want to send a message.

Sixfab Pico LTE Send Message to Slack Channel

If the actions are successful, you will have obtained a Webhook URL and will also be viewing your App in the channel you added.

Your Webhook URL that'll look something like this:

https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

That URL is your new Incoming Webhook, one that's specific to a single user, and a single channel.

Test the Code Example

Copy the following code block into the config.js file and copy the Weebhook URL and replace it with INCOMING_WEBHOOK_URL. Then save it to your Pico LTE device.

{
    "slack":{
        "webhook_url": "INCOMING_WEBHOOK_URL"
    }
}

Run the "send_message.py" script that you opened in Thonny.

Sixfab Pico LTE Send Message to Slack Channel

When you run the code, the message you want to send will be successfully transmitted. The output you get in the code should look like this:

>>> %Run -c $EDITOR_CONTENT INFO: Sending message to slack channel... INFO: Result: {'status': 0, 'response': ['ok'], 'interval': 0}

If the message is sent, it will be forwarded to the channel as shown in the image:

Sixfab Pico LTE Send Message to Slack Channel