symphonyoss / symphony-java-client

Java client library for Symphony
Apache License 2.0
34 stars 37 forks source link

Is StreamsClient.getStream(UserIDList) supposed to get or create a stream? #24

Closed shirleyshan closed 8 years ago

shirleyshan commented 8 years ago

what the StreamsClient.getStream(UserIDList) is supposed to do?

Based on the name, I thought it will get a stream based on the specified user ids. But the implementation actually tries to create a stream. Is this a bug or intended? If creation is intended, the name is very confusing.

ftbb commented 8 years ago

A little confusing…but getStream is identifying the stream between two or more users. There is no actual post of a message during this process.

In addition, I should really remove that method getStream(UserIdList) which is using an underlying model (UserIdList) from Symphony generated code. Instead use getStream(Set).

I would also suggest using “Services” vs calling out the underlying clients. ChatService, RoomService, PresenceService, ConnectionService should make your life easier…

Would also take a look at examples provided..

Frank

shirleyshan commented 8 years ago

I was using a RoomService, but I thought SymphonyClient.getStreamsClient() was the recommended way.

The reason is that I can't get a RoomService directly from SymphonyClient, instead I have to create a new RoomService on my own. This is not consistent with other service instantiations.

SymphonyClient exposes both getXXXClient and getXXXService methods. Thank you for pointing out that Service is the preferred way. Otherwise, I have no clues whether to use service or client.

ftbb commented 8 years ago

You are using an older version of the Symphony-java-client. Please upgrade to 0.9.1 released or 1.0.0-SNAPSHOT. You can retrieve roomservice from the client now.

The one enhancement I would like to introduce is the ability to create a Room object with a simple name and have the room service identify the stream automatically on joinRoom(Room).

Right now the deficiency is you still need to call streamsClient().createChatRoom(SymRoomAttributes) to create a stream that is attached to the Room before you add it to the service joinRoom(Room).

Alternatively you can RoomService.addRoom(Stream) which will return a Room object on the listener onNewRoom(Room).

You can raise an issue/enhancement on that...

shirleyshan commented 8 years ago

Going back to your answer on the method StreamsClient.getStream(UserIdList), quote, "... but getStream is identifying the stream between two or more users. There is no actual post of a message during this process.". But the source codes show that this method tries to create a stream not to identify a stream though. So it seems a bug to me. Please verify.

---------source code-------------
public Stream getStream(UserIdList userIdList) throws StreamsException { if (userIdList == null) { throw new NullPointerException("UsersIds were not provided..."); }

    StreamsApi streamsApi = new StreamsApi(apiClient);
    try {
        return **streamsApi.v1ImCreatePost**(userIdList, symAuth.getSessionToken().getToken());
    } catch (ApiException e) {
        throw new StreamsException("Failed to retrieve stream for given user ids...", e);
    }

}
ftbb commented 8 years ago

Thanks for your questions.

To be clear, the call will return the associated unique Stream for a given number of users. It is our assumption that the Symphony host system will lookup the stream if it already exists (historical) or create a new stream if it doesn't.

The important part is that the Stream is a unique identifier and the call has nothing to do with a posting of a message.

shirleyshan commented 8 years ago

Thank you for taking time to answer. I now understand that the streamApi.v1IMCreatePost actually does a lookup based on the userIdList first.

But I got an error response ({"code": 500, "message": "Failed to create IM session"}) from the API when there is an existing room created by the specified userId though. In theory, the API should return the existing rooms.

Do you know how I can initiate a request to ask someone to take a look at what happened on Symphony server?

ftbb commented 8 years ago

Strange..can you provide the version of Agent Server you are using?

Can you send over sample code?

I have tested without issue.... see below:

remoteUsers.add(symClient.getUsersClient().getUserFromEmail(System.getProperty("user.call.home")));
            logger.info("Reply1: {}", symClient.getStreamsClient().getStream(remoteUsers).getId());
            logger.info("Reply2: {}", symClient.getStreamsClient().getStream(remoteUsers).getId());
            logger.info("Reply3: {}", symClient.getStreamsClient().getStream(remoteUsers).getId());
            logger.info("Reply4: {}", symClient.getStreamsClient().getStream(remoteUsers).getId());```

Output:

2016-10-13 17:21:49 DEBUG StreamsClientImpl:104 - Stream ID for chat:  [frank.tarsillo@markit.com] :HWmEU5f4HItItegBaRtvK3___qpsjq_IdA 
2016-10-13 17:21:49 DEBUG StreamsClientImpl:104 - Stream ID for chat:  [frank.tarsillo@markit.com] :HWmEU5f4HItItegBaRtvK3___qpsjq_IdA 
2016-10-13 17:21:49 INFO  ChatExample:148 - Reply1: HWmEU5f4HItItegBaRtvK3___qpsjq_IdA
2016-10-13 17:21:49 DEBUG StreamsClientImpl:104 - Stream ID for chat:  [frank.tarsillo@markit.com] :HWmEU5f4HItItegBaRtvK3___qpsjq_IdA 
2016-10-13 17:21:49 INFO  ChatExample:149 - Reply2: HWmEU5f4HItItegBaRtvK3___qpsjq_IdA
2016-10-13 17:21:49 DEBUG StreamsClientImpl:104 - Stream ID for chat:  [frank.tarsillo@markit.com] :HWmEU5f4HItItegBaRtvK3___qpsjq_IdA 
2016-10-13 17:21:49 INFO  ChatExample:150 - Reply3: HWmEU5f4HItItegBaRtvK3___qpsjq_IdA
2016-10-13 17:21:49 DEBUG StreamsClientImpl:104 - Stream ID for chat:  [frank.tarsillo@markit.com] :HWmEU5f4HItItegBaRtvK3___qpsjq_IdA 
2016-10-13 17:21:49 INFO  ChatExample:151 - Reply4: HWmEU5f4HItItegBaRtvK3___qpsjq_IdA
shirleyshan commented 8 years ago

The agent server is 1.42.3

shirleyshan commented 8 years ago

It is an error on the Symphony server not on the java client side. Here is the request to trigger the 500 internal server error. curl -X POST -H "Content-Type: application/json" -H "sessionToken: 50fa35cfe61e1c94b03462bf138bee284984535181171c14e955bbbf182e560dd452f374b968110691dcf1a8a4538bd7de96777e0f72e6f6c09113f736f76ae1" -d '[346621040656406]' 'https://foundation-dev.symphony.com:443/pod/v1/im/create'

ftbb commented 8 years ago

Oh..great. Didn't know you were running on the Dev Pod..

I tested your code and user id with java-client 0.9.1. Please see below.

Can you make sure "assistantbot" is entitled for provisioning?

Can you also send me your code, so I can test it..


remoteUsers.add(symClient.getUsersClient().getUserFromId(new Long("346621040656406")));

        System.out.println(symClient.getStreamsClient().getStream(remoteUsers));
        System.out.println(symClient.getStreamsClient().getStream(remoteUsers));
        System.out.println(symClient.getStreamsClient().getStream(remoteUsers));

Output:

2016-10-14 15:31:03 DEBUG UsersClientImpl:78 - Found User: testbot@symphony.foundation:346621040656391
2016-10-14 15:31:03 DEBUG UsersClientImpl:107 - Found User: assistant-bot:346621040656406
2016-10-14 15:31:03 DEBUG StreamsClientImpl:104 - Stream ID for chat:  [assistantbot@symphony.foundation] :XcNTV4wArLZa-m41XoAyj3___qg7Utq3dA 
2016-10-14 15:31:03 DEBUG UsersClientImpl:107 - Found User: assistant-bot:346621040656406
2016-10-14 15:31:03 DEBUG StreamsClientImpl:104 - Stream ID for chat:  [assistantbot@symphony.foundation] :XcNTV4wArLZa-m41XoAyj3___qg7Utq3dA 
2016-10-14 15:31:03 DEBUG ChatService:142 - Adding new chat for user 346621040656406:assistantbot@symphony.foundation
2016-10-14 15:31:04 DEBUG StreamsClientImpl:104 - Stream ID for chat:  [assistantbot@symphony.foundation] :XcNTV4wArLZa-m41XoAyj3___qg7Utq3dA 
class Stream {
    id: XcNTV4wArLZa-m41XoAyj3___qg7Utq3dA
}
2016-10-14 15:31:04 DEBUG StreamsClientImpl:104 - Stream ID for chat:  [assistantbot@symphony.foundation] :XcNTV4wArLZa-m41XoAyj3___qg7Utq3dA 
class Stream {
    id: XcNTV4wArLZa-m41XoAyj3___qg7Utq3dA
}
2016-10-14 15:31:04 DEBUG StreamsClientImpl:104 - Stream ID for chat:  [assistantbot@symphony.foundation] :XcNTV4wArLZa-m41XoAyj3___qg7Utq3dA 
class Stream {
    id: XcNTV4wArLZa-m41XoAyj3___qg7Utq3dA
}
shirleyshan commented 8 years ago

Seemed that your app created a new chat. There are a couple of observations here then.

  1. Streams doesn't include room type. However, the API "/streams/list" supports four kinds of stream types though. "streamTypes": [ {"type": "IM"}, {"type": "MIM"}, {"type": "ROOM"}, {"type": "POST"}
  2. It seems that the account I use doesn't have the create IM entitlement. The the error message returned is not accurate. The error should not be a 500 error, it should be a Forbidden error.
ftbb commented 8 years ago

I would raise that one to Symphony API teams.

Entitlements should be set to something like the following...

Can have delegates
DISABLED Can edit profile picture
ENABLED Can create internal public rooms
ENABLED Can send files internally
ENABLED Can chat in external IM/MIMs
ENABLED