SlideShare a Scribd company logo
How To Build A
ChatBot
By Himanshu
Chat: Types
Peer to Peer
● WhatsApp
Bot
● JobFinder
Chat: Types
Peer to Peer
● WhatsApp
● Message Processing?
○ Detect Intent for Spam, Abuse or Hate.
Bot
● JobFinder
● Message Processing?
○ Detect Intent to understand the
message. .
Chat: Types
Peer to Peer
● WhatsApp
● Message Processing?
○ Detect Intent for Spam, Abuse or Hate.
○ No validation or verification.
○ Ideally takes less time.
Bot
● JobFinder
● Message Processing?
○ Detect Intent to understand the msg.
○ Validation & Verification required. May
include API calls.
○ Major bottleneck in scaling the bot.
Chat: Types
Peer to Peer
● WhatsApp
● Message Processing?
○ Detect Intent for Spam, Abuse or Hate.
○ No validation or verification.
○ Ideally takes less time.
Bot
● JobFinder
● Message Processing?
○ Detect Intent to understand the msg.
○ Validation & Verification required. May
include API calls.
○ Major bottleneck in scaling the bot.
Message order should be preserved and Message drop be minimal
Chat: Client-Server
ChatBot: Outline
Till Now..
1. How does a chat application differ from a regular application with respect to
client and server communication?
2. How is a chatbot different from a peer to peer chat?
3. Basic Outline of a chatbot.
Principles: Messages In Order
Clients Bot Server
M23 M22 M13 M12 M21 M11
R11 R21 R12 R13 R22 R23
M23 : 3rd message by 2nd client
R21 : 1st reply for 2nd client
Principles: Messages In Order
Clients Bot Server
M23 M22 M13 M12 M21 M11
R21 R11 R12 R13 R22 R23
M23 : 3rd message by 2nd client
R21 : 1st reply for 2nd client
Order not to be preserved for
messages from different users
Principles: Messages In Order
At both client and server side we need
Queuing Mechanism
● Rabbitmq at server side
Acknowledgement/Receipts Logic
● Socket events
Principles: Messages In Order
At both client and server side we need
Queuing Mechanism
● Rabbitmq at server side
● Without it at client side:
○ Client’s 1st msg is a 5 mb image and
,within 2 seconds, one word msg is sent
as 2nd msg.
Acknowledgement/Receipts Logic
● Socket events
Principles: Messages In Order
At both client and server side we need
Queuing Mechanism
● Rabbitmq at server side
● Without it at client side:
○ Client’s 1st msg is a 5 mb image and
,within 2 seconds, one word msg is sent
as 2nd msg.
○ OR don’t give the option of sending a
msg till last one is delivered!!
Acknowledgement/Receipts Logic
● Socket events
Principles: Messages In Order
At both client and server side we need
Queuing Mechanism
● Rabbitmq at server side
Acknowledgement/Receipts Logic
● Socket events
● Without it at client side:
○ Network Latency for a bigger msg may
deliver a smaller one before it.
Principles: Minimal Message Drop
At both client and server side we need
Queuing Mechanism
● Rabbitmq at server side
Receipts & Retry Logic
● Socket events
Principles: Minimal Message Drop
At both client and server side we need
Queuing Mechanism
● Rabbitmq at server side
● Why?
○ Socket connection breaks.
○ User goes offline or server is down.
Receipts & Retry Logic
● Socket events
● Why?
○ No Receipt means msg needs to be
retried.
Principles: Minimal Message Drop
At both client and server side we need
Queuing Mechanism
● Rabbitmq at server side
● Why?
○ Socket connection breaks.
○ User goes offline or server is down.
● 30-40 percent drop because of
break in connection.
Receipts & Retry Logic
● Socket events
● Why?
○ No Receipt means msg needs to be
retried.
● 0.1-1 percent drop without retry
logic.
Scalability and Resilience
● Use multiple queues and multiple consumer
processes. Same client messages should be in the
same queue: Kafka Topics & Partitions, Rabbitmq
exchanges & routing keys
Messages of
two users
don’t put any
dependency
on each other
Scalability and Resilience
● Use multiple queues at server side and multiple
consumer processes. Same client messages should
be in one queue.
● If message processing fails for a particular client,
dequeue all messages for the same client and put in
another queue: Dead Letter queue.
Messages of
two users
don’t put any
dependency
on each other
Scalability and Resilience
● Use multiple queues at server side and multiple
consumer processes. Same client messages should
be in one queue.
● If message processing fails for a particular client,
dequeue all messages for the same client and put in
another queue.
● Message Processing Time should be kept in check:
Asynchronous API and DB calls wherever
possible.
Messages of
two users
don’t put any
dependency
on each other
ChatBot: Make it Dynamic
Greeting
Introduction
Last Content
Main Flow 2
Main Flow 1
Thank You
Human Interaction
Old User New User
Cohort 1 Cohort 2
Event X
Flow Added Later
Invalid UR
ChatBot: Make it Dynamic
1. Define states.
2. Define Transitions.
ChatBot: Make it Dynamic
1. Define states.
2. Define Transitions.
a. Based on Rules
b. Based on Events
c. Based on Responses
ChatBot: Make it Dynamic
1. Define states.
2. Define Transitions.
a. Based on Rules
b. Based on Events
c. Based on Responses
3. Experiment framework can be integrated with it.
ChatBot: Make it Dynamic
1. Define states.
2. Define Transitions.
a. Based on Rules
b. Based on Events
c. Based on Responses
3. Experiment framework can be integrated with it.
State Machine also sets the philosophy of the chat.
ChatBot: Gist
1. Messages should be in order.
2. Messages should rarely drop.
3. Message processing time should be kept in check.
4. Multiple consumers should be used to scale.
5. Message processing failure for one user should not block another user.
6. Chat should be dynamic.
Questions?

More Related Content

Similar to Building chat bot

MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
Jitendra Bafna
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
vishnu rao
 
Characterizing and Detecting Livestreaming Chatbots
Characterizing and Detecting Livestreaming Chatbots Characterizing and Detecting Livestreaming Chatbots
Characterizing and Detecting Livestreaming Chatbots
IIIT Hyderabad
 
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, GoogleBringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Ambassador Labs
 
Microservices summit talk 1/31
Microservices summit talk   1/31Microservices summit talk   1/31
Microservices summit talk 1/31
Varun Talwar
 
2 years into drinking the Microservice kool-aid (Fact and Fiction)
2 years into drinking the Microservice kool-aid (Fact and Fiction)2 years into drinking the Microservice kool-aid (Fact and Fiction)
2 years into drinking the Microservice kool-aid (Fact and Fiction)
roblund
 
SPDY and What to Consider for HTTP/2.0
SPDY and What to Consider for HTTP/2.0SPDY and What to Consider for HTTP/2.0
SPDY and What to Consider for HTTP/2.0
Mike Belshe
 
Patna_Meetup_MQ
Patna_Meetup_MQPatna_Meetup_MQ
Patna_Meetup_MQ
Om Prakash
 
Netflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaNetflix Data Pipeline With Kafka
Netflix Data Pipeline With Kafka
Steven Wu
 
Netflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaNetflix Data Pipeline With Kafka
Netflix Data Pipeline With Kafka
Allen (Xiaozhong) Wang
 
Testing and Developing gRPC APIs
Testing and Developing gRPC APIsTesting and Developing gRPC APIs
Testing and Developing gRPC APIs
Postman
 
TSC Summit #4 - Howto get browser persitence and remote execution (JS)
TSC Summit #4 - Howto get browser persitence and remote execution (JS)TSC Summit #4 - Howto get browser persitence and remote execution (JS)
TSC Summit #4 - Howto get browser persitence and remote execution (JS)
Mikal Villa
 
FastNetMon and Metrics
FastNetMon and MetricsFastNetMon and Metrics
FastNetMon and Metrics
Altinity Ltd
 
gRPC or Rest, why not both?
gRPC or Rest, why not both?gRPC or Rest, why not both?
gRPC or Rest, why not both?
Mohammad Murad
 
Consuming RabbitMQ at TTL
Consuming RabbitMQ at TTLConsuming RabbitMQ at TTL
Consuming RabbitMQ at TTL
jeanml
 
10 Things Every Developer Using RabbitMQ Should Know
10 Things Every Developer Using RabbitMQ Should Know10 Things Every Developer Using RabbitMQ Should Know
10 Things Every Developer Using RabbitMQ Should Know
VMware Tanzu
 
Message Broker System and RabbitMQ
Message Broker System and RabbitMQMessage Broker System and RabbitMQ
Message Broker System and RabbitMQ
University of Alabama at Birmingham
 
An Introduction To Software Development - Software Development Midterm Review
An Introduction To Software Development - Software Development Midterm ReviewAn Introduction To Software Development - Software Development Midterm Review
An Introduction To Software Development - Software Development Midterm Review
Blue Elephant Consulting
 
Building real time applications with Symfony2
Building real time applications with Symfony2Building real time applications with Symfony2
Building real time applications with Symfony2
Antonio Peric-Mazar
 
Messaging
MessagingMessaging
Messaging
Sean Kelly
 

Similar to Building chat bot (20)

MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Characterizing and Detecting Livestreaming Chatbots
Characterizing and Detecting Livestreaming Chatbots Characterizing and Detecting Livestreaming Chatbots
Characterizing and Detecting Livestreaming Chatbots
 
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, GoogleBringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
 
Microservices summit talk 1/31
Microservices summit talk   1/31Microservices summit talk   1/31
Microservices summit talk 1/31
 
2 years into drinking the Microservice kool-aid (Fact and Fiction)
2 years into drinking the Microservice kool-aid (Fact and Fiction)2 years into drinking the Microservice kool-aid (Fact and Fiction)
2 years into drinking the Microservice kool-aid (Fact and Fiction)
 
SPDY and What to Consider for HTTP/2.0
SPDY and What to Consider for HTTP/2.0SPDY and What to Consider for HTTP/2.0
SPDY and What to Consider for HTTP/2.0
 
Patna_Meetup_MQ
Patna_Meetup_MQPatna_Meetup_MQ
Patna_Meetup_MQ
 
Netflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaNetflix Data Pipeline With Kafka
Netflix Data Pipeline With Kafka
 
Netflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaNetflix Data Pipeline With Kafka
Netflix Data Pipeline With Kafka
 
Testing and Developing gRPC APIs
Testing and Developing gRPC APIsTesting and Developing gRPC APIs
Testing and Developing gRPC APIs
 
TSC Summit #4 - Howto get browser persitence and remote execution (JS)
TSC Summit #4 - Howto get browser persitence and remote execution (JS)TSC Summit #4 - Howto get browser persitence and remote execution (JS)
TSC Summit #4 - Howto get browser persitence and remote execution (JS)
 
FastNetMon and Metrics
FastNetMon and MetricsFastNetMon and Metrics
FastNetMon and Metrics
 
gRPC or Rest, why not both?
gRPC or Rest, why not both?gRPC or Rest, why not both?
gRPC or Rest, why not both?
 
Consuming RabbitMQ at TTL
Consuming RabbitMQ at TTLConsuming RabbitMQ at TTL
Consuming RabbitMQ at TTL
 
10 Things Every Developer Using RabbitMQ Should Know
10 Things Every Developer Using RabbitMQ Should Know10 Things Every Developer Using RabbitMQ Should Know
10 Things Every Developer Using RabbitMQ Should Know
 
Message Broker System and RabbitMQ
Message Broker System and RabbitMQMessage Broker System and RabbitMQ
Message Broker System and RabbitMQ
 
An Introduction To Software Development - Software Development Midterm Review
An Introduction To Software Development - Software Development Midterm ReviewAn Introduction To Software Development - Software Development Midterm Review
An Introduction To Software Development - Software Development Midterm Review
 
Building real time applications with Symfony2
Building real time applications with Symfony2Building real time applications with Symfony2
Building real time applications with Symfony2
 
Messaging
MessagingMessaging
Messaging
 

Recently uploaded

Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 

Recently uploaded (20)

Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 

Building chat bot

  • 1. How To Build A ChatBot By Himanshu
  • 2. Chat: Types Peer to Peer ● WhatsApp Bot ● JobFinder
  • 3. Chat: Types Peer to Peer ● WhatsApp ● Message Processing? ○ Detect Intent for Spam, Abuse or Hate. Bot ● JobFinder ● Message Processing? ○ Detect Intent to understand the message. .
  • 4. Chat: Types Peer to Peer ● WhatsApp ● Message Processing? ○ Detect Intent for Spam, Abuse or Hate. ○ No validation or verification. ○ Ideally takes less time. Bot ● JobFinder ● Message Processing? ○ Detect Intent to understand the msg. ○ Validation & Verification required. May include API calls. ○ Major bottleneck in scaling the bot.
  • 5. Chat: Types Peer to Peer ● WhatsApp ● Message Processing? ○ Detect Intent for Spam, Abuse or Hate. ○ No validation or verification. ○ Ideally takes less time. Bot ● JobFinder ● Message Processing? ○ Detect Intent to understand the msg. ○ Validation & Verification required. May include API calls. ○ Major bottleneck in scaling the bot. Message order should be preserved and Message drop be minimal
  • 8. Till Now.. 1. How does a chat application differ from a regular application with respect to client and server communication? 2. How is a chatbot different from a peer to peer chat? 3. Basic Outline of a chatbot.
  • 9. Principles: Messages In Order Clients Bot Server M23 M22 M13 M12 M21 M11 R11 R21 R12 R13 R22 R23 M23 : 3rd message by 2nd client R21 : 1st reply for 2nd client
  • 10. Principles: Messages In Order Clients Bot Server M23 M22 M13 M12 M21 M11 R21 R11 R12 R13 R22 R23 M23 : 3rd message by 2nd client R21 : 1st reply for 2nd client Order not to be preserved for messages from different users
  • 11. Principles: Messages In Order At both client and server side we need Queuing Mechanism ● Rabbitmq at server side Acknowledgement/Receipts Logic ● Socket events
  • 12. Principles: Messages In Order At both client and server side we need Queuing Mechanism ● Rabbitmq at server side ● Without it at client side: ○ Client’s 1st msg is a 5 mb image and ,within 2 seconds, one word msg is sent as 2nd msg. Acknowledgement/Receipts Logic ● Socket events
  • 13. Principles: Messages In Order At both client and server side we need Queuing Mechanism ● Rabbitmq at server side ● Without it at client side: ○ Client’s 1st msg is a 5 mb image and ,within 2 seconds, one word msg is sent as 2nd msg. ○ OR don’t give the option of sending a msg till last one is delivered!! Acknowledgement/Receipts Logic ● Socket events
  • 14. Principles: Messages In Order At both client and server side we need Queuing Mechanism ● Rabbitmq at server side Acknowledgement/Receipts Logic ● Socket events ● Without it at client side: ○ Network Latency for a bigger msg may deliver a smaller one before it.
  • 15. Principles: Minimal Message Drop At both client and server side we need Queuing Mechanism ● Rabbitmq at server side Receipts & Retry Logic ● Socket events
  • 16. Principles: Minimal Message Drop At both client and server side we need Queuing Mechanism ● Rabbitmq at server side ● Why? ○ Socket connection breaks. ○ User goes offline or server is down. Receipts & Retry Logic ● Socket events ● Why? ○ No Receipt means msg needs to be retried.
  • 17. Principles: Minimal Message Drop At both client and server side we need Queuing Mechanism ● Rabbitmq at server side ● Why? ○ Socket connection breaks. ○ User goes offline or server is down. ● 30-40 percent drop because of break in connection. Receipts & Retry Logic ● Socket events ● Why? ○ No Receipt means msg needs to be retried. ● 0.1-1 percent drop without retry logic.
  • 18. Scalability and Resilience ● Use multiple queues and multiple consumer processes. Same client messages should be in the same queue: Kafka Topics & Partitions, Rabbitmq exchanges & routing keys Messages of two users don’t put any dependency on each other
  • 19. Scalability and Resilience ● Use multiple queues at server side and multiple consumer processes. Same client messages should be in one queue. ● If message processing fails for a particular client, dequeue all messages for the same client and put in another queue: Dead Letter queue. Messages of two users don’t put any dependency on each other
  • 20. Scalability and Resilience ● Use multiple queues at server side and multiple consumer processes. Same client messages should be in one queue. ● If message processing fails for a particular client, dequeue all messages for the same client and put in another queue. ● Message Processing Time should be kept in check: Asynchronous API and DB calls wherever possible. Messages of two users don’t put any dependency on each other
  • 21. ChatBot: Make it Dynamic Greeting Introduction Last Content Main Flow 2 Main Flow 1 Thank You Human Interaction Old User New User Cohort 1 Cohort 2 Event X Flow Added Later Invalid UR
  • 22. ChatBot: Make it Dynamic 1. Define states. 2. Define Transitions.
  • 23. ChatBot: Make it Dynamic 1. Define states. 2. Define Transitions. a. Based on Rules b. Based on Events c. Based on Responses
  • 24. ChatBot: Make it Dynamic 1. Define states. 2. Define Transitions. a. Based on Rules b. Based on Events c. Based on Responses 3. Experiment framework can be integrated with it.
  • 25. ChatBot: Make it Dynamic 1. Define states. 2. Define Transitions. a. Based on Rules b. Based on Events c. Based on Responses 3. Experiment framework can be integrated with it. State Machine also sets the philosophy of the chat.
  • 26. ChatBot: Gist 1. Messages should be in order. 2. Messages should rarely drop. 3. Message processing time should be kept in check. 4. Multiple consumers should be used to scale. 5. Message processing failure for one user should not block another user. 6. Chat should be dynamic.