Skip to content

Commit 11c93fe

Browse files
Integrated latest changes at 08-30-2025 1:30:16 PM
1 parent 21aca04 commit 11c93fe

File tree

30 files changed

+1057
-12
lines changed

30 files changed

+1057
-12
lines changed

ej2-javascript-toc.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,16 @@
519519
<ul>
520520
<li><a href="/ej2-javascript/chat-ui/es5-getting-started">Getting Started</a></li>
521521
<li><a href="/ej2-javascript/chat-ui/messages">Messages</a></li>
522+
<li>Chat Bot Integrations
523+
<ul>
524+
<li>
525+
<a href="/ej2-javascript/chat-ui/bot-integrations/integration-with-bot-dialogflow">Integration with Google Dialogflow</a>
526+
</li>
527+
<li>
528+
<a href="/ej2-javascript/chat-ui/bot-integrations/integration-with-bot-framework">Integration with Microsoft Bot Framework</a>
529+
</li>
530+
</ul>
531+
</li>
522532
<li><a href="/ej2-javascript/chat-ui/timebreak">Time break</a></li>
523533
<li><a href="/ej2-javascript/chat-ui/timestamp">Timestamp</a></li>
524534
<li><a href="/ej2-javascript/chat-ui/typing-indicator">Typing indicator</a></li>
@@ -937,6 +947,7 @@
937947
<li><a href="/ej2-javascript/dialog/how-to/display-a-dialog-with-custom-position">Display a Dialog with custom position</a></li>
938948
<li><a href="/ej2-javascript/dialog/how-to/prevent-closing-of-modal-dialog">Prevent closing of modal Dialog</a></li>
939949
<li><a href="/ej2-javascript/dialog/how-to/prevent-the-focus-on-the-first-element">Prevent the focus on the first element</a></li>
950+
<li><a href="/ej2-javascript/dialog/how-to/prevent-the-focus-to-the-previous-element">Prevent the focus to the previous element</a></li>
940951
<li><a href="/ej2-javascript/dialog/how-to/prevent-opening-of-the-dialog">Open a Dialog on condition</a></li>
941952
<li><a href="/ej2-javascript/dialog/how-to/read-all-the-values-from-dialog-on-button-click">Read All values of Dialog on button click</a></li>
942953
<li><a href="/ej2-javascript/dialog/how-to/customize-the-dialog-appearance">Customize the Dialog appearance</a></li>
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
---
2+
layout: post
3+
title: Dialogflow With ##Platform_Name## Chat UI control | Syncfusion
4+
description: Checkout and learn about Integration of Google Dialogflow With ##Platform_Name## Chat UI control of Syncfusion Essential JS 2 and more.
5+
platform: ej2-javascript
6+
control: Chat UI
7+
publishingplatform: ##Platform_Name##
8+
documentation: ug
9+
domainurl: ##DomainURL##
10+
---
11+
12+
# Integration of Google Dialogflow With ##Platform_Name## Chat UI control
13+
14+
The Syncfusion Chat UI supports integration with [Google Dialogflow](https://cloud.google.com/dialogflow/docs), enabling advanced conversational AI features in your applications.
15+
16+
## Getting Started With the ChatUI control
17+
18+
Before integrating Dialogflow, ensure that the Syncfusion Chat UI control is correctly rendered in your application:
19+
[ ##Platform_Name## Getting Started Guide](../getting-started)
20+
21+
## Prerequisites
22+
23+
* Google account to access `Dialogflow` and `Google Cloud Console`.
24+
* Backend requires `Node.js` (v16 or higher) and `npm`.
25+
* Syncfusion Chat UI for ##Platform_Name## `@syncfusion/ej2-interactive-chat` installed in your project.
26+
* Dialogflow Service Account with the `Dialogflow API Client` role and its JSON key file.
27+
28+
## Install Dependencies
29+
30+
* Install `backend` dependencies for Dialogflow and server setup:
31+
32+
```bash
33+
34+
npm install express body-parser dialogflow cors
35+
36+
```
37+
* Install the Syncfusion Chat UI in your project:
38+
39+
```bash
40+
41+
npm install @syncfusion/ej2-interactive-chat --save
42+
43+
```
44+
45+
## Set Up the Dialogflow Agent
46+
47+
1. In the Dialogflow console, create an [agent](https://cloud.google.com/agent-assist/docs), set a name (e.g., `MyChatBot`), and configure the default language (e.g., English - `en`).
48+
49+
2. Add intents with training phrases and responses (e.g., greetings, FAQs). Test using the Dialogflow simulator.
50+
51+
3. In the Google Cloud Console, go to `APIs & Services` > `Credentials`, create a Service Account with the Dialogflow API Client role, and download the JSON key file.
52+
53+
> `Security Note`: Never commit the JSON key file to version control. Use environment variables or a secret manager (e.g., Google Cloud Secret Manager) for production.
54+
55+
## Configure Node.js Backend
56+
57+
Create `backend/service-acct.json` with your Dialogflow service account credentials:
58+
59+
{% tabs %}
60+
{% highlight js tabtitle="service-acct.json" %}
61+
{
62+
"type": "service_account",
63+
"project_id": "your-dialogflow-project-id",
64+
"private_key_id": "abc123xyz...",
65+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEv...",
66+
"client_email": "dialogflow-agent@your-dialogflow-project-id.iam.gserviceaccount.com",
67+
...
68+
}
69+
{% endhighlight %}
70+
{% endtabs %}
71+
72+
Set up an Express server in `backend/index.js` to handle Dialogflow requests:
73+
74+
{% tabs %}
75+
{% highlight js tabtitle="index.js" %}
76+
77+
const express = require('express');
78+
const { SessionsClient } = require('dialogflow');
79+
const bodyParser = require('body-parser');
80+
const cors = require('cors');
81+
const serviceAccount = require('./service-acct.json');
82+
83+
const app = express();
84+
app.use(cors());
85+
app.use(bodyParser.json());
86+
87+
const projectId = serviceAccount.project_id;
88+
const sessionClient = new SessionsClient({ credentials: serviceAccount });
89+
90+
app.post('/api/message', async (req, res) => {
91+
const message = req.body.text;
92+
const sessionId = req.body.sessionId || 'default-session';
93+
94+
const sessionPath = `projects/${projectId}/agent/sessions/${sessionId}`;
95+
96+
const request = {
97+
session: sessionPath,
98+
queryInput: {
99+
text: {
100+
text: message,
101+
languageCode: 'en-US',
102+
},
103+
},
104+
};
105+
106+
try {
107+
const responses = await sessionClient.detectIntent(request);
108+
const result = responses[0].queryResult;
109+
res.json({ reply: result.fulfillmentText });
110+
} catch (err) {
111+
console.error('Dialogflow error:', err);
112+
res.status(500).json({ reply: "Error connecting to Dialogflow." });
113+
}
114+
});
115+
116+
app.listen(5000, () => console.log('Backend running on http://localhost:5000'));
117+
118+
{% endhighlight %}
119+
{% endtabs %}
120+
121+
> Use a unique `sessionId` (e.g., UUID) for each user to maintain conversation context.
122+
123+
## Integrate ChatUI in ##Platform_Name##
124+
125+
Use the Chat UI `messageSend` event to exchanges message. Each time a user sends a message, this event will be invoked with details of the sent message.
126+
127+
### Forward Message to backend:
128+
129+
Upon message submission, a POST request is sent to your backend API endpoint (`/api/message`). This backend service forwards the user’s message to Dialogflow and waits for a response.
130+
131+
### Displaying Bot response:
132+
133+
You can add the below respective files in your application:
134+
135+
{% if page.publishingplatform == "typescript" %}
136+
137+
{% tabs %}
138+
{% highlight ts tabtitle="index.ts" %}
139+
{% include code-snippet/chat-ui/dialogflow/index.ts %}
140+
{% endhighlight %}
141+
{% highlight html tabtitle="index.html" %}
142+
{% include code-snippet/chat-ui/dialogflow/index.html %}
143+
{% endhighlight %}
144+
{% endtabs %}
145+
146+
{% elsif page.publishingplatform == "javascript" %}
147+
148+
{% tabs %}
149+
{% highlight js tabtitle="index.js" %}
150+
{% include code-snippet/chat-ui/dialogflow/index.js %}
151+
{% endhighlight %}
152+
{% highlight html tabtitle="index.html" %}
153+
{% include code-snippet/chat-ui/dialogflow/index.html %}
154+
{% endhighlight %}
155+
{% endtabs %}
156+
157+
{% endif %}
158+
159+
## Run and Test
160+
161+
### Start the Backend server:
162+
163+
Navigate to your backend project folder and run the following command to start the Node.js server:
164+
165+
```bash
166+
167+
node index.js
168+
169+
```
170+
171+
### Start the ##Platform_Name## frontend:
172+
173+
In a separate terminal window, navigate to your project folder and start the development server:
174+
175+
```bash
176+
177+
npm start
178+
179+
```
180+
Open your app and chat with your Dialogflow-powered bot.
181+
182+
![ChatUI with Dialogflow](../images/dialogflow.png)
183+
184+
## Troubleshooting:
185+
186+
* `Permission Denied`: Ensure the service account has the `Dialogflow API Client` role in the Google Cloud Console.
187+
* `CORS Error`: Verify that the CORS origin in backend/index.js matches your frontend URL (e.g., http://localhost:3000).
188+
* `No Response`: Test intents in the Dialogflow Console simulator to ensure they are configured correctly.
189+
* `Quota Exceeded`: Check Dialogflow API quotas in the Google Cloud Console.
190+
* `Network Issues`: Confirm the backend server is running and the frontend is pointing to the correct URL (e.g., http://localhost:5000).
191+
* `Invalid Credentials`: Verify the service account JSON or environment variables are correctly configured.
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
---
2+
layout: post
3+
title: Microsoft Bot With ##Platform_Name## Chat UI component | Syncfusion
4+
description: Checkout and learn about Integration of Microsoft Bot Framework With ##Platform_Name## Chat UI component of Syncfusion Essential JS 2 and more details.
5+
platform: ej2-javascript
6+
control: Chat UI
7+
publishingplatform: ##Platform_Name##
8+
documentation: ug
9+
domainurl: ##DomainURL##
10+
---
11+
12+
# Integration of Microsoft Bot With ##Platform_Name## Chat UI control
13+
14+
The Syncfusion Chat UI supports integration with a Microsoft Bot Framework bot hosted on Azure, enabling a custom chat interface for seamless user interaction. The process involves setting up a secure backend token server, configuring the bot in Azure, and integrating the Syncfusion Chat UI in your application.
15+
16+
## Getting Started With the Chat UI control
17+
18+
Before integrating Microsoft Bot Framework, ensure that the Syncfusion Chat UI control is correctly rendered in your application:
19+
20+
[##Platform_Name## Getting Started Guide](../getting-started)
21+
22+
## Prerequisites
23+
24+
* `Microsoft Azure Account`: Required to create and host the bot.
25+
* `Node.js Environment`: The backend portion requires `Node.js` and `npm`.
26+
* `Syncfusion Chat UI`: Install @syncfusion/ej2-interactive-chat in your project.
27+
* `Deployed Azure Bot`: A bot should be created and published using the Bot Framework, which is accessible via an Azure App Service. Refer to Microsoft's Bot Creation Guide.
28+
29+
## Install Dependencies
30+
31+
* Install `frontend` dependencies for bot communication and the Syncfusion Chat UI:
32+
33+
* Install `directline-js` package to handle communication with the Bot Framework.
34+
35+
* Install `axios` for the HTTP requests.
36+
37+
```bash
38+
39+
npm install @syncfusion/ej2-interactive-chat --save
40+
npm install directline-js axios --save
41+
42+
```
43+
44+
* Install `backend` dependencies for the token server:
45+
46+
```bash
47+
48+
npm install express axios cors dotenv
49+
50+
```
51+
52+
## Configure the Azure Bot
53+
54+
1. In the [Azure Portal](https://portal.azure.com/#home), navigate to your bot resource.
55+
56+
2. Enable the Direct Line channel:
57+
* Go to `Channels` > `Direct Line` > `Default-Site`.
58+
* Copy one of the displayed secret keys.
59+
60+
3. Verify the Messaging endpoint in the Configuration section (e.g., https://your-bot-service.azurewebsites.net/api/messages).
61+
62+
> `Security Note`: Never expose the Direct Line secret key in frontend code. Use a backend token server to handle it securely.
63+
64+
## Set Up Token Server
65+
66+
Create a `token-server` folder with an `index.js` and a `.env` files.
67+
68+
{% tabs %}
69+
{% highlight js tabtitle=".env" %}
70+
DIRECT_LINE_SECRET=PASTE_YOUR_DIRECT_LINE_SECRET_HERE
71+
{% endhighlight %}
72+
{% endtabs %}
73+
74+
{% tabs %}
75+
{% highlight ts tabtitle="index.js" %}
76+
require('dotenv').config();
77+
const express = require('express');
78+
const axios = require('axios');
79+
const cors = require('cors');
80+
81+
const app = express();
82+
app.use(cors()); // Enable CORS for your frontend
83+
84+
const directLineSecret = process.env.DIRECT_LINE_SECRET;
85+
if (!directLineSecret) {
86+
throw new Error('Direct Line secret is not set in the .env file.');
87+
}
88+
89+
app.post('/directline/token', async (req, res) => {
90+
try {
91+
const response = await axios.post(
92+
'https://directline.botframework.com/v3/directline/tokens/generate',
93+
{}, // Request body can be empty
94+
{
95+
headers: {
96+
'Authorization': `Bearer ${directLineSecret}`
97+
}
98+
}
99+
);
100+
res.json({ token: response.data.token });
101+
} catch (err) {
102+
console.error('Error generating Direct Line token:', err.response ? err.response.data : err.message);
103+
res.status(500).json({ error: 'Failed to generate Direct Line token.' });
104+
}
105+
});
106+
107+
const port = process.env.PORT || 5000;
108+
app.listen(port, () => console.log(`Token server running on http://localhost:${port}`));
109+
{% endhighlight %}
110+
{% endtabs %}
111+
112+
## Integrate ChatUI in ##Platform_Name##
113+
114+
Add the below files in their respective files to connect the Syncfusion Chat UI to the bot via the Direct Line API:
115+
116+
{% if page.publishingplatform == "typescript" %}
117+
118+
{% tabs %}
119+
{% highlight ts tabtitle="index.ts" %}
120+
{% include code-snippet/chat-ui/bot-framework/index.ts %}
121+
{% endhighlight %}
122+
{% highlight html tabtitle="index.html" %}
123+
{% include code-snippet/chat-ui/bot-framework/index.html %}
124+
{% endhighlight %}
125+
{% endtabs %}
126+
127+
{% elsif page.publishingplatform == "javascript" %}
128+
129+
{% tabs %}
130+
{% highlight js tabtitle="index.js" %}
131+
{% include code-snippet/chat-ui/bot-framework/index.js %}
132+
{% endhighlight %}
133+
{% highlight html tabtitle="index.html" %}
134+
{% include code-snippet/chat-ui/bot-framework/index.html %}
135+
{% endhighlight %}
136+
{% endtabs %}
137+
138+
{% endif %}
139+
140+
## Run and Test
141+
142+
### Start the Token Server
143+
144+
Navigate to the `token-server` folder and run the following command to start the server:
145+
146+
```bash
147+
148+
node index.js
149+
150+
```
151+
152+
### Start the frontend
153+
154+
In a separate terminal window, navigate to your project folder and start the development server:
155+
156+
```bash
157+
158+
npm start
159+
160+
```
161+
Open `http://localhost:3000` to interact with your Microsoft Bot Framework chatbot.
162+
163+
## Troubleshooting
164+
165+
* `Token Server Error (500)`: Ensure the `DIRECT_LINE_SECRET` in the `.env` file is correct and that you have restarted the token server after changes.
166+
* `CORS Error`: Ensure the CORS configuration in `index.js` allows requests from your frontend URL (e.g., `http://localhost:3000`).
167+
* `Bot is Not Responding`:
168+
- Test the bot in the Azure Portal using the `Test in Web Chat` feature to ensure it's running correctly.
169+
- Check the bot's `Messaging endpoint` in the Configuration section and ensure it is correct and accessible.
170+
* `Connection Fails on Load`: Verify the token server is running and accessible from the browser. Check the console for network errors.
171+
* `Token Expiration`: Direct Line tokens are short-lived. The `directline-js` library typically handles token refresh automatically, but if issues persist, restart the Direct Line connection.
38.5 KB
Loading

0 commit comments

Comments
 (0)