如何将dialogflow与网站中的浮动聊天集成 [英] How to integrate dialogflow with floating chat in website

查看:73
本文介绍了如何将dialogflow与网站中的浮动聊天集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在网站内使用Dialogflow框架。我知道dialogflow是作为网站小部件提供网站集成的,但是我想在其中使用自定义设计的浮动聊天框。就像一个徘徊在页面一角的聊天框。我如何与这样的chatUI集成

I want to using Dialogflow framework within website . I know dialogflow offers the website integration as widget but.I want to use in it a custom designed floating chatbox in website.Like a chatbox which hovers in the corner of the page.How can i integrate with such chatUI

推荐答案

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

Yes, there is a way in dialogflow to do so. You will just have to create a simple chat window in html/angular or in any framework you want to design. You can just capture user-entered query & make an ajax call & pass it to dialogflow. Again that depends on the api version that you're using. Dialogflow offers you v1/v2 apis, which itself changes the request format. Please have a look at code below (used 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");
            }
        });
}

希望这可以回答您的查询。让我知道是否还有更多。

Hope this answers your query. Let me know if you have any more.

这篇关于如何将dialogflow与网站中的浮动聊天集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆