The provided sample includes:
- Get a bot user token in Slack
- Get a list of channels in a Slack Team
- Post formatted messages to Slack in different channels using Bot User.
- Post email notifications from Gmail to Slack as messages. The sample Solution sends out emails' summary in formatted messages to Slack from your configured Gmail account. You can post mails' contents as messages to any channel you want.
This sample shows how Linx automatically reads emails from GMail and post formatted messages to Slack. Once this Slack integration is active, the sample posts messages to Slack Channel.
- Create New App in Slack
- Slack API documentation
- Test apis from browser
- Slack reference for block kit
- How to find your Channel Id in Slack
- How to use the ReadEmail plugin from Linx
- Linx Designer
- Slack account
- Gmail account
This solution was developed in the Linx Designer v5.21.0.0
and v6.4.1
-
Choose from Scratch.
- Enter App Name, e.g linx-bot-github
- Choose a workspace and click on create app
-
Under 'Add features and functionality'
- Click on Bots
-
Under 'First, assign a scope to your bot token'
- Click on Review Scopes to Add
-
Go to
Scopes
section- Click on Add an OAuth Scope
- Choose the following from the list:
- im:history
- chat:write
- channels:history
- im:write
- chat:write.public
- channels:read
- groups:read
- im:read
- mpim:read
- Click on Add an OAuth Scope
- Choose the following from the list:
-
As the above is done, a message
You can now show tabs on App HomeManage which tabs your user sees in your app’s home. Go to App Home
will appear. -
Scroll the page up and go to the section
OAuth Tokens for Your Workspace
-
Click on the button Install to workspace and click on Allow
-
Once successful, you will be directed to the
OAuth Tokens for Your Workspace
section -
Click on the Copy Button to copy the Bot User OAuth Token. Note that it starts with
xoxb-
SlackBotUserOAuth
: Paste the token copied aboveJSONSampleFile
: Sample JSON text file pathSlackUri
: Slack API Url.
Linx email configuration will help you get started with email plugin in Linx.
- Go to the Google Account section
- Select Security
- Make sure 2-Step Verification is switched 'On'
- Select App passwords
- Verify yourself
- Select 'Other'
- Provide a name (e.g. Linx)
- Click Generate
- The password that you have to use in Linx will display
Note: After setting up your App password, you can switch 2-Step Verification 'Off' again.
This sample was setup using a Gmail instance.
GmailUserName:
Username of your email account.GmailPassword:
App password.
The sample GMail Read function properties are configured as follows:
Mark as read
: TrueOnly unread items
: True
Requests are authenticated via a Bearer access token included in the Authorization
header of each request.
When making requests to the GitHub, you must also include the following header:
Accept: application/x-www-form-urlencoded , application/json
A function to test if you've entered the right token and the right channel. Tests the api https://api.slack.com/methods/auth.test/test
- Parameters:
HeaderText
: string type.
- Result:
SectionText
: string type.
Calls the Post message API https://api.slack.com/methods/chat.postMessage
- Parameters:
blocks
: JSON format as string type.
Calls the Get API https://api.slack.com/methods/conversations.list. Lists all channels in a Slack team.
Gets the Channel's name.
- Copy Paste the file JSONSample.txt to C:\Work\slack\JSONSample.txt
- In the Demo Folder, Click on the function named PostJSONMessageToSlack.
- Parameters
channelId
: Enter Channel Id to post message.
- In the Demo Folder, Click on the function named PostMessageToAllChannels to post to all channels.
- In the Demo Folder, Click on the function named PostMessageToChannelForChannelName to post to a channel.
- In the Demo Folder, click on the function named PostMessageToSlack to post to a channel.
- Parameters
Header Text
: Text to be displayed as headerSection Text
: Text to be displayed in sectionChannelId
: Channel Id
- In the Demo Folder, Click on the function named PostEmailContentsToSlack. Only unread items will be read, and messages containing the From, Subject, Date will be sent to Slack. The default channel is General.
For questions please ask the Linx community or use the Slack channel.