AWS Lambda

TUTORIAL: How to integrate the Amazon Lex with a slack channel

A tutorial on how to integrate the amazon lex with your slack channel

In the height of the hackathon held in march 2024 by MetalToad, a team of 5 members took on a project to integrate a natural language chatbot (Amazon Lex) with a slack channel. I bring you this blog post but we shall address it as a tutorial, how you can also build your own chatbot and integrate it with your slack channel.

The tutorial was created by Mario Mauro, Chris Chinedozie, Simon Scudder, Gabriel Lima and Marcelo Beiral

  • Chatbot purpose and Features

Designing the purpose of the chatbot is core and crucial. For this tutorial, our chatbot listens to events in the channel like giving a shoutout or thumbs up to a team member, identifying the counts of votes that shoutout receives and ranking shoutout recipients by most votes.

The following dream lists are features added to toadbot 2024

    • Allow the shoutouts to more than one recipient or teams
    • Do not allow a user to have repeated votes 
    • A recipient to a shoutout should not be allowed to vote for yourself
    • The ranking of most voted people (monthly/year)
    • Generate a certificate for the top voted person

  • Stacks: An overview of how the pipeline works

The process starts with slack, a shoutout in a slack channel triggers the process, and now we have slack talking to lex, which is going to interpret what we put on slack and it calls a lambda, the lambda saves informations into dynamoDB and then use bedrock to write the text for the certificates, as seen in image 1.

  • What is Amazon Lex ?

Amazon lex (AWS Amazon) is a fully managed AWS service for building conversational interfaces into any application using voice and text. 

With amazon lex, we can take the text we typed in a slack channel and interpret it and decide on a situation, the situation is called “Intent” and these intents can use variables called Slots.

Let's look at an example of how Lex works.

The following message was sent to the slack channel. 

With Lex, 2 variables can be created

    • Variable 1: The recipient of the shoutout, which in this case is @JohnSmith
    • Variable 2: The reason for the shoutout, which is “for the presentation on AWS tools”.

In Lex, these variables are called Slots.

Amazon Lex has a native integration with tools like Facebook, Slack, TwilioSMS etc, but for the sack of this project, we will be focusing only on slack.

In this project, Amazon Lex takes the phrase sent in slack channel and will compare it with different phrases that I have taught the model and will pick the Intent that matches with it.

Lets say, I have several Intents created in Lex (eg. Shoutout, Increment, Rank, Celebrate) 

Digging deeper into our previous example, we see the phrase contains a trigger called “Shoutout” which matches with our Intent and contains 2 variables.

However, An Intent can be trigger by not just one but many Instances, lets take for example the Intent “Increment” can be called using words and symbols like (++. +1, me too, Ditto), as seen in the image 2 below. Lex has been taught to understand that I am trying to perform an “Increment” Intent by using natural language interpretation to figure out what I mean to do.


Back to our initial example, the “Shoutout” intent has been trained with the following examples, see image 3.

    • {person} ++ for {reason} 
    • Shoutout to {person} for {reason}
    • High 5 to {person} for {reason}
    • Congratulate {person} for {reason}
    • Shoutout to {person} because he {reason}
    • Shoutout to {person} because she {reason}

Shoutout has 2 slots:

    1. Name (who received the shoutout)
    2. Reason (why he/she/it got the shoutout)

Slots in Amazon Lex can be setup for different types like, Standard types, Required or optional, Custom lists of options or sample values, A single value or an array of values (advanced options -> multi-valued slot), and with slot for an array of values, we solve the question of giving a shoutout to more than one person.

  • How to Integrate Lex with AWS Lambda

To integrate Lex with a lambda function, we do this inside the chatbot Alias as in image 4a, create a new alias and make sure to select the language you want to enable in the alias as shown in image 4b, and next, we choose the lambda function and its respective version as in image 4c. For this project, a lambda function called toadbot2024 was created with the latest version and it is called upon fulfillment and that means when all required slots are filled, this is enabled in advanced options and then click “Update options” as shown in image 4d. 

Image 4: Integrating Lex with AWS LAMBDA

Let's look at how this integration works, Lex admits a single lambda function per Alias, this function does these 2 things.

    • The function receives a standard payload from Lex
    • Perform the action based on intent detected by Lex

The lambda function upon receiving a standard payload from Lex, we look for the situation or the intent of the payload.

    • Intent Shoutout: Save recipient(s) and reason
    • Intent Increment: Add 1 to score
    • Intent Ranking: Retrieve list of recipients by score

If it's a shoutout, then I know I need to do something with the recipient and the reason like making a vote and saving the data into a dynamoDB but if it's an increment intent then I need to increment 1 vote to the recipient and update the dynamoDB and so on.

In conclusion, this project's main objective was to update and add new features into an existing chatbot application used by the company metaltoad. 

Features like, 

    • Allow more than one recipient or teams
    • Not allow repeated votes
    • Can’t vote for yourself

And, in conjunction create this tutorial and blog on how you too can create your own chatbot for your slack channel with designs and implementations you want. 

Similar posts

Get notified on new marketing insights

Be the first to know about new B2B SaaS Marketing insights to build or refine your marketing function with the tools and knowledge of today’s industry.