Dialogflow is now available as a native integration in Chatwoot. So it is recommended to use it instead.
Also, refer to Chatwoot Implementation Samples for other examples.
This repo contains a sample rails api which acts an agent bot and showcases an example use case of hotel booking via bot It relies on google dialogflow to for its NLP processing and makes use of bot messages in chatwoot to deliver a rich experiance.
- Create a google cloud Project [ Unless you already have one]
- Create a Dialogflow ES Bot under the project
- Go to small talk and enable the small talk
- Go to Intents and import the given intenets in
dialogflow_intents
folder in this repo.
- Create an AgentBot by running the following in your chatwoot rails console
bot = AgentBot.create!(name: "Booking Bot", outgoing_url: "http://localhost:4000")
AgentBotInbox.create!(inbox: Inbox.first, agent_bot: bot)
# returns the token
bot.access_token.token
# if you want to update the image of the bot
avatar_resource = LocalResource.new("your image url")
AgentBot.first.avatar.attach(io: avatar_resource.file, filename: avatar_resource.tmp_filename, content_type: avatar_resource.encoding)
- Clone the repo to your local
- Copy
.env.example
to.env
and update the values as mentions - run
rails s -p 4000
You should be able to connect to the agent Bot from 'localchatwooturl/widget_tests` and test the bot out
run following on your production Chatwoot Instance to set up the agent bot
bot = AgentBot.create!(name: "Booking Bot", outgoing_url: "http://localhost:4000")
# choose your inbox instead of Inbox.first
AgentBotInbox.create!(inbox: Inbox.first, agent_bot: bot)
# returns the token
bot.access_token.token
# if you want to update the image of the bot
avatar_resource = LocalResource.new("your image url")
AgentBot.first.avatar.attach(io: avatar_resource.file, filename: avatar_resource.tmp_filename, content_type: avatar_resource.encoding)
- Run the following and generate an image for google cloud
# replace project_id with your id
gcloud config set project $PROJECT_ID
gcloud builds submit --tag gcr.io/$PROJECT_ID/agent_bot
-
Go to cloud run and click create new service
-
Choose the agent_bot image upload now, and toggle advanced settings
- Add the environment variables as required by
.env.example
- Allow all traffic and unauthenticated requests
- Click Deploy
run the following in your console
# chose agent bot
bot = AgentBot.first
bot.outgoing_url = "your cloud run url"
bot.save!
Build a docker image using the provided docker file. Deploy with the required environment variables provided