如何在网站中将 dialogflow 与浮动聊天集成

How to integrate dialogflow with floating chat in website

我想在网站中使用 Dialogflow 框架。我知道 dialogflow 提供网站集成作为小部件 but.I 想在其中使用自定义设计的浮动聊天框 website.Like 悬停在 page.How 角落的聊天框我可以与这样的 chatUI 集成吗

是的,dialogflow 中有一种方法可以做到这一点。您只需在 html/angular 或您想要设计的任何框架中创建一个简单的聊天 window。您可以只捕获用户输入的查询并进行 ajax 调用并将其传递给 dialogflow。同样,这取决于您使用的 api 版本。 Dialogflow 为您提供 v1/v2 apis,它本身会更改请求格式。请查看下面的代码(使用 v1 api):

function captureUserQuery() {
         var text = jQuery(".my-text").val();
         dialogflowApi(text);  
}

function dialogflowApi(text) {
         jQuery.ajax({
            type: "POST",
            url: "https://api.dialogflow.com/v1/query?v=20170712",
            contentType: "application/json; charset=utf-8",
            headers: {
                "Authorization": "Bearer " + access_token
            },
            data: JSON.stringify({
                query: text,
                lang: "en",
                sessionId: "chatbot"
            }),
            success: function(response) {
                console.log("success");
                // Here you will get the response to your query in json, you will have to parse it based on the type it has like text, image, card etc. & show it to user. 
                parseResponse(response); // function to parse your response. 
            },
            error: function() {
                console.log("Error");
            }
        });
}

希望这能回答您的问题。如果还有的话请告诉我。

您可以通过更新 dialogflow 提供的 iframe 标记来实现。您可以将任何 html 页面放在 iframe 标记内。你也可以添加一个浮动 button/icon 来激活它:

<iframe height="430" width="350" src="https://bot.dialogflow.com/kjhdfjhfjfh">

<your custom designed floating chatbox in website html>

</iframe>