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

  1. Prior Knowledge of Java/J2EE.

  2. Prior Knowledge of SpringBoot.

  3. Prior Knowledge of PostgresSQL.

  4. Prior Knowledge of REST APIs and related concepts like path parameters, headers, JSON etc.

  5. 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 user

  • egov-user : For searching user

  • egov-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 user

  • egov-mdms-service : For loading mdms data

  • egov-location : For loading locality data

  • rainmaker-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

  1. Add configs required for chatbot Service.

  2. Deploy the latest version of chatbot Service.

  3. 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

  1. To integrate, host of chatbot module should be overwritten in helm chart.

  2. 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.

  3. 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

Title 

Link

API Swagger Documentation

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 is text then user input would be sent in parameter text, in other cases where media_type have some other value ex:- image, location etc, the user input would be sent in parameter media_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 is text then user input would be sent in parameter text, in other cases where media_type have some other value ex:- image, location etc, the user input would be sent in parameter media_data

Kafka Consumers

  • update-pgr-service : used in update.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.