KPIT HR-Bot enables KPIT employees to be more productive by allowing employees to complete tasks like applying for/ approving leaves, etc. using channels like Skype and Teams. Employees no longer need to manually parse through FAQ documents, or seek clarifications from HR through emails to find out about HR policies, they can find these details just by querying the HR Bot.

  • Solution overview Bot Flow The KPIT HR Bot is created using the Bot Framework and deployed to an Azure Web app. The key dependencies of the KPIT HR Bot include the Microsoft QnA Maker Service to provide answers to user HR process related queries, and the KPIT Authentication and HR System APIs for performing actions like fetching, approving and rejecting pending requests.

  • Key technologies used

Microsoft Partnered with KPIT to create the initial version of the HR-Bot during a 2 day hackfest.

  • Core Team:
    • Meeta Jangde - Senior Developer, Information Systems Group, KPIT
    • Ravi Khatri - Senior Developer, Information Systems Group, KPIT
    • Jyoti Sagar Chowrasia - Senior Developer, Information Systems Group, KPIT
    • Venkat Reddy - Information Systems Group-DT, KPIT
    • Maninderjit Bindra – Senior Technical Evangelist, Microsoft
    • Brij Raj Singh – Senior Technical Evangelist, Microsoft

The Hackfest Team

Customer profile

KPIT is a global technology company that specializes in providing IT Consulting and Product Engineering solutions and services to key focus industries - Automotive and Transportation, Consumer and Industrial Goods, Energy and Resources, High Tech, Life Sciences, and Utilities. The KPIT CIOs Office owns KPIT internal systems which are used by over 10000 of its employees.

Problem statement

KPIT CIOs office wanted to enhance the user experience of internal employees when accessing FAQ related to HR processes. CIOs office also wanted to enable increased productivity of KPIT employees. Details related to these points are shown below :

  • KPIT has several FAQ documents for processes like performance appraisal, visa processing etc. Currently the employees need to figure out which FAQ document they need to refer to and then search through that FAQ document regarding their query. KPIT want the HR-bot to be able to respond to queries related to all these FAQ documents.
  • KPIT want to make services like leave applications / approvals available to authenticated users over chat channels like skype , teams and at some point on skype for business.

Solution and steps

Scope

  • Before getting started with the actual implementation of the bot, the hackfest scope for the bot was finalized
  • The scope included 3 bot main menu items
    • The Bot should allow authenticated users to Retrieve pending approval requests, and approve / reject the requests with comments. The backend APIs to retrieve, approve/reject the requests, authenticate users are in place.
    • The Bot should allow the authenticated users to submit new compensatory off requests. This would require the user to enter required fields like date, hours and comment
    • The Bot would respond to user queries related to HR Processes. The QNA Maker service would be used to load the existing FAQ documents and modify the QNA maker service Model as needed. For the scope of the hackfest 2 of the KPIT FAQ documents were imported and configured in the QNA maker service

Key Flows

Pending Request / Compensatory Off Flow

Bot Flow

  • To perform actions like fetching pending approval requests or to create a new compensatory off request the bot needs to call the KPIT HR System APIs. A JWT authentication token needs to passed to these KPIT APIs. For such actions bot first checks if the JWT token required to invoke these APIs is available for the user. If the token is not available the bot authentication flow, detailed in the Technical delivery section below is triggered. Once the JWT token is available the KPIT HR System Rest APIs can be invoked.

HR Process query flow

Bot Flow

  • If user has any HR process related query, this flow is triggered. Response to the queries is provided by the QnA Maker Service Model.

Technical delivery

Authentication

  • The Authentication flow is shown below. This required the KPIT team to create a new Java Web Page and controller. Once the JWT token for a user is available for a user it is stored in the bot session. Bot Flow
  • The diagram above represents the happy flow
  • Some key points related to this flow are :
    • If user tries to perform an action which requires to call the KPIT HR System APIs, then bot first checks if JWT token exists for the user in the session. If JWT token does not exist then bot generates a unique string and sends a message to the user that user needs to authenticate along with URL of the KPIT authentication Java Web page appended with the unique string generated.
    • User clicks this link and the Authentication page opens up. User enters credentials and hits submit. The Webpage controller then first checks if the credentials are valid by calling the KPIT authentication service authenticate operation. This operation returns a JWT token if authentication is successful
    • The web page controller then generates a 6 character random access code
    • Next the controller saves the combination of the unique string received from the bot, generated access code and JWT token in a redis cache.
    • After this the user is displayed the access code, and request to type this in the open bot chat window.
    • Once the user types this access code into the chat window, bot first validates if valid JWT token exists for the combination of access code and unique string in the redis cache.
    • If token is found bot calls the KPIT IDP authentication service is token valid operation to validate if the token is still valid.
    • If token is valid it is stored by the bot in the users session
    • Message is sent to the user that user has been authenticated.

HR-bot

  • The bot capabilities have been defined in the solution scope section above
  • Selecting any menu item from the main bot menu takes the User into a nested dialog. Images below show the get / approve pending requests and apply for compensatory off functionalities: Get / Approve pending requests Apply for compensatory off

  • If the user selects option 3 “Find Out About HR Policies” from the Main menu, then the nested bot dialog calls the QNA service end point to retrieve answers to queries

QNA Maker Service

  • During the hackfest 2 of the FAQ documents were imported into the QNA service and then configured. This included the Performance Appraisal policy document. Eventually all the FAQ documents would be imported into the same knowledge base. Image below demonstrates this functionality in action : Find out about HR Policies Below is the bot code that integrates with the QnA Maker service. The QnA Maker subscription key (QNA_KEY), the QNA_HOST and QNA_PATH need to injected as environment variables.
var builder = require('botbuilder');
var https = require('https');
const util = require('util');

module.exports = [

    function (session) {
        builder.Prompts.text(session, 'Ok! Shoot what do you have in your mind.');
    },
    function (session, results) {
        session.dialogData.Qna = results.response;
         console.log(results.response);
        jsonObject = JSON.stringify({"question":results.response});

        var postheaders = {
        'Content-Type' : 'application/json',
        'Content-Length' : Buffer.byteLength(jsonObject, 'utf8'),
        'Ocp-Apim-Subscription-Key': process.env.QNA_KEY           
        };

       console.log("postheaders : " + util.inspect(postheaders, false, null));

        var options = {
            host: process.env.QNA_HOST,
            path: process.env.QNA_PATH,
            method: 'POST',
            headers : postheaders
            };

        console.log("options:" + util.inspect(options, false, null));    
        // do the POST call
        var reqPost = https.request(options, function(res) {
            console.log("statusCode: ", res.statusCode);
            console.log("headers: ", res.headers);

            res.on('data', function(d) {
                console.info('POST result:\n');
                console.log(d);
                var resVal = d.toString('utf8');
                session.send('this is the response according to FAQs available.');
                session.send(JSON.parse(resVal).answer);
                session.endDialog();
                console.info('\n\nPOST completed');
            });
        });

        // write the json data
        reqPost.write(jsonObject);
        reqPost.end();
        reqPost.on('error', function(e) {
            console.error(e);
        });

    }
];

Repository

The following repository contains the initial version of the code base which was created during the hackfest. Integration with the KPIT APIs has been stubbed in this version of the code : https://github.com/maniSbindra/hr-bot

Prerequisite steps to get the github sample running

  • Latest Node.js with NPM. Download it from here.
  • The Bot Framework Emulator. To install the Bot Framework Emulator, download it from here. Please refer to this documentation article to know more about the Bot Framework Emulator.
  • [Recommended] Visual Studio Code for IntelliSense and debugging, download it from here
  • Obtain Azure Subscription
  • Obtain QnA Maker Keys, and configure the keys as shown in the configuration section

Configuration

Following environment variables / application settings need to be configured :

  • MICROSOFT_APP_ID
  • MICROSOFT_APP_PASSWORD
  • QNA_KEY=
  • QNA_HOST=<the QNA Maker service host, e.g. : westus.api.cognitive.microsoft.com>
  • QNA_PATH=<the QNA Maker service path, e.g. : /qnamaker/v1.0/knowledgebases/……./generateAnswer >

Conclusion

During this technical engagement between KPIT and Microsoft we created a multichannel bot integrating with the KPIT Authentication API and KPIT HR System APIs. Following were the benefits :

  • Using the skype bot created authenticated users are able to perform tasks like getting pending approval requests, approving requests etc. This will enable KPIT users to perform these tasks through channels like skype even when they are on the go, thus enabling them to be more productive
  • Users can now find out about HR policies just by chatting with the HR-Bot, without needing to manually parse through the various FAQ documents

Next Steps :

  • KPIT team will enhance the QNA Maker Knowledge base to include more FAQ documents
  • HR-bot will be enhanced to include additional HR tasks.
  • KPIT team want to make the authentication seamless, i.e. they want to eliminate the need for the user to add the access code back into the chat window. They will need to make some changes to the authentication service and bot to achieve this.