Coder Social home page Coder Social logo

symphony-java-sample-bots's Introduction

Symphony Java Sample Bots

NOTE! This repository have been archived; if you're looking for Symphony Java client samples, checkout https://github.com/symphonyoss/symphony-java-client/tree/master/examples


Build Status Open Issues Average time to resolve an issue License CII Best Practices Validation Status FOSSA Status

A series of sample Java bots that use the symphony-java-client (SJC) to interact with the Symphony platform. The main goal of this repository is to help developers moving their first steps with SJC, including the initial and minimum Maven project setup.

The code structure is intentionally kept simple, to improve code readability; no advanced use cases will be hosted in this project, since SJC already includes a long collection of examples

Below are listed the 4 sample bots currently hosted; 2 bots (HelloWorldBot and RssBot) run and terminate, while 2 others (EchoBot and StockInfoBot) run in background continuously and respond to messages under certain conditions.

Browse the code to check the differences.

  • Hello World Bot - org.symphonyoss.samples.HelloWorldBot; sends a hello world message to a given Symphony user (specified via receiver.email in symphony.properties) in a 1:1 chat, then terminates
  • Echo Bot - org.symphonyoss.samples.EchoBot; listens and posts back messages on 1:1 and group Symphony chats
  • Stock Info Bot - org.symphonyoss.samples.StockInfoBot; listens to 1:1 and group Symphony chats, checks messages for cashtags and posts related data extracted from Yahoo Finance API
  • RSS Bot - org.symphonyoss.samples.RssBot; fetches RSS feed data from given url (rss.url in symphony.properties) and sends some (rss.limit in symphony.properties) of them to a given Symphony user (user.email in symphony.properties) in a 1:1 chat.

Project setup

Follow these instructions to get started with this project and run your first java application using the Symphony Java client.

  1. Make sure Apache Maven 3.x is installed in your workstation; run which mvn on your console to check
  2. Clone this repo - git clone https://github.com/symphonyoss/symphony-java-sample-bots.git ; cd symphony-java-sample-bots
  3. Create a symphony.properties file in the project root - cp symphony.properties.sample symphony.properties
  4. Follow the instructions below to put the right configuration

Bot configuration

Open symphony.properties and edit the properties documented below.

Symphony API endpoints

sessionauth.url=https://foundation-dev-api.symphony.com/sessionauth
keyauth.url=https://foundation-dev-api.symphony.com/keyauth
pod.url=https://foundation-dev.symphony.com/pod
agent.url=https://foundation-dev.symphony.com/agent

The Symphony API endpoints, defaulting to the Foundation Developer Pod values; make sure that you have access to these endpoints, using curl or similar commands.

SSL endpoints truststore

truststore.file=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/security/cacerts
truststore.password=changeit

The certificate truststore to validate SSL certificates of the Symphony API endpoints; if the server is using certificates that are not included in the default JVM bundle, you can specify the location of a custom truststore to use.

Make sure to locate the cacert file of your JVM; in OSX, the command is $(/usr/libexec/java_home) /jre/lib/security/cacerts, check this article for other platforms.

Symphony service account

user.cert.file=./certs/bot.user.p12
user.cert.password=changeit
[email protected]

These properties identify the Symphony service account that will impersonate the bot; to authenticate, it needs a P12 certificate released by the Symphony pod administrator (and its related password).

If you don't have a Symphony pod, you can apply for a [14 day trial of the Foundation Developer Pod](symphony .foundation/odp).

To validate your p12 certificate, try openssl pkcs12 -info -in <file-name>.p12.

Running behind an HTTP proxy

The bot configuration allows to define a proxy.url parameter that will configure SJC accordingly; the code is part of Utils.java and relies on jersey-apache-connector-2.23.1 and javax.ws .rs-api-2.1 libraries, defined in pom.xml

Other bot configurations

Specifies the email of the Symphony user that should receive the message; it is only used by HelloWorldBot and RssBot.

rss.url=https://twitrss.me/twitter_user_to_rss/?user=symphonyoss
rss.limit=3

Specifies the source and limit of the RSS feed used by RssBot

Building the project

Simply type mvn package and a uberjar will be created in the ./target folder.

Running the Bots

Assuming the Maven is executed, you can run each sample bot using the following Java command:

export SYMPHONY_CONFIG_FILE=symphony.properties
java -Xmx1024m -classpath target/symphony-java-sample-bots-0.9.1-SNAPSHOT.jar org.symphonyoss.samples.HelloWorldBot

You can replace HelloWorldBot with the other samples mentioned before. For OSX/Linux users, a run-bot.sh is provided.

If you're running on Windows, you should use set instead of export.

If you're using Java 9 (check with java -version), please add --add-modules java.activation right after the java element in the commandline reported above.

Integration testing

This project ships with EchoBotIT, a simple example of integration testing using the Symphony Java client.

To configure it, you must create a symphony.properties.it configuration file (checkout symphony.properties.it .sample), which will be used to instanciate a second client that listens to the sender's messages.

Make sure that user.email in symphony.properties.it matches with sender.email defined in symphony.properties.

To run it, simply type:

export SYMPHONY_CONFIG_FILE=symphony.properties.it
mvn clean install -Pintegration-testing

Dependencies

This project uses the following libraries:

Contribute

Please read our Contribution guidelines and access our issue tracker on Github.

Project team

  • Maurizio (maoo) Pillitu - Devops Director at the Symphony Software Foundation ; Project leader, Administrator and main developer of the project
  • Frank (ftbb) Tarsillo - MD at IHS MarkIT ; Administrator and support developer of the project; he's also the Project leader of the Symphony Java Client

All Administrators can:

  • Access to the project build settings (on Travis CI)
  • Access SonarCloud, Coverity, WhiteSource (or any other reporting system) to manage authentication keys connected with CI build
  • Deploy artifacts (nightly build snapshots) on Sonatype and (releases on) Maven Central The OpenShift Online environment, used for Continuous Delivery (against the Symphony Foundation Developer pod), can is managed by the Foundation Infra team

Governance model

This project is largely self-governed; to know more, please read on https://symphonyoss.atlassian.net/wiki/display/FM/Project+Governance

symphony-java-sample-bots's People

Contributors

ftbb avatar maoo avatar pmonks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

symphony-java-sample-bots's Issues

Simplify command line execution of the sample bots

Currently the sample bots are invoked via a confusing mix of 3 scripts:

  1. run-bot.sh
  2. env.sh
  3. target/symphony-java-sample-bots-0.9.0-SNAPSHOT/bin/RunBot

There's also a run-it.sh script that further confuses newcomers (it has nothing to do with starting the bots, but newcomers don't know that and so go digging around in it to try to figure out what it's for).

Given that the primary goal of the sample bots is to provide a short and shallow on-ramp to Symphony bot development in Java, it's critical that all elements of these samples be distilled down to their absolute simplest, even where that would not be considered production-grade best practice.

These startup scripts (like the RunBot class itself - see issue #7) are nowhere near suitable for a newcomer to approach and digest without assistance, and therefore to meet this repository's overarching goal.

maven cannot access repository

Hi,

when I import this project I have trouble getting the artifactorg.symphonyoss:symphonyoss:pom:10-SNAPSHOT which is requested through the specified repository in the pom file

Project build error: Non-resolvable parent POM for symphony.bots.sample:symphony-java-sample-bots:0.9.1-SNAPSHOT: 
Failure to transfer org.symphonyoss:symphonyoss:pom:10-SNAPSHOT from http://maven-repository.<company>.net was cached in the local repository, resolution will not be reattempted until the update interval of <company>MavenRepository has elapsed or updates are forced. Original error: 
Could not transfer artifact org.symphonyoss:symphonyoss:pom:10-SNAPSHOT from/to <company>MavenRepository (http://maven-repository.<company>.net): 
Access denied to http://maven-repository.<company>.net/org/symphonyoss/symphonyoss/10-SNAPSHOT/symphonyoss-10-SNAPSHOT.pom. 
Error code 403, URLBlocked and 'parent.relativePath' points at wrong local POM

I am behind a proxy that (I think) blocks getting that artifact. Is there any way around it?

Also, I don't really understand why I need that artifact. Why isn't the dependency

<dependency>
         <groupId>org.symphonyoss.symphony</groupId>
         <artifactId>symphony-client</artifactId>
         <version>${symphony.java.client.version}</version>
 </dependency>

enough?

Help's highly appreciated!

Add NOTICE entries for category B licenses

The following items should be added to NOTICE file

CDDL 1.1: MIME streaming extension, javax.ws.rs-api

Eclipse Public License 1.0: JUnit

Similar to Apache License but with the acknowledgment clause removed: JDOM

The MIT License: Mockito, jsoup

CDDL: HK2 API module, HK2 Implementation Utilities, OSGi resource locator bundle - used by various API providers that rely on META-INF/services mechanism to locate providers., ServiceLocator Default Implementation, aopalliance version 1.0 repackaged as a module, javax.annotation API, javax.inject:1 as OSGi bundle

MPL 1.1: Javassist

CDDL: jersey-core-client, jersey-core-common, jersey-ext-entity-filtering, jersey-media-json-jackson, jersey-media-multipart, jersey-repackaged-guava

Check symphonyoss/symphony-java-client#29 for reference

Run bot from behind a proxy with auth

I am trying to run a bot from my company intranet which allows connection ONLY through proxy with authorization.

While the Sample bot seems to be taking into account the -Dhttps.proxyHost and -Dhttps.proxyPort it does not -Dhttps.proxyUser and -Dhttps.proxyPassword

Our proxy also rewrite https certs but I have the company cert trusted in the global keystore and mvn and other Java tools work just fine.

Dependency not resolvable

Following the instruction on README.md to build the repo

git clone https://github.com/symphonyoss/symphony-java-sample-bots.git
cd symphony-java-sample-bots
mvn clean package

Get the following error:

[ERROR] Failed to execute goal on project symphony-java-sample-bots: Could not resolve dependencies for project org.symphonyoss:symphony-java-sample-bots:jar:0.9.0-SNAPSHOT: Could not find artifact org.symphonyoss.symphony:symphony-client:jar:1.0.0-SNAPSHOT in sonatype-oss-public (https://oss.sonatype.org/content/groups/public/) -> [Help 1]

Missing PresenceListener on Symphony Java Client

Several tests are failing against the symphony-java-client version 1.0.2-SNAPSHOT:

[ERROR] /Users/m/w/projects/symphony-java-sample-bots/src/main/java/org/symphonyoss/examples/presenceservice/SymUserCache.java:[34,39] cannot find symbol
[ERROR]   symbol:   class PresenceListener
[ERROR]   location: package org.symphonyoss.client.services

The following examples have been commented out to avoid the build to fail, therefore they need to be reimplemented according to the changes applied to the Symphony Java Client:

  • src/main/java/org/symphonyoss/examples/hashtagbot/HashtagBot.java
  • src/main/java/org/symphonyoss/examples/presenceservice/PresenceServiceExample.java
  • src/main/java/org/symphonyoss/examples/presenceservice/SymUserCache.java
  • src/main/java/org/symphonyoss/examples/setpresence/SetPresenceExample.java

Rethink design of RunBot

Currently, RunBot uses reflection to start each bot, but this is non-intuitive for newcomers to Symphony and the symphony-java-client, and doesn't promote best practices in their own bots (reflection being generally considered bad practice in Java).

Startup scripts don't support proxies

To facilitate onboarding of new Symphony pod developers working in HTTP proxy environments (i.e. most firms), the env.sh script should include options for setting:

  • PROXY_HOST
  • PROXY_PORT
  • PROXY_USERNAME
  • PROXY_PASSWORD

The enhanced run-bot.sh script (see issue #17) should then include these options in the JVM's startup command line (i.e. via -Dhttp.proxyHost=${PROXY_HOST} -Dhttp.proxyPort=${PROXY_PORT} -Dhttp.proxyUser=${PROXY_USERNAME} -Dhttp.proxyPassword=${PROXY_PASSWORD}).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.