Example Node.js connector to make your Teneo solution available on Slack
[!IMPORTANT]
This project has been retired and archived
If there is a need of continued use / development of this project for your own needs please feel free to fork the project - which will remain here in archived form.
This node.js example connector allows you to make your Teneo bot available on Slack. The connector acts as middleware between Slack and Teneo and uses the Slack Events API to receive messages from Slack. This guide will take you through the steps of creating a new Slack app and deploying the connector to respond to events sent by Slack.
Note: Starting November 28, 2022, free Heroku Dynos, free Heroku Postgres, and free Heroku Data for Redis® plans will no longer be available.
The Slack Events API requires that the connector is available via https. On this page we will be using Heroku to host this connector, for which a Heroku account is needed. You can however also manually install the connector on a location of your choice, see Running the connector locally.
Your bot needs to be published and you need to know the engine url.
Create a new Slack app here: https://api.slack.com/apps. Give it a name and add it to the appropriate workspace.
On the page that appears, scroll to the bottom of the screen and copy the ‘Signing Secret’. You will need it later when you deploy the connector.
In the left navigation menu under ‘Features’ choose ‘OAuth & Permissions’. Scroll down until you see ‘Scopes’. Under ‘Bot Token Scopes’ click the ‘Add an OAuth Scope’ button. In the field that appears type ‘chat:write’
Still on the ‘OAuth & Permissions’, scroll back to the top and click the ‘Install App to Workspace’ button and authorize. Copy the ‘Bot User OAuth Access Token’, you will need it in the next step when you deploy the connector.
Click the button below to deploy the connector to Heroku:
In the ‘Config Vars’ section, add the following:
Click ‘View app’ and copy the url of your Heroku app, you will need it in the next step.
If you prefer to run your bot locally, see Running the connector locally.
Go back to your app on Slack. In the left navigation menu under ‘Features’ choose ‘Event Subscriptions’. Then:
https://[yourherokuappname].herokuapp.com/slack/events
(replace [yourherokuappname] with the name of your app on Heroku)message.im
That’s it! Your bot should now be available as an app in Slack and ready to respont to the messages sent to it.
To add message attachments, this connector looks for an output parameter slack
in the engine response. The value of that parameter is assumed to contain the attachement JSON as defined by Slack.
If we look at Slack’s JSON specification of attachments, to attach an image the value of the slack
output parameter would need to look like this:
{
"fallback": "Image description as fallback",
"image_url": "https://url.to/an/image.png"
}
Note: although it is possible to add multiple attachments to a Slack message, this connector assumes the output parameter contains just the JSON for a single attachment.
If you prefer to manually install this connector or run it locally, proceed as follows:
npm install
in the folder where you stored the source.
ngrok http 3000
Create a file called .env in the project’s root folder, based on the sample file called ‘.env.sample’ that is included in the project. Inside .env, replace the environment variables with the corresponding values:
SLACK_SIGNING_SECRET=<your_slack_signing_secret> SLACK_BOT_USER_OAUTH_ACCESS_TOKEN=<your_slack_bot_oauth_token> TENEO_ENGINE_URL=<your_engine_url> node server.js
Start the connector with the following command:
node server.js