Chatbot Service
Overview
Chatbot service is a chatbot which provides functionality to the user to access PGR module services like file complaint, track complaint, notifications from whatsapp. Currently citizen has three options to start conversation scan QR code, give missed call or directly send message to configured whatsapp number.
Pre-requisites
Prior Knowledge of Java/J2EE.
Prior Knowledge of SpringBoot.
Prior Knowledge of PostgresSQL.
Prior Knowledge of REST APIs and related concepts like path parameters, headers, JSON etc.
Prior Knowledge of JSONQuery in Postgres. (Similar to PostgresSQL with a few aggregate functions.)
Dependencies
egov-user-chatbot
: For creating user without name validation and logging in useregov-user
: For searching useregov-localization
: The chatbot is made such that it will store localization codes and the actual text value will be fetched only at the end. This way we can provide multi-lingual support. Localization service is also used to construct messages from templates. This dependency can be eliminated if you want to pass values instead of localization codes.egov-filestore
: It is a dependency if you want to send/receive any file. This includes sending PDF/Image files.egov-url-shortening
: For shortening links sent to the useregov-mdms-service
: For loading mdms dataegov-location
: For loading locality datarainmaker-pgr
: For creating/searching PGR complaints
Functionalities
Chatbot service allows citizen to access PGR service through whatsapp. Citizen can provide all details required to create PGR complaint through question and answer method. The service continuosly listen on PGR update Kafka topic and send notifications to users associated with PGR record. On any message from citizen which is forwarded by whatsapp provider, chatbot processes his messages by passing message through various stages ex:- validations, enrichment, transformations etc and at the end sends final response to user by calling endpoint of whatsapp provider.
Configurations
There are two types of configurations for chatbot states:-
Configuration for each state in chatbot, ex:-
name : pgr.create.locality description : "Locality" nodeType : step optional : false type : text validationRequired : true typeOfValues : FixedSetValues displayOptionsInExternalLink: true message : chatbot.messages.pgrCreateLocality values : class : org.egov.chat.xternal.valuefetch.LocalityValueFetcher params : tenantId : ~pgr.create.tenantId authToken : /user/authToken recipient: /extraInfo/recipient matchAnswerThreshold: 70 errorMessage: chatbot.messages.pgrCreateLocalityError
Graph adjacency list configuration:- to define flow between chatbot states,ex:-
root,pgr.create.tenantId,pgr.track.end pgr.create.tenantId,pgr.create.locality pgr.create.locality,pgr.create.landmark
Flow Diagrams
High Level Diagram of chatbot interactions
Flow Diagram of Chatbot-User conversation
Flow Diagram of Chatbot notifications
Deployment Details
Add configs required for chatbot Service.
Deploy the latest version of chatbot Service.
Add Role-Action mapping for API’s.
Integration
Integration Scope
The chatbot service is used to communicate with the users, lodge their complaints or provide miscellaneous / adhoc services which citizens avail from ULBs in an interactive way over whatsapp.
Integration Benefits
Can perform service-specific business logic without impacting the other module.
In the future, if we want to expose the application to citizen then it can be done easily.
Workflow or Service-specific workflow can be enabled at the chatbot level at any time without changing the design.
Steps to Integration
To integrate, host of chatbot module should be overwritten in helm chart.
POST /messages
should be added as the endpoint for receiving user sent message and forward it to chatbot core logic for further processing and sending back response.GET /messages
should be added as the endpoint for receiving user sent message and forward it to chatbot core logic for further processing and sending back response.
Reference Docs
Doc Links
Title | Link |
API Swagger Documentation |
API Details
a) POST /messages
Receive user sent message and forward it to chatbot core logic for further processing and sending back response
If the
media_type
parameter value istext
then user input would be sent in parametertext
, in other cases wheremedia_type
have some other value ex:- image, location etc, the user input would be sent in parametermedia_data
b) GET /messages
Receive user sent message and forward it to chatbot core logic for further processing and sending back response
If the
media_type
parameter value istext
then user input would be sent in parametertext
, in other cases wheremedia_type
have some other value ex:- image, location etc, the user input would be sent in parametermedia_data
Kafka Consumers
update-pgr-service
: used inupdate.pgr.service.topic
application property, chatbot listens on this topic to listen for updates on PGR records and then to send notifications to user.The service uses consumers for internal processing also between different stages.
Kafka Producers
send-message-localized
: chatbot sends data to this topic for telemetry indexing and for internal processing.The service uses producers for internal processing also between different stages.