This is a Rails app that allows a user to engage with the Root Insurance API via either a Facebook messanger bot, Slack bot, or an Alexa skill.
- Facebook Bot
- Slack Bot
- Alexa Bot (Alexa skill)
The facebook bot echos everything you say back to you.
- Read the facebook getting started documentation and set up your app.
- Set the
FACEBOOK_PAGE_ACCESS_TOKEN
environment variable to your page access token. - Start your app.
- Once you've started the app, you need to use ngrok to expose your local server to the internet. The following command will expose your server, on port 3000, to the internet:
ngrok http 3000
. - Ngrok will give you a url which you can use to set up your webhooks. See here.
This is a basic slack bot with three commands:
- Get a list of all phone brands
- Get a list of all phones made by
brand
- Get the value of a specific
phone
The first thing you have to do is to register a Slack bot and obtain the SLACK_API_TOKEN
. You can create a new Bot Integration here services/new/bot.
The bot lives in lib/slack-insure-bot
.
The part to pay attention to is how you structure the commands. For example creating a command to list all phone brands
will be structure like this:
module SlackInsureBot
module Commands
class Default < SlackRubyBot::Commands::Base
command 'list all phone brands' do |client, data, _match|
brands = ["Samsung", "Apple", "Nokia"]
client.say(channel: data.channel, text: brands.join("\n"))
end
end
end
end
Check out slack-ruby-bot. This is the main lib where everything is copied from ;)
- slack-bot-on-rails: A bot running on Rails and using React to display Slack messages on a website.
- slack-mathbot: Slack integration with math.
- slack-google-bot: A Slack bot that searches Google, including CSE.
- slack-aws: Slack integration with Amazon Web Services.
- slack-deploy-bot: A Slack bot that helps you to deploy your apps.
- slack-gamebot: A game bot service for ping pong, chess, etc, hosted at playplay.io.
- slack-victorbot: A Slack bot to talk to the Victorops service.
An Alexa Skill is essentially an app that runs on an Amazon Echo.
You can ask Alexa to:
- Get a list of all phone brands
- Get a list of all phones made by
brand
- Setup an Amazon Echo and register it using your personal Amazon account.
- Register for an Amazon developer account and setup the Alexa skill here.
Add "Insurance Helper" as both the Name
and the Invocation Name
.
The interaction model is by far the hardest part of creating an Alexa skill. I suggest reading this and watching this video in order to get a basic understanding of what is required to create an interaction model.
- Add the JSON blob found in
interaction_model/intent_schema.json
in the Intent Schema field. - Create a new Custom Slot Type and the values found in
interaction_model/custom_slots/LIST_OF_BRANDS
. - Add the Sample Utterances found in
interaction_model/sample_utterances.txt
in the Sample Utterances field.
- Select HTTPS as the Service Endpoint Type.
- Once you've started the app, you need to use ngrok to expose your local server to the internet. Once your app is running, you need to run
ngrok http 3000
to do this. You'll then get an url which you can add in the Default field. It will looks something like thishttps://056d1d30.ngrok.io/alexa
.
Select the option My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority
.
The Alexa skill posts data to the WebhooksController
. Here we then call the AlexaService
which figures out the intent of the request and generates a response. This gets send back to the Alexa Skill and is verbalized by the Echo.
The first step is to add the necessary secrets in config/settings.yml
.
Install the gems
bundle install
Run migrations
rails db:migrate
Start the server
rails s
Setup ngrok to expose the endpoint
ngrok http 3000