Connecting Dialogflow to JAICF project
The platform makes it easy to integrate a conversational user interface into your mobile app, web application, device, and so on. In this article, we are looking at connecting Telegram for a JAICF project using Dialogflow.
To connect the Dialogflow channel to the JAICF project, please follow these steps:
Prepare the project
Before connecting a channel, prepare the JAICF project in advance:
- Specify the following in the dependencies of
build.gradle.kts
file:
dependencies {
// ...
implementation("com.just-ai.jaicf:jaicp:$jaicfVersion")
implementation("com.just-ai.jaicf:google-actions:$jaicfVersion")
}
$jaicfVersion
with the latest framework version.- Configure depending on the connection method to the platform:
-
long polling
— the bot will connect to the Just AI server when interacting with the platform. Simple solution, convenient for local development, and debugging.For this method, specify
ActionsFulfillmentDialogflow()
in theJaicpPoller.kt
file:
package com.just-ai.jaicf.template.connections
fun main() {
JaicpPollingConnector(
templateBot,
accessToken,
channels = listOf(
ChatApiChannel,
ChatWidgetChannel,
TelephonyChannel,
ActionsFulfillmentDialogflow()
)
).runBlocking()
}
-
webhook
— the bot will receive messages from the platform using the specified link. Must be configured to connect JAICP Cloud.For this method, specify
ActionsFulfillmentDialogflow()
in theJaicpServer.kt
file:
package com.just-ai.jaicf.template.connections
fun main() {
JaicpServer(
botApi = templateBot,
accessToken = accessToken,
channels = listOf(
ChatApiChannel,
ChatWidgetChannel,
TelephonyChannel,
ActionsFulfillmentDialogflow()
)
).start(wait = true)
}
Create a channel
Open the JAICF project on JAICP. Go to the Channels tab on the side panel, then click Inbound → Connect channel. In the Voice Assistants section, choose Dialogflow. Specify the channel name and click Create.
Click Get webhook under the name of the newly created channel. It will be copied to the clipboard. The copied webhook will be needed later when configuring the skill.
Configure the Dialogflow
Create an agent
Log in to Dialogflow CX Console. First, you need to register and create a new agent, click Create new agent.
Fill in the following fields:
- Agent name — specify your agent name.
- DEFAULT LANGUAGE — the default language supported by your agent. You can add additional languages after creating your agent.
- DEFAULT TIME ZONE — the default time zone for your agent.
Click Create.
Create intents
In order for the agent to start processing requests, you need to add intents. Intent is the key unit of the Dialogflow service, which combines a set of phrases, customer intent and other meta information.
There are two default intents added in the agent:
Default Welcome Intent
— greeting and start of the dialog;Default Fallback Intent
— activated if none of the other intents match.
Click Intents on the side menu. Since we have a welcome intent by default, let’s add a goodbye intent. To do this, fill in the fields:
- Intent name — specify
Bye
here. - In the Training phrases section specify
Bye
andGoodbye
. - In the Fulfillment section activate the switches Enable webhook call for this intent and Enable webhook call for slot filling.
Then click Save. Following the sample add all the necessary intents for your script.
Intents in the JAICF project script
Please note that names of the intents in Dialogflow and in the scripts of the JAICF project must match:
state("bye") {
activators {
intent("<Dialogflow intents name>")
}
action {
reactions.sayRandom(
"Dialogflow intents name"
)
reactions.image("https://media.giphy.com/media/EE185t7OeMbTy/source.gif")
}
}
Fulfillment
In the Dialogflow Console on the left panel, click Fulfillment. Here, in the Webhook section, insert the webhook that was created earlier when creating the channel on JAICP. Save your changes.
Next, click Integrations on the left panel, here activate the integration with Telegram.
Testing
In a few seconds, you can test how your skill works. To do this, after completing the training, click Try it now in the right panel of the Dialogflow console. Enter in the field one of the activation phrases that you specified when creating the skill.