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

All Your Chat Belong to Ex: Building Chatbots in Elixir

All Your Chat Belong to Ex: Building Chatbots in Elixir

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.

Elixir is the perfect language and ecosystem for building bots and for conversational interfaces. In this session, we will see how we can build scalable, realtime web applications (or “bots”) using a new library Juvet and 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

October 15, 2023
Tweet

More Decks by Jamie Wright

Other Decks in Programming

Transcript

  1. Elixir
    +
    CHATBOTS
    ALL YOUR CHAT BELONG TO EX

    View full-size slide

  2. WELCOME
    WELCOME
    WELCOME

    View full-size slide

  3. AND I
    AM
    A
    BOT BUILDER™

    View full-size slide

  4. A Brief In
    tr
    o
    CHATBOTS

    View full-size slide

  5. A COMPUTER PROGRAM DESIGNED TO
    SIMULATE A CONVERSATION WITH HUMAN
    USERS
    CHATBOT

    View full-size slide

  6. USER PLATFORM APP
    OPS CHANNEL
    /HELP
    OPS CHANNEL
    HERE IS THE HELP


    YOU REQUESTED:
    { CHANNEL: ‘C1234’,


    USER: ‘U8324’,


    TEAM: ‘T4390’,


    MESSAGE: ‘/HELP’ }
    CHAT.POST_MESSAGE(‘HERE IS THE HELP YOU REQUESTED:’)

    View full-size slide

  7. USER PLATFORM APP
    CLIENT SERVER

    View full-size slide

  8. J
    os
    eph
    WEIZENBAUM

    View full-size slide

  9. RADIOHEAD
    IS
    ALWAYS
    AHEAD OF THEIR TIME™

    View full-size slide

  10. imp
    or
    tant?
    CHATBOTS
    Why are

    View full-size slide

  11. WHAT
    OCCURRED
    AT THAT
    BASKETBALL GAME?

    View full-size slide

  12. FAMILIAR LESS BARRIERS

    View full-size slide

  13. MESSAGES SLACK
    TEAMS FACEBOOK

    View full-size slide

  14. BE WHERE YOUR USERS ARE

    View full-size slide

  15. PLATFORM SPECIFIC
    FUN STUFF
    BUSINESS STUFF

    View full-size slide

  16. FUN
    DEV CODE RUN BEEP-BOOP

    View full-size slide

  17. built today?
    CHATBOTS
    How are

    View full-size slide

  18. HOW SLACK WORKS
    A P P D I R E C T O R Y

    View full-size slide

  19. HOW SLACK WORKS
    O A U T H W / S L A C K

    View full-size slide

  20. HOW SLACK WORKS
    S C O P E R E Q U E S T

    View full-size slide

  21. HOW SLACK WORKS
    N E W B O T U S E R !

    View full-size slide

  22. USER PLATFORM APP
    OPS CHANNEL
    /HELP
    HOW SLACK WORKS
    { CHANNEL: ‘C1234’,


    USER: ‘U8324’,


    TEAM: ‘T4390’,


    MESSAGE: ‘/HELP’ }

    View full-size slide

  23. JAVASCRIPT LIBRARIES

    View full-size slide

  24. JAVASCRIPT LIBRARIES

    View full-size slide

  25. WORKER THREADS
    CPU PERFORMANCE
    SINGLE-
    THREADED
    EVENT LOOP
    UNHANDLED


    EXCEPTIONS
    NODE LIMITATIONS

    View full-size slide

  26. PROCESSES
    PANACEA
    CURES WHAT
    ALES ‘YA
    SPEED
    HOT CODE
    RELOADING
    FAULT TOLERANCE

    View full-size slide

  27. WHY ELIXIR?
    BUILT FOR COMMUNICATION

    View full-size slide

  28. WHY ELIXIR?
    BUILT FOR COMMUNICATION
    90%

    View full-size slide

  29. WHY ELIXIR?
    BUILT FOR COMMUNICATION

    View full-size slide

  30. FAST
    WHY ELIXIR?

    View full-size slide

  31. WHY ELIXIR?
    https://github.com/mroth/phoenix-showdown/blob/master/README.md#benchmarking

    View full-size slide

  32. STATEFUL PROCESSES
    WHY ELIXIR?

    View full-size slide

  33. WHY ELIXIR?
    PROCESS PROCESS PROCESS
    SUPERVISOR

    View full-size slide

  34. HOT CODE RELOADING
    WHY ELIXIR?

    View full-size slide

  35. WHY ELIXIR?
    FAULT TOLERANT

    View full-size slide

  36. WHY ELIXIR?
    PROCESS PROCESS
    SUPERVISOR
    PROCESS

    View full-size slide

  37. be improved?
    CHATBOTS
    How can building

    View full-size slide

  38. PLUG
    MIDDLEWARE
    CONTEXT
    ROUTER
    CONTROLLER
    TEMPLATES

    View full-size slide

  39. NEXT.TATSU.IO

    View full-size slide

  40. LEBOTSKI
    DISPENSARIES BOWLING ALLEYS
    • COCKTAIL BARS

    View full-size slide

  41. LEBOWSKI COMMANDS
    / B E V E R A G E - H E R E - M A N

    View full-size slide

  42. LEBOTSKI
    DISPENSARIES BOWLING ALLEYS
    • COCKTAIL BARS

    View full-size slide

  43. Aaron
    DRAPLIN
    DRAPLIN.COM

    View full-size slide

  44. JWRIGHT/LEBOTSKI

    View full-size slide

  45. DEMO
    DEMO
    DEMO

    View full-size slide

  46. with Juvet?
    CHATBOTS
    Building

    View full-size slide

  47. JUVET WALKTHROUGH
    A D D D E P E N D E N C Y

    View full-size slide

  48. JUVET WALKTHROUGH
    A D D E X T R A A P P

    View full-size slide

  49. JUVET WALKTHROUGH
    S U P E R V I S I O N T R E E

    View full-size slide

  50. JUVET WALKTHROUGH
    S U P E R V I S I O N T R E E
    NEW LEBOWSKI
    APP FOR MY TEAM

    View full-size slide

  51. JUVET WALKTHROUGH
    C O N F I G U R E

    View full-size slide

  52. JUVET WALKTHROUGH
    B O T

    View full-size slide

  53. JUVET WALKTHROUGH
    R O U T E R

    View full-size slide

  54. JUVET WALKTHROUGH
    A D D P L U G

    View full-size slide

  55. PLUG
    > LISTEN TO SPECIFIC ENDPOINTS
    > INTEGRATE INTO EXISTING APP

    View full-size slide

  56. JUVET WALKTHROUGH
    A D D C O M M A N D R O U T E

    View full-size slide

  57. ROUTER
    > DSL TO DEFINE ROUTES
    > FIND APPROPRIATE ROUTE
    > MIDDLEWARE

    View full-size slide

  58. ROUTER
    F I N D I N G R O U T E S

    View full-size slide

  59. ROUTER
    F I N D I N G R O U T E S

    View full-size slide

  60. MIDDLEWARE
    > CHAIN RESPONSIBILITIES TOGETHER
    > EXTENSION POINTS
    > MODIFY CONTEXT
    > COMMON RUNTIME ON EACH REQUEST

    View full-size slide

  61. MIDDLEWARE
    D E F I N I N G M I D D L E W A R E

    View full-size slide

  62. JUVET WALKTHROUGH
    C U S T O M M I D D L E W A R E

    View full-size slide

  63. CONTEXT
    > VARIABLES FOR USE IN CONTROLLER
    > ONLY UPDATED IN MIDDLEWARE

    View full-size slide

  64. JUVET WALKTHROUGH
    R O U T E R

    View full-size slide

  65. JUVET WALKTHROUGH
    C O N T R O L L E R

    View full-size slide

  66. CONTROLLER
    > ACTION PER REQUEST
    > PREPARE + SEND RESPONSE(S)

    View full-size slide

  67. JUVET WALKTHROUGH
    T E A M S C H E M A

    View full-size slide

  68. JUVET WALKTHROUGH
    U S E R S C H E M A

    View full-size slide

  69. JUVET WALKTHROUGH
    T E A M M AT E S C H E M A

    View full-size slide

  70. JUVET WALKTHROUGH
    C O N T R O L L E R

    View full-size slide

  71. T E M P L AT E

    View full-size slide

  72. JUVET WALKTHROUGH
    S E N D I N G T E M P L AT E

    View full-size slide

  73. TEMPLATES
    > PLATFORM INDEPENDENT
    > SENT BACK AS A RESPONSE
    > INTERLACE DATA

    View full-size slide

  74. like MVC Apps
    CHATBOTS
    The
    tr
    adeo
    ff
    s on building

    View full-size slide

  75. ROUTING
    A NICE


    BLACK BOX
    YOUR APP
    ROUTER
    CONTROLLERS
    TEMPLATES
    AUTHORIZATION
    LOW-LEVEL API
    PLATFORM LIBRARIES
    HIDE THE PLUMBING

    View full-size slide

  76. FAMILIAR PATTERN
    MODEL
    VIEW CONTROLLER
    USER
    SEES USES
    MANIPULATES
    UPDATES

    View full-size slide

  77. EVERYTHING HAS A PLACE
    TEMPLATES
    CONTROLLERS
    MODELS ROUTES
    > BUSINESS LOGIC > HANDLES PLATFORM REQUESTS
    > RUNS MIDDLEWARE
    > PASSES CONTEXT
    > CREATES CONTROLLER
    > RUNS ACTION
    > HANDLES REQUEST
    > PREPARES RESPONSE
    > RENDERS RESPONSE(S)
    > RETRIEVE DATA
    > UPDATE DATA
    > INTEGRATES DATA
    > PROVIDES RESPONSE

    View full-size slide

  78. EXTENSION POINTS
    USER
    REQUEST
    PLATFORM APP
    ROUTER FINDS ROUTE
    MIDDLEWARE IS RUN
    CONTROLLER IS CREATED
    ACTION IS CALLED
    TEMPLATE IS RENDERED
    RESPONSE IS SENT
    USER
    RESPONSE

    View full-size slide

  79. OVERKILL FOR SIMPLE BROADCAST
    PLATFORM
    GITHUB
    > CHAT.POSTMESSAGE

    View full-size slide

  80. HARDER TO DEBUG
    > (PHOENIX.ROUTER.NOROUTEERROR) NO ROUTE FOUND FOR POST /SLACK/ACTIONS (TATSUWEB.ROUTER)
    > (TATSU 0.0.11) LIB/PHOENIX/ROUTER.EX:405: TATSUWEB.ROUTER.CALL/2
    > (COWBOY 2.9.0) /TATSU_NEXT/DEPS/COWBOY/SRC/COWBOY_HANDLER.ERL:37: :COWBOY_HANDLER.EXECUTE/2


    > (TATSU 0.0.11) LIB/TATSU_WEB/ENDPOINT.EX:1: TATSUWEB.ENDPOINT.PLUG_BUILDER_CALL/2
    > …
    > …
    > …
    > …
    > …
    > …
    > …
    C A L L S T A C K

    View full-size slide

  81. Future
    ENHANCEMENTS

    View full-size slide

  82. DIALOGUE
    R U B Y

    View full-size slide

  83. DIALOGUE
    TATSUIO/DIALOGUE

    View full-size slide

  84. ADDITIONAL PLATFORMS
    TWILIO
    TEAMS
    DISCORD
    SLACK
    ALEXA
    #01
    #02
    #03
    #04

    View full-size slide

  85. BETTER TEMPLATING
    COMPONENTS PARTIALS SEPARATE PLATFORMS

    View full-size slide

  86. IN-HOUSE AUTHENTICATION

    View full-size slide

  87. BETTER ERROR MESSAGES
    > (PHOENIX.ROUTER.NOROUTEERROR) NO ROUTE FOUND FOR POST /SLACK/ACTIONS (TATSUWEB.ROUTER)
    > …
    >…


    > …
    > …
    > …
    > …
    > …
    > ??? 💀😅
    C A L L S T A C K

    View full-size slide

  88. RANDOM ACCESS MEMORY
    USER
    CAN YOU
    SCHEDULE


    A MEETING?
    APP
    I SURE CAN.


    WITH WHOM?
    USER
    WITH TIM.
    APP
    GOT IT. WHEN?
    USER
    TOMORROW AT 2.
    APP
    DONE.


    I SCHEDULED A


    MEETING WITH


    TIM TOMORROW
    AT 2.

    View full-size slide

  89. RANDOM ACCESS MEMORY
    CAN YOU SCHEDULE


    A MEETING?
    USER
    CAN YOU SCHEDULE


    A MEETING


    WITH TIM


    TOMORROW AT 2?
    APP
    DONE.


    I SCHEDULED


    YOUR MEETING


    WITH TIM FOR


    TOMORROW AT 2.
    CAN YOU SCHEDULE


    A MEETING?
    USER
    ACTUALLY CAN


    YOU MAKE IT FOR 3?
    APP
    DONE.


    I RE-SCHEDULED


    IT FOR


    TOMORROW AT 3.

    View full-size slide

  90. RANDOM ACCESS MEMORY
    DETECT PARAMETERS ALLOW CHANGE

    View full-size slide

  91. DISCOVERABILITY
    T R A I N I N G W H E E L S
    ARE YOU READY FOR


    THE MEETING?


    YOU CAN REPLY


    WITH ‘Y’ES OR ’N’O.
    APP USER
    YES.
    MEETING SCHEDULED!


    DID YOU KNOW YOU


    CAN REQUEST A RESCHEDULE


    BY REPLYING


    ‘RE-SCHEDULE’?
    APP

    View full-size slide

  92. VALIDATION
    ANDY WANTS TO MEET
    WITH YOU TODAY AT 2.
    APP
    ARE YOU AVAILABLE?
    USER
    BLERG.

    View full-size slide

  93. VALIDATION
    I’M SORRY ‘BLERG’ IS
    NOT AN ANSWER.
    APP
    ACKNOWLEDGE THE RESPONSE
    1.
    YOU CAN RESPOND ‘YES’
    OR ‘NO’
    APP
    PROVIDE CORRECT OPTIONS
    2.
    ANDY WANTS TO MEET
    WITH YOU TODAY AT 2.
    APP
    ARE YOU AVAILABLE?
    RE-ASK THE QUESTION
    3.

    View full-size slide

  94. SELECTION
    WHERE DO YOU WANT TO
    MEET MACKENZIE
    TONIGHT?
    APP USER
    1.
    1. COFFEE SHOP


    2. RESTAURANT


    3. BAR
    APP
    O P T I O N R E D U C T I O N

    View full-size slide

  95. SELECTION
    OK. WHICH COFFEE
    SHOP?
    APP
    O P T I O N R E D U C T I O N
    1. CAFE JOE’S


    2. STARBUCKS ON MAIN


    3. PERKATORY
    APP

    View full-size slide

  96. RESPONSE SAMPLING
    YES
    APP
    OK
    APP
    CORRECT
    APP
    WRONG
    APP
    NOPE
    APP
    LOOKS GOOD
    APP
    👍
    APP

    APP
    THAT’S WHAT SHE SAID
    APP
    COOL
    APP

    View full-size slide

  97. GO FORTH + CREATE BOTS

    View full-size slide

  98. NEXT.TATSU.IO

    View full-size slide

  99. SPEAKERDECK.COM/JWRIGHT/ATO2023

    View full-size slide

  100. @JWRIGHT
    JWRIGHT
    [email protected]
    STANDUP.FM

    View full-size slide

  101. @JWRIGHT
    JWRIGHT
    [email protected]
    STANDUP.FM

    View full-size slide