Codementor Events

Integrate Amazon Lex with Discord (or any chat service) using Java

Published Feb 07, 2018
Integrate Amazon Lex with Discord (or any chat service) using Java

I’m currently in the Amazon Lex Hackathon, one of the requirements of the bot that I’m making for my wives is to connect it with Discord, Why?, because a big portion of their clients use this tool to communicate with them.

Amazon has a pretty nice documentation for the chat integrations that Lex handles (Messenger, Slack, Twillio) but, when the case is to use Lex with a custom chat tool like discord, or your own chat service, particularly with Java it is very limited.

Prerequisites:

  • An amazon account (you can try AWS for free one year)
  • Know how to make a basic bot (discord or any other service) or have your own chat platform

Let’s do it!


The architecture of the solution

  1. Make an API, with API Gateway: I could not find a way to connect the discord directly with Lex (please, if you find it, tell me), so, to connect your custom messaging service with your Lex bot, you need an interface, create a simple API that send the data from your chat service to a Lambda function.
  2. Prepare the lambda funcion that will speak directly with Lex: This function will take the data from the API and send it to your Lex bot, lex also generates the answer and sends it back to the API as response.
  3. Configure your lex bot as you can see in the documentation of AWS Lex, this part has a nice documentation, your bot will be called from the lambda function created in the step 2.

Enough talk, Show me the code!

The API Gateway and Lex are simple configurations in the AWS Console, and the discord part is only needed to call the API and verify the response, the code that matters is the integration between API Gateway and Lambda, so, there you go:

Probably I’ll be not able to finish the bot, but I regret nothing since I’ve learned a lot of this topic.

If you find a better way to do this, please feel free to share,

Hope it helps,

Greetings

Discover and read more posts from Pablo Rodriguez V.
get started
post commentsBe the first to share your opinion
Show more replies