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

Breakthrough Event-Driven Architecture for Chatbots

Breakthrough Event-Driven Architecture for Chatbots

B29f42636a5f1249b640473d49aa4514?s=128

LINE Developers Thailand

October 16, 2021
Tweet

Transcript

  1. None
  2. Chanintorn Asavavichairoj Lead Tech Specialist SCB TechX BREAKTHROUGH 
 EVENT-DRIVEN

    ARCHITECTURE 
 FOR CHATBOTS
  3. © 2021 SCB Tech X Co., Ltd. Jo, Tech Specialist

    at SCB TechX
  4. © 2021 SCB Tech X Co., Ltd. Agenda Breakthrough Event-Driven

    Architecture for Chatbot What is Event- Driven Architecture? 01 Loosely Coupled with LINE Webhook Event 02 Enabling Event-Driven by Kafka Family 03 Usecase : Message Sentiment Monitoring 04
  5. © 2021 SCB Tech X Co., Ltd. Chain Reaction Event

    Software Design Pattern Rube Goldberg Machine (https://www. concordia.qld.edu.au/rube-goldberg-machine)
  6. © 2021 SCB Tech X Co., Ltd. What is Event-Driven

    Architecture (EDA)? Software Design Pattern Decision 
 (OLAP) Events Events Events 👨💼 Customer Events Wired Context New / Existed 
 Data Business Outcome 
 
 
 Customer Experiences 😋 System Events 👩💼 ⌚ Others Events 📟 🕹
  7. © 2021 SCB Tech X Co., Ltd. Transaction and Analytic

    Data Processing Event-Driven Architecture Business Processes Business 
 Data Warehouse OLTP OLAP Business Decision Operation Data Bigdata Deep Learning Machine Learning Great Chatbot
  8. © 2021 SCB Tech X Co., Ltd. Monolith vs Microservices

    Software Design Pattern Local transactions within the same codebase Distributed transactions across services Monolith Microservices
  9. © 2021 SCB Tech X Co., Ltd. HTTP Response Message

    Response Feedback N/A Communication and Collaboration between Microservices Software Design Pattern Synchronous Asynchronous Communication Blocking Non-Blocking I/O REST Message Queue Event Source Pattern Command Driven Event Driven Collaboration N/A
  10. © 2021 SCB Tech X Co., Ltd. Request/Response vs Event

    Source Software Design Pattern </> Request Response Produce Consume Consume ☎ ☎ Request/Response Broker 
 
 
 
 Topic </> Event Source Topic Topic ✉ ✉ ✉
  11. © 2021 SCB Tech X Co., Ltd. LINE Webhook Event

    LINE Messaging API NLU PROCESSING CHAT LOGS ACCOUNT LINK USER PROFILE BEACON MICRO LOCATION Follow / Unfollow Message Join / Leave Group Beacons Postback Account Link Device Link / Unlink ANALYTIC METRICS Webhook
  12. © 2021 SCB Tech X Co., Ltd. LINE Webhook Event

    LINE Messaging API NLU PROCESSING CHAT LOGS ACCOUNT LINK USER PROFILE BEACON MICRO LOCATION Follow / Unfollow Message Join / Leave Group Beacons Postback Account Link Device Link / Unlink ANALYTIC METRICS Webhook http://user-pro 
 Coupling
  13. © 2021 SCB Tech X Co., Ltd. LINE Webhook Event

    LINE Messaging API NLU PROCESSING CHAT LOGS ACCOUNT LINK USER PROFILE BEACON MICRO LOCATION Follow / Unfollow Message Join / Leave Group Beacons Postback Account Link Device Link / Unlink ANALYTIC METRICS Event Broker Webhook
  14. © 2021 SCB Tech X Co., Ltd. LINE Webhook Event

    LINE Messaging API NLU PROCESSING CHAT LOGS ACCOUNT LINK USER PROFILE BEACON MICRO LOCATION Follow / Unfollow Message Join / Leave Group Beacons Postback Account Link Device Link / Unlink ANALYTIC METRICS Message, 

  15. © 2021 SCB Tech X Co., Ltd. Introduce Kafka Family

    Event Source Middleware Connector / Connect Stream Processing Support Management Client / Schema / Development Connector / Connect KAFKA KAFKA PRODUCER Source KAFKA KAFKA CONSUMER Sink
  16. © 2021 SCB Tech X Co., Ltd. Stream Processing Realtime

    Processing with KSQL Coding Sophistication Dev in Java / Scala Dev in others languages Data Engineer, DevOps BI Analyst No Need for Technical Skill streams
  17. © 2021 SCB Tech X Co., Ltd. KSQL Concept :

    Message Filtering Realtime Processing with KSQL CREATE STREAM line-message AS 
 SELECT * 
 FROM line-webhook 
 WHERE type=‘message'; { 
 type: ‘message’, 
 text: ‘this is text’ 
 } { 
 type: ‘message’, 
 text: ‘this is text’ 
 } { 
 type: ‘postback’, 
 data: ‘this is data’ 
 } { 
 type: ‘message’, 
 text: ‘hello’ 
 } { 
 type: ‘message’, 
 text: ‘hello’ 
 } { 
 type: ‘sticker’, 
 stickerid: 123 
 }
  18. © 2021 SCB Tech X Co., Ltd. KSQL Concept :

    Data Transformation Realtime Processing with KSQL CREATE STREAM line-message AS 
 SELECT text 
 FROM line-webhook 
 WHERE type=‘message'; { 
 type: ‘message’, 
 text: ‘this is text’ 
 } { 
 text: ‘this is text’ 
 } { 
 type: ‘postback’, 
 data: ‘this is data’ 
 } { 
 type: ‘message’, 
 text: ‘hello’ 
 } { 
 text: ‘hello’ 
 } { 
 type: ‘sticker’, 
 stickerid: 123 
 }
  19. © 2021 SCB Tech X Co., Ltd. KSQL Concept :

    Data Aggregation Realtime Processing with KSQL CREATE STREAM line-message AS 
 SELECT COUNT(*) AS count 
 FROM line-webhook WINDOW TUMBLING (SIZE 1 HOUR) 
 GROUP BY type; { 
 type: ‘message’, 
 text: ‘this is text’ 
 } { 
 type: ‘postback’, 
 data: ‘this is data’ 
 } { 
 type: ‘message’, 
 text: ‘hello’ 
 } { 
 type: ‘sticker’, 
 stickerid: 123 
 } { 
 type: ‘message’, 
 count: 2 
 } { 
 type: ‘postback’, 
 count: 1 
 } { 
 type: ‘sticker’, 
 count: 1 
 }
  20. © 2021 SCB Tech X Co., Ltd. Realtime LINE Events

    Processing with KSQL Sample Use Case 
 
 
 
 NLU PROCESSING Webhook Messaging API 1 2 3 4 5 6 7 8
  21. © 2021 SCB Tech X Co., Ltd. Pain Point from

    Chatbot False Positive Sample Use Case False Positive Missed Classi fi cation 0% 100% X % Ambiguous Con fi dent Level Fallback Y % 🤥 🥺 🤥 🤥 🥺 🥺 😇 Sorry, I don’t know 🤖 #@%&{]!~]){>=+*?
  22. © 2021 SCB Tech X Co., Ltd. Enriching chatbot journey

    with live chat experiences Related Sessions .. 
 LINE THAILAND DEVELOPER CONFERENCE 2020 LINE Developer Thailand Pain Point from Chatbot False Positive Sample Use Case Manual Labeling Satisfaction Survey Tone and Sentiment Bot Training Effort
  23. © 2021 SCB Tech X Co., Ltd. Message Sentiment Monitoring

    Sample Use Case 🤖 Message 
 Events SENTIMENT 
 ANALYZER 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
 10 { 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
 10 List of up to 15 keywords describing the sticker {
  24. © 2021 SCB Tech X Co., Ltd. Message Sentiment Monitoring

    Sample Use Case 
 
 NOTIFY SERVICE 3 4 0 
 
 
 SENTIMENT 
 ANALYZER
  25. © 2021 SCB Tech X Co., Ltd. 1 
 2

    
 3 
 4 
 5 
 6 
 7 
 8 
 9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 
 26 
 27 consumer = KafkaConsumer( 
 
 
 SENTIMENT 
 ANALYZER 🤖 sentiment_analyzer.py (Sample Code) Kafka Consumer 

  26. © 2021 SCB Tech X Co., Ltd. 1 
 2

    
 3 
 4 
 5 
 6 
 7 
 8 
 9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 
 26 
 27 const client = new kafka.KafkaClient({ "kafkaHost": "localhost:9092" }); const consumer = new kafka.Consumer(client, [ { topic: ‘SENTIMENT-ALERT’ } ], { autoCommit: true, groupId: 'line-notify-group' }); consumer.on('message', function (message) { var sentiment_stats = JSON.parse(message.value); request({ method: 'POST', uri: 'https://notify-api.line.me/api/notify', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, auth: { 'bearer': token }, form: { message: sentiment_stats.sentiment } }, (err, httpResponse, body) => { if (err) { Message Sentiment Monitoring Sample Use Case 
 
 NOTIFY SERVICE line-notify.js (Sample Code) Send Notify to admin 

  27. © 2021 SCB Tech X Co., Ltd. Let’s start short

    demo!
  28. None
  29. © 2021 SCB Tech X Co., Ltd. Deal with Automated

    Test ? Event-Driven Challenge Integration test in 
 event driven architecture Related Sessions .. 
 LINE THAILAND DEVELOPER CONFERENCE 2021 </> Request Response HTTP(S) Server Request/Response </> Produce 📮 Message Broker Response Event Source
  30. None