问题
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
回答1:
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.
回答2:
You can do so by updating the iframe tag provided by dialogflow. You can put any html page you want inside the iframe tag. Also you can add a floating button/icon to activate it:
<iframe height="430" width="350" src="https://bot.dialogflow.com/kjhdfjhfjfh">
<your custom designed floating chatbox in website html>
</iframe>
来源:https://stackoverflow.com/questions/49179584/how-to-integrate-dialogflow-with-floating-chat-in-website