Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Your Own R2 Unit

Building Your Own R2 Unit

There is another massive shift happening with how we interact with companies through software. Users feel comfortable naturally talking with their applications through chat bots. Chat is the next generation of the user interface.

Companies like Slack, Facebook, WhatsApp, and WeChat have some of the most popular apps in the world and they are all betting on a messaging interface.

Ruby and it’s ecosystem of libraries can support these new types of interactions. In this session, we will see how we can build scalable, realtime web applications (or “bots”) using the Slack API. We will see what a good bot architecture looks like and how we can integrate with existing artificial intelligence services to make our bots smarter.

Jamie Wright

March 12, 2016
Tweet

More Decks by Jamie Wright

Other Decks in Programming

Transcript

  1. But I was going to go into Tosche Station to

    pick up some power converters… " #emoji-bot
  2. Can you schedule a meeting for tomorrow with Jim and

    Tim? Which Jim do you want me to schedule a meeting with? 1. Jim F. 2. Jim P. Sure. It looks like the afternoon is best. Do you want me to schedule this for then? Meeting invite went out for 2PM tomorrow to everyone. I will follow up to confirm everyone is booked. Ok. There is no more free time tomorrow. Do you want me to try for Wednesday? Multiple contacts "Yes" "No"
  3. Discoverability Meeting scheduled! Did you know you can reschedule by

    just saying "reschedule meeting with Dave"?
  4. Validation I'm sorry, "blerg" is not an answer. You can

    say "yes" or "no". Are you available to meet with Andy today at 2PM? "blerg"
  5. Selection Where do you want to meet tonight with MacKenzie?

    1. Coffee Shop 2. Restaurant for dinner 3. Local bar "1"
  6. Feedback No one in your meeting is available on Friday.

    Would you like me to ask them anyway? R2 is typing …
  7. Gender Neutral "are you a boy or a girl?" Neither.

    Those X-Wing pods are skinny. I would not fit with any extra parts.
  8. Beer Test Just keep me away from those Jawas and

    we'll be cool. "you are my best friend"
  9. Different Responses "how come you had rocket feet early on

    but then you didn't after episode 3?" They were using potatoes for special effects in the first 3. How would they pull off rocket feet?
  10. Different Responses "Yeah, but how do you explain Jabba the

    Hutt in the special edition?" They were using potatoes for special effects in the first 3. How would they pull off rocket feet?
  11. Use Their Surroundings "Dagobah did not look like a pleasant

    place!" It's 70 degrees in February where you're at. Global warming is affecting all systems.
  12. Fallback "Can you blerg?" I'm sorry, that oil bath got

    into some of my circuits. What were you saying?
  13. oauth response {"provider"=>"slack", "uid"=>"UXXXXXXX", "info"=> {"nickname"=>"jwright", "team"=>"Brilliant Fantastic", "user"=>"jwright", "team_id"=>"TXXXXXX",

    "user_id"=>"UXXXXXX", "name"=>nil, "email"=>nil, "first_name"=>nil, # … }, "credentials"=> {"token"=>"xoxp-XXXXX-XXXXXXX-XXXXXX", "expires"=>false}, "extra"=> {"raw_info"=> {"ok"=>true, "url"=>"https://bf.slack.com/", "team"=>"Brilliant Fantastic", "user"=>"jwright", "team_id"=>"TXXXXXX", "user_id"=>"UXXXXXX"}, "web_hook_info"=>{}, "bot_info"=> {"bot_user_id"=>"UXXXXXX", "bot_access_token"=>"xoxb-XXXXXX-XXXXXXXX"}}}}
  14. oauth response {"provider"=>"slack", "uid"=>"UXXXXXXX", "info"=> {"nickname"=>"jwright", "team"=>"Brilliant Fantastic", "user"=>"jwright", "team_id"=>"TXXXXXX",

    "user_id"=>"UXXXXXX", "name"=>nil, "email"=>nil, "first_name"=>nil, # … }, "credentials"=> {"token"=>"xoxp-XXXXX-XXXXXXX-XXXXXX", "expires"=>false}, "extra"=> {"raw_info"=> {"ok"=>true, "url"=>"https://bf.slack.com/", "team"=>"Brilliant Fantastic", "user"=>"jwright", "team_id"=>"TXXXXXX", "user_id"=>"UXXXXXX"}, "web_hook_info"=>{}, "bot_info"=> {"bot_user_id"=>"UXXXXXX", "bot_access_token"=>"xoxb-XXXXXX-XXXXXXXX"}}}}
  15. oauth response {"provider"=>"slack", "uid"=>"UXXXXXXX", "info"=> {"nickname"=>"jwright", "team"=>"Brilliant Fantastic", "user"=>"jwright", "team_id"=>"TXXXXXX",

    "user_id"=>"UXXXXXX", "name"=>nil, "email"=>nil, "first_name"=>nil, # … }, "credentials"=> {"token"=>"xoxp-XXXXX-XXXXXXX-XXXXXX", "expires"=>false}, "extra"=> {"raw_info"=> {"ok"=>true, "url"=>"https://bf.slack.com/", "team"=>"Brilliant Fantastic", "user"=>"jwright", "team_id"=>"TXXXXXX", "user_id"=>"UXXXXXX"}, "web_hook_info"=>{}, "bot_info"=> {"bot_user_id"=>"UXXXXXX", "bot_access_token"=>"xoxb-XXXXXX-XXXXXXXX"}}}}
  16. oauth response {"provider"=>"slack", "uid"=>"UXXXXXXX", "info"=> {"nickname"=>"jwright", "team"=>"Brilliant Fantastic", "user"=>"jwright", "team_id"=>"TXXXXXX",

    "user_id"=>"UXXXXXX", "name"=>nil, "email"=>nil, "first_name"=>nil, # … }, "credentials"=> {"token"=>"xoxp-XXXXX-XXXXXXX-XXXXXX", "expires"=>false}, "extra"=> {"raw_info"=> {"ok"=>true, "url"=>"https://bf.slack.com/", "team"=>"Brilliant Fantastic", "user"=>"jwright", "team_id"=>"TXXXXXX", "user_id"=>"UXXXXXX"}, "web_hook_info"=>{}, "bot_info"=> {"bot_user_id"=>"UXXXXXX", "bot_access_token"=>"xoxb-XXXXXX-XXXXXXXX"}}}}
  17. Store Information # app/controllers/sessions_controller.rb class SessionsController < ApplicationController def create

    auth = request.env["omniauth.auth"] team = Team.create_from_auth auth user = User.create_from_auth auth, team bot = Bot.create_from_auth auth, team end end
  18. Store Information # db/schema.rb create_table "bots", force: :cascade do |t|

    t.string "bot_id" t.string "access_token" t.integer "team_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["team_id"], name: "index_bots_on_team_id" end create_table "teams", force: :cascade do |t| t.string "access_token" t.string "domain" t.string "team_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "users", force: :cascade do |t| t.string "user_id" t.integer "team_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end
  19. Start Bot EM.next_tick do client = Slack::RealTime::Client.new(token: bot.access_token) begin client.start_async

    client.on(:close) do restart end rescue StandardError => e # TODO: handle slew of errors here end end * over simplification http://api.slack.com/rtm
  20. Introduce Bot client = Slack::Web::Client.new(token: bot.access_token) response = client.im_open(user_id: user.user_id)

    client.chat_postMessage(channel: response.channel.id, text: "Hello there") http://api.slack.com/chat.postMessage
  21. Event listening client = Slack::RealTime::Client.new(token: bot.access_token) client.on :message do |data|

    case data.text when /hello/ then client.web_client.chat_postMessage channel: data.channel, text: "Hi!" when /not now/ then client.web_client.chat_postMessage channel: data.channel, text: "Goodbye" end end http://api.slack.com/events
  22. behaviors client = Slack::RealTime::Client.new(token: bot.access_token) client.on :message do |data| case

    data.text when /hello/ then #… when /not now/ then #… when did_something(data.text) then #… when did_something_else(data.text) then #… end end
  23. Natural language processing Is BB8 ready to go? intent: entities:

    charge_status target: "BB8" status: "ready"
  24. Natural language processing Is BB8 ready to go? intent: entities:

    confidence: charge_status target: "BB8" status: "ready" 0.82
  25. nlp as a service require "wit" response = Wit.text_query("Is BB8

    ready to go?", ENV["WIT_ACCESS_TOKEN"]) bot.process_intent(response) http://api.wit.ai/message
  26. nlp as a service "outcomes" : [ { "_text" :

    "Is BB8 ready to go?", "intent" : "charge_status", "entities" : { "target" : [ { "value" : "BB8" } ], "status" : [ { "value" : "ready" } ], }, "confidence" : 0.82 } ]
  27. I know I'm not as difficult to build as that

    pain in the ass gold-plated primadonna. go and build bots