This guide provides detailed information for beginners who want to bootstrap their first Symphony BDK project in Java. Two different approaches will be detailed here:
- using the Symphony Generator
- from scratch
This section requires
npm(Node Package Manager) to be installed on your local machine as a prerequisite
For all Symphony BDK applications, you should start with the Symphony Generator. The Symphony Generator offers a fast way to bootstrap your Symphony BDK project in several languages, including Java:
npm i -g generator-symphony
yo symphony 2.0
This section will help you to understand how to create your bot application from scratch.
If you want to use Maven as build system, you have to configure your root pom.xml as such:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>symphony-bdk</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>symphony-bdk</name>
<description>Demo project for Symphony BDK</description>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.symphony.platformsolutions</groupId>
<artifactId>symphony-bdk-bom</artifactId>
<version>1.2.1.BETA</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Core dependencies -->
<dependency>
<groupId>com.symphony.platformsolutions</groupId>
<artifactId>symphony-bdk-core</artifactId>
</dependency>
<dependency>
<groupId>com.symphony.platformsolutions</groupId>
<artifactId>symphony-bdk-core-invoker-jersey2</artifactId>
</dependency>
<dependency>
<groupId>com.symphony.platformsolutions</groupId>
<artifactId>symphony-bdk-template-freemarker</artifactId>
</dependency>
<!-- Logger implementation -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
</project>If you want to use Gradle as build system, you have to configure your root build.gradle as such:
plugins {
id 'java-library'
}
group = 'com.example'
version = '1.0.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
// import a BOM
implementation platform('com.symphony.platformsolutions:symphony-bdk-bom:1.2.1.BETA')
// define dependencies without versions
implementation 'com.symphony.platformsolutions:symphony-bdk-core'
implementation 'com.symphony.platformsolutions:symphony-bdk-core-invoker-jersey2'
implementation 'com.symphony.platformsolutions:symphony-bdk-template-freemarker'
implementation 'ch.qos.logback:logback-classic'
}Before implementing any code, you need to create your src/main/resources/config.yaml configuration file according
to your Symphony environment:
host: acme.symphony.com # your own pod host name
bot:
username: bot-username # your bot (or service account) username
privateKeyPath: /path/to/bot/rsa-private-key.pem # your bot RSA private keyClick here for more detailed documentation about BDK configuration
Now you can create a Simple Bot Application by creating main class src/main/java/com/example/symphony/BotApplication.java:
public class BotApplication {
public static void main(String[] args) {
final SymphonyBdk bdk = new SymphonyBdk(BdkConfigLoader.loadFromClasspath("/config.yaml")); // (1)
bdk.datafeed().subscribe(new RealTimeEventListener() { // (2)
@Override
public void onMessageSent(V4Initiator initiator, V4MessageSent event) {
bdk.messages().send(event.getMessage().getStream(), "<messageML>Hello, World!</messageML>"); // (3)
}
});
bdk.datafeed().start(); // (4)
}
}- The
SymphonyBdkclass acts as an entry point into the library and provides a fluent API to access to the main BDK features such as Datafeed, services or Activities - Subscribe to the
onMessageSentReal Time Event - When any message is sent into a stream where your bot is a member, it will reply by message
Hello, World! - Start the Datafeed read loop