Gawe bot Obrolan Sederhana ing SAP UI5

Pambuka

Chatbot minangka fungsi penting lan wis dadi bagean saka kabeh aplikasi ngarep saiki. Ing artikel iki, kita bakal Nggawe bot Obrolan Sederhana ing SAP UI5.

Apa Bot Chat?

Bot Chat minangka aplikasi sing bisa digunakake dening sapa wae karo sistem utawa komputer. Jawaban sing digawe dening komputer bisa hardcoded adhedhasar pitakonan utawa bisa nyata-wektu kui karo bantuan saka Artificial Intelligence.

Kepiye Cara Ngleksanakake Chatbot ing SAP UI5?

Ing artikel iki, kita bakal nggawe bot chatting sing prasaja ing ngendi jawaban kasebut hardcoded ing UI dhewe. Sampeyan bisa ngganti respon kasebut kanthi ngirim input menyang API lan nuduhake asil saka API minangka output.

Langkah-langkah kanggo Nggawe Bot Ngobrol Prasaja ing SAP UI5

Langkah-langkah kanggo Nggawe bot Obrolan Sederhana ing SAP UI5

Aliran Bot Chat

Aliran Bot Chat

Ndeleng.xml


 

Controller.js

sap.ui.define(["sap/ui/core/mvc/Controller", "sap/m/MessageBox", "sap/m/MessageToast", "sap/ui/model/json/JSONModel" ], fungsi ( Controller, MessageBox, MessageToast, JSONModel) {"nggunakake ketat";bali Controller.extend("Test.Test.controller.Main", { handleMessagePopoverPress: fungsi (oEvent) {// nggawe popover yen (!this._oPopover) {iki ._oPopover = sap.ui.xmlfragment("Test.Test.fragment.Bot", this);this.getView().addDependent(this._oPopover); } if (this._oPopover.isOpen()) {this._oPopover .close(); } else {this._oPopover.openBy(oEvent.getSource());}}, takon: function (oEvent) {var input = sap.ui.getCore().byId("query").getValue (); var fBox = new sap.m.FlexBox({alignItems: "Mulai", justifyContent: "End"}); var text = new sap.m.Text({text: input }); text.addStyleClass(" chat2"); fBox.addItem(text);fBox.addStyleClass("sapUiSmallMarginTop"); sap.ui.getCore().byId("chat").addItem(fBox); sap.ui.getCore().byId(). "query").setValue("");this.answer(input);}, answer: function (query) {var salam = ["hi", "halo", "apa kabar", "wassup"]; var greetings_response = ["Halo", "Sugeng tepang kaliyan panjenengan", "Hmm mm"]; var job = ["Apa sing bisa sampeyan lakoni kanggo aku?", "Apa sing bisa sampeyan lakoni kanggo aku", "Apa sing bisa sampeyan lakoni", "Apa sing bisa sampeyan lakoni?"]; yen (query) {yen (salam.indexOf(query.toLowerCase()) != -1) {var item = greetings_response[Math.floor(Math.random() * greetings_response.length)]; var a = this.createText(item); iki.reply(a); } else if (query.toLowerCase().match(/what.*you.*do/g)) {var a = this.createText("Apa sing arep tak lakoni?  XD"); var b = this.createButton("Tampilake Angket Sampeyan"); var c = this.createButton("Tampilake rincian pangguna"); var d = this.createButton("Delete users"); var e = this.createButton("Do something nakal");var vbox = new sap.m.VBox();vbox.addItem(a);vbox.addItem(b);vbox.addItem(c);vbox.addItem(d) ;vbox.addItem(e);this.reply(vbox); } else {this.reply();}}}, reply: function (ans) {if (ans) {var fBox = new sap.m.FlexBox( {alignItems: "Mulai", justifyContent: "Mulai"});ans.addStyleClass("chat1");ans.addStyleClass("sapUiSizeCompact");fBox.addItem(ans);fBox.addStyleClass("sapUiSmallMarginTop");sa .ui.getCore().byId("chat").addItem(fBox); } else {var fBox = new sap.m.FlexBox({alignItems: "Mulai", justifyContent: "Mulai"});var text = new sap.m.Text({ text: "Ora kenal sampeyan. 

 

Bot.fragment.xml


output

Bot Chat prasaja nggunakake SAP UI5

Pengarang


komentar

Ninggalake a Reply

Panjenengan alamat email ora bisa diterbitake. Perangkat kothak ditandhani *

Situs iki nggunakake Akismet kanggo ngurangi spam. Sinau babagan proses data sampeyan.