The sky is the limit on what you can use a bot for in Chatlio, but we’ll walk you through creating a sample JavaScript (node.js) bot that listens for term(s) in strings and then responds to visitors with a response if the term was found in visitor message.
One of the easier ways to develop a Slack bot is to use Slack’s Bolt platform. With Bolt, you can use JavaScript, Python, or Java. We will reference JavaScript for the remaining portion of this document for simplicity sake.
Follow Slack’s Getting Started instructions for creating a Bolt app in Slack. The instructions will walk you through the following:
Here is an additional node.js example we came up with to aid you in your development:
// app.js
const { App } = require('@slack/bolt');
require('dotenv').config();
// Initialize your app with your bot token and signing secret
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN,
});
// Listen for messages containing "hello"
app.message('pricing', async ({ message, say }) => {
// messages from visitors using your Chatlio widget are 'bot_messages'.
if (message.subtype === 'bot_message') {
await say({
// The blocks are what your Slack operators will see.
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: '`Here is a link to our pricing page: https://yoursite.com/#pricing"',
},
},
],
// This text is what your Chatlio widget visitors will see.
text: 'Here is a link to our pricing page: https://yoursite.com/#pricing"',
});
}
});
// Listen for messages containing "reset password"
app.message('reset my password', async ({ message, say }) => {
// messages from visitors using your Chatlio widget are 'bot_messages'.
if (message.subtype === 'bot_message') {
await say({
// The blocks are what your Slack operators will see.
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'Here is where you can reset your password: https://yoursite.com/#password-reset',
},
},
],
// This text is what your Chatlio widget visitors will see.
text: 'Here is where you can reset your password: https://yoursite.com/#password-reset',
});
}
});
// Error handling
app.error(async (error) => {
console.error('An error occurred:', error);
});
// Start the app
(async () => {
try {
await app.start(process.env.PORT || 3000);
console.log('⚡️ Bolt app is running!');
} catch (error) {
console.error('Unable to start App:', error);
}
})();
Once you have everything setup in Slack, you will need to enable your Slack app/bot in Chatlio:
Start up a chat in the widget and test out the scenarios you are hoping to automate with your bot. Here is an example of what the ‘reset my password’ listener from the node.js code we provided above would look like to the visitor on the Chatlio widget:
Let us know in chat window below if you have questions about this or would like more info!
Happy botting!
This website is built using latest technogies. Unfortunately your browser doesn't support those. Please update your browser to view this website correctly. Thank you.Update my browser now