January 11, 2019 6 Comments

Dialogflow is a very robust platform for developing chatbots. One of the strongest reasons of using Dialogflow is its powerful Natural Language Understanding (NLU). You can build highly interactive chatbot as NLP of Dialogflow excels in intent classification and entity detection. It also offers integration with many chat platforms like Google Assistant, Facebook Messenger, Telegram, Viber, Kik, Line, etc. There is an option of web based integration too but the layout is not pretty attractive and also we can not display it on website as chat bubble straightaway. To use the bot in chat bubble we have to find some workaround.

Snatchbot is another chatbot development platform that supports multiple messaging channels like Facebook Messenger, Skype, Viber, Line, and many others. Also, it offers web based interface including chat bubble. The intuitive UI of snatchbot helps you build the flow of the chat conversation easily. Even if you are starting new, it won’t take much time to get familiarity with the tool and setup basic chatbot. Another nice feature of snatchbot is email notification for set events. We can send notification to email when user takes particular action or respond with some particular answer. Adding to the feature list, another good one is handoff conversation from bot to human agent. And all this is available at no cost. The free plan of snatchbot has sufficient to offer for a moderate level of chatbot. One lacking point is NLP. It does have Natural Language Processing (NLP) but that is not as powerful as Dialogflow.

We wanted to put a chat bubble on our site but Dialogflow didn’t offer it and Snatchbot was falling short in NLP. Hence, to make use of best of both the platforms, we decided to create integration bridge between Dialogflow and Snatchbot.

It is a Flask framework based script developed in Python. The integration script uses Dialogflow SDK and JSON API of Snatchbot. It accepts request from Snatchbot, passes on to Dialogflow, get response from Dialogflow and pass it back to Snatchbot with Snatchbot compatible JSON.

We have open sourced the integration script which can be found on our github repository. If you want to use it for your purpose, follow the below steps.

If you haven’t created a Dialogflow agent then first you need to create it (here is a detailed Dialogflow tutorial on how to develop Resume Chatbot) or if you already have one then let’s get started. 

Steps for integration

1. Download the script files from github repository and setup on your python hosting server or on your local system. You will need to install Flask if it’s not there already.

2. Get your Agent Project Id from Dialogflow console and enter it on line number 141 of app.py file. 

3. Download Service Account Credential file from GCP and save it in your project directory.

3. Enter the GCP Credential file path in the app.py file on line number 16.

4. If you have setup the script on server hosting then you will get a URL to access the app. Copy it, we’ll need it in later step.

5. If you are setting up the integrator in local system then you will need to connect it using ngrok.

               

6. Now, go to your snatchbot account and create a new bot or if you have already created a bot then select existing bot.

7. In the bot create new interaction of JSON API type.

8. In the JSON API interaction set the API Address of your app obtained in 4th/5th step. Also, set the Error Message so that if snatchbot is not able to connect to your API URL then it will display this error message.

9. You’re done! Now, when this JSON API interaction is called in your chat flow, it will make request to Dialogflow and fetch response from there. Dialogflow will respond with JSON compatible to snatchbot, so snatchbot will display the response to user.

Demo

You can click on the chat bubble on right side of the page. The chat bubble on our site is displayed using Snatchbot. And the conversation flow is setup using Dialogflow agent.

Do let us know if you face any issue in setting up or using the script. We would be happy to help! Contact us or post your query in the comment section.

You are welcome to connect via email (letstalk@pragnakalp.com) or skype (live:letstalk_86) for paid chatbot development work or integration of this script.

6 Comments

  • Pragnakalp Techlabs

    hi, i got error in running py file,

    C:\Users\kgullan\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/kgullan/Downloads/dialogflow-connector-for-snatchbot-using-python-master/app.py
    File “C:/Users/kgullan/Downloads/dialogflow-connector-for-snatchbot-using-python-master/app.py”, line 16
    os.environ[“GOOGLE_APPLICATION_CREDENTIALS”]=”C:\Users\kgullan\Downloads\dchatbot-fujmtd-687e090911b0.json”
    ^
    SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape

    Process finished with exit code 1
    ========================

    appreciate your feedback

    • Pragnakalp Techlabs

      Hello Mark,
      Instead of “C:\Users\kgullan\Downloads\dchatbot-fujmtd-687e090911b0.json”, you can try “C:\\Users\\kgullan\\Downloads\\dchatbot-fujmtd-687e090911b0.json”. It should work as in Windows path must be doubled slashed because it taskes the next character after backslash as a unicode character.

      Let us know if this fixes your problem.

    • Pragnakalp Techlabs

      Hi, Does it work for you ? Since November dont work this code.

      • Pragnakalp Techlabs

        Try passing the relative path like this os.environ[“GOOGLE_APPLICATION_CREDENTIALS”]=”./serviceAccountKey.json”.

  • Pragnakalp Techlabs

    Hi, We have been using your wonderful sewing for our page.
    Recently this year I started to get the following error:

    File “C:\Users\alejandro.avila\Anaconda3\lib\site-packages\grpc\_channel.py”, line 726, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
    grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.INVALID_ARGUMENT
    details = "Input text not set."
    debug_error_string = "{"created":"@1578929315.116000000","description":"Error received from peer ipv4:xxx.xxx.xxx.xxx","file":"src/core/lib/surface/call.cc","file_line":1056,"grpc_message":"Input text not set.","grpc_status":3}"

    google.api_core.exceptions.InvalidArgument: 400 Input text not set.

    I followed your steps but now i have this error.
    appreciate your help.

    • Pragnakalp Techlabs

      Seems like no input text is null at line number 27. Please check that the message on line number 148 is not null. Else you will get this error.

Write a comment

Your email address will not be published. Required fields are marked *

Want to talk to an Expert Developer?

Our experts in Generative AI, Python Programming, and Chatbot Development can help you build innovative solutions and scale your business faster.