Skip to content

dialogflow_projeto_existente

Juliana Damasio Oliveira edited this page May 19, 2021 · 3 revisions

Including the integration in your JaCaMo project

If you don't already have one, create a lib folder at the root of your project.

Download this file Models.jar and save it in the folder lib.

Right-click on the file and select Build Path/Add to Build Path.

Create a new file at the root of the project called build.gradle

and add the following code to this file:

plugins {
    id 'java'
    id 'eclipse'
}

repositories {
    mavenCentral()

    maven { url "http://jacamo.sourceforge.net/maven2" }
    maven { url "https://repo.gradle.org/gradle/libs-releases-local" }
    maven { url "https://jitpack.io" }
    
    flatDir {
       dirs 'lib'
    }
}

dependencies {
	compile group: 'org.jacamo' , name: 'jacamo'   , version: '0.9-SNAPSHOT'  , changing: true , transitive: true

	compile 'org.jason-lang:jason:2.5-SNAPSHOT'
	compile 'javax.xml.bind:jaxb-api:+'
	
		
	compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.29.1'
	compile 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.29.1'
	compile 'org.glassfish.jersey.inject:jersey-hk2:2.29.1'
	compile group: 'org.glassfish.jersey', name: 'jersey-bom', version: '2.29.1', ext: 'pom'

	compile 'org.glassfish.jersey.core:jersey-server:2.29.1'
	compile 'org.glassfish.jersey.core:jersey-client:2.29.1'
	compile 'org.glassfish.jersey.media:jersey-media-multipart:2.29.1'

	compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.29.1'

	// containers:
	compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.29.1'
	compile 'org.glassfish.grizzly:grizzly-http-server:2.4.4'
	
	compile 'org.apache.zookeeper:zookeeper:3.5.4-beta'
	compile 'org.apache.curator:curator-framework:4.0.1'
	compile 'org.apache.curator:curator-x-async:4.0.1'
	

	compile 'com.google.code.gson:gson:2.8.5'
	
	implementation 'com.github.eishub:eis:v0.6.2'
	
	implementation files('lib/Models.jar')
		
}

task run (type: JavaExec, dependsOn: 'classes') {
    description 'runs the application'
    group ' JaCaMo'
    main = 'jacamo.infra.JaCaMoLauncher'
    args '<yourJcmFile>.jcm'
    classpath sourceSets.main.runtimeClasspath
}

sourceSets {
    main {
        java {
            srcDir 'env'
            srcDir 'agt'
        }
    }
}

Replace <yourJcmFile>.jcm by the name of your file .jcm.
Now, right-click on the project and select Configure / Add Gradle Nature so that the eclipse understands that it needs to import the Gradle classes. It may take some time to synchronize.

In env create a new package with the name br.pucrs.smart

Download the following classes and place them in the newly created package:

Instead of downloading one class at a time, you can download all the classes mentioned below compressed in this file classes.zip and unzip it to get the classes by transferring them to the folder br/pucrs/smart

Create in env a new package with the name br.pucrs.smart.interfaces, download the following class, and place it inside it.

Create a Jason agent to communicate with Dialogflow and put the following code in it:

+request(Req)
	:true
<-
	.print("Request received ",Req," from dialog");
	!responder(Req);
	.
	
+!responder(Req)
	: (Req == "Call Jason Agent")
<-
	reply("Hello, I am your agent Jason, can I help you?");
	.
+!responder(Req)
	: true
<-
	reply("Sorry, I do not recognize this intention");
	.
	
+!hello
    : True
<-
    .print("hello world");
    .

{ include("$jacamoJar/templates/common-cartago.asl") }
{ include("$jacamoJar/templates/common-moise.asl") }

Include your new agent, communication artifact, and server in your file .jcm

ex.

  agent communicating_agent:communicating_agent.asl{
    focus: integration
  }
    
	workspace wp{
		artifact integration:br.pucrs.smart.IntegrationArtifact
	}
	
	platform: br.pucrs.smart.RestArtifact("--main 2181 --restPort 8080")

To run the project, open the project folder in the terminal and type the command gradle build (this may take some time) then run the command gradle run.

If you want to create Docker images from that application, create a new file at the root of the project called Dockerfile and put the following code in it.
The process for creating the image is the same as in Creating Docker image

FROM alpine

ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
ENV JACAMO_HOME=/jacamo/build
ENV PATH $PATH:$JAVA_HOME/bin #:$JACAMO_HOME/scripts

RUN apk add --update --no-cache git gradle openjdk8-jre bash fontconfig ttf-dejavu graphviz
RUN git clone https://github.com/jacamo-lang/jacamo.git && \
    cd jacamo && \
    gradle config

COPY . /app

RUN cd app && gradle build

EXPOSE 3271
EXPOSE 3272
EXPOSE 3273
EXPOSE 8080

WORKDIR /app


ENTRYPOINT [ "gradle", "run" ]

CMD []