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

Breakthrough Event-Driven Architecture for Chat...

Breakthrough Event-Driven Architecture for Chatbots

LINE Developers Thailand

October 16, 2021
Tweet

More Decks by LINE Developers Thailand

Other Decks in Technology

Transcript

  1. © 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
  2. © 2021 SCB Tech X Co., Ltd. Chain Reaction Event

    Software Design Pattern Rube Goldberg Machine (https://www. concordia.qld.edu.au/rube-goldberg-machine)
  3. © 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 📟 🕹
  4. © 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
  5. © 2021 SCB Tech X Co., Ltd. Monolith vs Microservices

    Software Design Pattern Local transactions within the same codebase Distributed transactions across services Monolith Microservices
  6. © 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
  7. © 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 ✉ ✉ ✉
  8. © 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
  9. © 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
  10. © 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
  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 Message, 

  12. © 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
  13. © 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
  14. © 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 
 }
  15. © 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 
 }
  16. © 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 
 }
  17. © 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
  18. © 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 🤖 #@%&{]!~]){>=+*?
  19. © 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
  20. © 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 {
  21. © 2021 SCB Tech X Co., Ltd. Message Sentiment Monitoring

    Sample Use Case 
 
 NOTIFY SERVICE 3 4 0 
 
 
 SENTIMENT 
 ANALYZER
  22. © 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 

  23. © 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 

  24. © 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