Set up a smart chatbot on discourse 🤖

Hello,

After weeks of tinkering, I finally managed to set up an AI bot, similar to discobot but one that learns and is more responsive. Here is how I did it for anyone interested in setting it up. There is quite a few steps, but once you get it all set up, the result is amazing.

  1. Install the hubot plugin for discourse Hubot Adapter for Discourse, to install hubot on your discourse, the hubot variables like HUBOT_DISCOURSE_USERNAME are entered into (yourhubotfolder)/bin/hubot file, just nano or edit it to write export HUBOT_DISCOURSE_USERNAME=mybot) For more details go here Discobot for training - #10 by featheredtoast

  2. Sign up and make a new bot on https://dialogflow.com/

  3. Install a hubot / apiai (dialogueflow) adapter from here: GitHub - ojacques/hubot-apiai: Add smartness and conversational UX to Hubot with API.AI as back-end 3a. in the bin/hubot file, make sure you have the following variables set

    export HUBOT_DISCOURSE_USERNAME=(bot’s username, don’t do discobot)
    export HUBOT_DISCOURSE_KEY=(your bot-user’s api key, not the site api)
    export HUBOT_DISCOURSE_SERVER=(discourse url)
    export API_AI_CLIENT_ACCESS_TOKEN=(dialogflow bot server api, found in the settings)
    export GOOGLE_APPLICATION_CREDENTIALS=(yourjson).json
    export DIALOGFLOW_PROJECT_ID=(nameoftheproject)

You will have to download a google application credential json, which you can get following this guide: https://cloud.google.com/genomics/downloading-credentials-for-api-access

  1. Now boot up your hubot by typing bin/hubot -a discourse-adapter to run it. If you want it to run even when you are not in the terminal, type nohup bin/hubot -a discourse-adapter &

  2. Private message the bot for testing. If you set up the dialogflow bot with small talk, you can say hi, how are you and engage in small talk right away. Other dialogue you have to set up. There are a few tutorials on youtube that are a good start. Tutorial - How to Make a Basic DialogFlow (API.AI) Agent - YouTube

Here is a demo

If you have any questions, feel free to ask.

Also, a proper thank you to @codinghorror and the team for developing discourse, and @awole20 for developing the hubot plugin, couldn’t have done it without you!

37 Likes

This is just plain awesome! I am not too experienced with this myself, but do you know if this would work to deploy on Heroku or not? Thanks for the tutorial!

1 Like

Hubot is indeed able to be installed on Heroku - check out the Hubot docs for more info: Deploying to Heroku | HUBOT

5 Likes

That’s cool. I’ll look further into this.

@awole20 @Timothy_Vail I know I sound absolutely hilarious by saying this, but is there any way to make a bot that you guys know of without being an admin (a.k.a having an api key)?

You need to be the admin of not only discourse but of the server it sits on. No way around that one.

3 Likes

That´s a bummer. Thanks for the information though.

I am slowly working my way through this. What threw me at the first stage was access errors when running yo hubot --adapter=discourse-adapter per the installation instructions for the plugin. It looks like you have to change the permission for the folders. Fix is documented here.

1 Like

So, as I discussed above, I hit an error installing NPM. Error was using root when installing, a common gotcha that leads to a lot of EACCES and permission errors. This is a well-documented error. I believe a lot of people are on Digital Ocean. Follow their documentation for correctly setting up NPM on your droplet.

Thanks for sharing this, Tim. I’m curious to know what types of dialogue you’ve set up for the chatbot. How are your forum users engaging with it in the real world?

4 Likes

Hello Nacho,

It’s actually been awhile since I’ve used the chatbot, but am planning on using it again for an upcoming project. Mostly it was used for training sessions for teachers, they would go through a course using chatbot and learn about teaching through the dialogue. Let me know if you have any questions.

4 Likes

Thanks, great post! Love it

1 Like

Wow loved this and I must sleep on it these days.
I need some AI on my discourse site

2 Likes

Before I dive into implementing this on my Discourse (and since I am only somewhat proficient, but good at following directions :nerd_face: ) … are these instructions in this thread still working? Or… is there a more current or preferred way to integrate an AI bot?

2 Likes

There’s been a few conversations. Here is one with more recent developments:

1 Like