Search code examples
dialogflow-esintegrationwebhookschatbotkommunicate

How to limit the number of chats received in chatbot Kommunicate


I have integrated Kommunicate chat bot into my website, however, a lot of traffic is generated on my website, due to which a lot more users are chatting than I have the bandwidth to support (agent wise). I can't seem to find a way to limit the number of currently active chats one agent/human can handle at any given time. I wish to find a solution for the same.

Can this be done through the webhook integration provided? If so, how?


Solution

  • The solution indeed lied in adding the webhook integration.

    First, I spin up a simple flask server, serving a single endpoint: /webhook.

    app = Flask(__name__)
    @app.route('/webhook', methods=['GET', 'POST'])
    def webhook():
        logger.debug('Webhook Triggered') #-> we know it's being trigerred.
        resp_generated = make_response(jsonify(results()))
        logger.debug(resp_generated)#-> always shows 200 anyway.
        return resp_generated
    
    if __name__ == '__main__':
      app.run(host ='0.0.0.0', port = 5000, debug = True)
    

    Then I use ngrok to create a tunnel to my local server (I plan to host it on GKE in the later stages)

    ngrok http 5000
    

    This gives me an HTTPS URL to my Flask server such as https:\\534bbe.ngrok.io

    Then I go into DialogFlow -> Fulfillment -> Enter my Webhooks endpoint there:

    enter image description here [Note: Hit the save button at the bottom of the page]

    You would have to enable webhook call for the Intents on which you are going to add your server logic, in my case it was when I wanted to transfer to a live agent while limiting the number of chats:

    enter image description here

    To ensure that the default behavior of Kommunicate is not broken when my server goes down, I have added custom payload (as shown in the image above):

    {
      "metadata": {
        "KM_ASSIGN_TO": ""
      },
      "platform": "kommunicate",
      "message": "---- Redact that sweet sweet company Information. Yeah!!---"
    }
    

    [Note: Make sure to hit Save on the top right, once you make your changes in the Intent.]

    Then I added the Webhook URL (same as the one used in DialogFlow) in Kommunicate -> Settings -> Developer -> Webhooks enter image description here [Note: Hit the save changes button at the bottom of the page]

    Once everything is set up, you will start receiving messages in the server and can add your logic as you wish. Do note that this is super tedious as you would have to read a lot of documentation and add a bunch of logic to get it to work as you want it to.