Skip to content

karlmoll/symphony-api-client-java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

symphony-api-client-java

The Java client is built in an event handler architecture. If you are building a bot that listens to conversations, you will only have to implement an interface of a listener with the functions to handle all events that will come through the Data Feed.

Install using maven

    <dependency>
                <groupId>com.symphony.platformsolutions</groupId>
                <artifactId>symphony-api-client-java</artifactId>
                <version>1.0.7</version>
    </dependency>

Configuration

Create a config.json file in your project which includes the following properties

    {
      "sessionAuthHost": "COMPANYNAME-api.symphony.com",
      "sessionAuthPort": 8444,
      "keyAuthHost": "COMPANYNAME-api.symphony.com",
      "keyAuthPort": 8444,
      "podHost": "COMPANYNAME.symphony.com",
      "podPort": 443,
      "agentHost": "COMPANYNAME.symphony.com",
      "agentPort": 443,
      "botCertPath": "PATH",
      "botCertName": "BOT-CERT-NAME",
      "botCertPassword": "BOT-PASSWORD",
      "botEmailAddress": "BOT-EMAIL-ADDRESS",
      "appCertPath": "",
      "appCertName": "",
      "appCertPassword": "",
      "proxyURL": "",
      "proxyUsername": "",
      "proxyPassword": ""
    }

Example main class

public class BotExample {

    public static void main(String [] args) {
        BotExample app = new BotExample();
    }
    public BotExample() {
        URL url = getClass().getResource("config.json");
        SymConfigLoader configLoader = new SymConfigLoader();
        SymConfig config = configLoader.loadFromFile(url.getPath());
        SymBotAuth botAuth = new SymBotAuth(config);
        botAuth.authenticate();
        SymBotClient botClient = SymBotClient.initBot(config, botAuth);
        DatafeedEventsService datafeedEventsService = botClient.getDatafeedEventsService();
        RoomListener roomListenerTest = new RoomListenerTestImpl(botClient);
        datafeedEventsService.addRoomListener(roomListenerTest);
        IMListener imListener = new IMListenerImpl(botClient);
        datafeedEventsService.addIMListener(imListener);
    }
}

Example RoomListener implementation

public class RoomListenerTestImpl implements RoomListener {

    private SymBotClient botClient;

    public RoomListenerTestImpl(SymBotClient botClient) {
        this.botClient = botClient;
    }

    @Override
    public void onRoomMessage(InboundMessage message) {
        OutboundMessage messageOut = new OutboundMessage();
        messageOut.setMessage("<messageML>Hi "+message.getUser().getFirstName()+"!</messageML>");
        try {
            this.botClient.getMessagesClient().sendMessage(message.getStream().getStreamId(), messageOut);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onRoomCreated(RoomCreated roomCreated) {

    }

    @Override
    public void onRoomDeactivated(RoomDeactivated roomDeactivated) {

    }

    @Override
    public void onRoomMemberDemotedFromOwner(RoomMemberDemotedFromOwner roomMemberDemotedFromOwner) {

    }

    @Override
    public void onRoomMemberPromotedToOwner(RoomMemberPromotedToOwner roomMemberPromotedToOwner) {

    }

    @Override
    public void onRoomReactivated(Stream stream) {

    }

    @Override
    public void onRoomUpdated(RoomUpdated roomUpdated) {

    }

    @Override
    public void onUserJoinedRoom(UserJoinedRoom userJoinedRoom) {
        OutboundMessage messageOut = new OutboundMessage();
        messageOut.setMessage("<messageML>Welcome "+userJoinedRoom.getAffectedUser().getFirstName()+"!</messageML>");
        try {
            this.botClient.getMessagesClient().sendMessage(userJoinedRoom.getStream().getStreamId(), messageOut);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onUserLeftRoom(UserLeftRoom userLeftRoom) {

    }
}

About

symphony-api-client-java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%