Right. This is a chatbot for Slack that listens out for W1A catchphrases and responds appropriately. Yes, exactly.
Okay. This bot has been trained to identify any repeated phrases, and the responses to those phrases, based on the scripts from W1A. You can view these in model.js. Brilliant.
The bot listens to the messages of any channels it's subscribed to, identifies matching phrases using a fuzzy search algorithm, then sends a fitting response. I know, right?
The code is set up to run as an AWS Lambda function. This is good, guys.
Right, yes. There are two ways to interact with the bot. If you invite it to a channel, it will listen to all the messages and chime in when anybody says a matching phrase. Fabulous. Alternatively, you can direct message it, and it will respond directly if any of your phrases match. Great.
- Create a Lambda function on your AWS account from scratch, with Node.js 10.x runtime. Note the function name, AWS region and ARN of the execution role.
- Add API Gateway as a trigger with a new API and open security. Edit the API to replace the ANY method with a POST method pointing to your function. Note the endpoint URL (visible on the Lambda function page).
- Create an IAM user with programmatic access and AWSLambdaFullAccess permissions. Note the access key ID and secret access key.
- Clone this repository
- Run
npm installandnpm install -g node-lambda - Run
node-lambda setup. - Edit
.envand configureAWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_ROLE_ARN,AWS_REGIONandAWS_FUNCTION_NAME. RemoveAWS_ENVIRONMENT, unless you have specified an environment for your Lambda function.
- Create a new app in https://api.slack.com/apps
- Set up the Bot User and update
config.jswith the bot's display name. - Note the Verification Token in Basic Information.
- Install the app and note the Bot User OAuth Access Token.
- Edit
deploy.envand add the two environmental variablesVERIFICATION_TOKENandBOT_USER_TOKEN
- Run
npm run deployto deploy the W1A bot to your Lambda function.
- In the Slack API config, enable Event Subscriptions and enter the endpoint URL of your Lambda function as the request URL. If all is well, this should be verified.
- Add Bot User Events for
message.channels,message.groupsandmessage.im, then save changes.
So that's all good.