Closed salujamanish closed 3 years ago
@RezaJooyandeh could you please follow up?
@juancamilor and @angiurgiu do you mind looking into this issue?
@danielgerlag could you take a look with @angiurgiu 's help ? This is the current production sdk (not the one with WIP)
@salujamanish looking into it, will get back to you soon.
@salujamanish How did you create the communication users that you passed in the createChatThreadOptions
parameter?
The readme sample has hard coded users for examples... did you use your own CommunicationUser
instances?
Does this tutorial work for you? https://docs.microsoft.com/en-us/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-java
@salujamanish How did you create the communication users that you passed in the
createChatThreadOptions
parameter? The readme sample has hard coded users for examples... did you use your ownCommunicationUser
instances?Does this tutorial work for you? https://docs.microsoft.com/en-us/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-java
@danielgerlag below is the snippet of my code, I just followed the given documentation.
CommunicationUser user1 = new CommunicationUser("d1ab-1d3a0d00012d"); CommunicationUser user2 = new CommunicationUser("a1ab-1d3a0d00012c");
List<ChatThreadMember> members = new ArrayList<ChatThreadMember>();
ChatThreadMember firstThreadMember = new ChatThreadMember()
.setUser(user1)
.setDisplayName(" Name 1");
ChatThreadMember secondThreadMember = new ChatThreadMember()
.setUser(user2)
.setDisplayName(" Name 2");
members.add(firstThreadMember);
members.add(secondThreadMember);
CreateChatThreadOptions createChatThreadOptions = new CreateChatThreadOptions()
.setTopic("Topic")
.setMembers(members);
@salujamanish could you provide a little more context that precedes that snippet?
When you create the ChatClient
, are you using the token of user1
or the access token of your ACS resource in Azure?
How did you originally create user1
and user2
inside your ACS resource?
@salujamanish just following up, can you provide the additional details? or were you already able to resolve your issue?
@salujamanish just following up again.
I contacted @salujamanish directly and confirmed he was able to resolve his issue... this was not a bug.
@danielgerlag what is solution, since am also facing the same issue. @salujamanish can you post the fix the here ?
@skunchakuri the snippets were used out of context... please follow this tutorial for prerequisites and end to end instructions on setting up chat.
@danielgerlag @salujamanish i followed the same in provided resource. FYI we have tired in JAVA and React Js and Angular Js too. we blocked here, can anyone post the solution here.
@skunchakuri Did you create identities and access tokens for your chat users like this? https://docs.microsoft.com/en-us/azure/communication-services/quickstarts/access-tokens?pivots=programming-language-java
for chat users (connection userid) i have created a token.
On Mon, Feb 8, 2021 at 9:10 PM Daniel Gerlag notifications@github.com wrote:
@skunchakuri https://github.com/skunchakuri Did you create identities and access tokens for your chat users like this?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Azure/azure-sdk-for-java/issues/17951#issuecomment-775237363, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJEZMENYSTT33IDOUBC4NBLS6AAXVANCNFSM4ULTIEFA .
we were failing to get thread id, but we can create chat client.
What do you mean by connection userid
?
Did you assign the chat scope to the token?
@skunchakuri , for your user access token what is the scope you are setting ? Be sure to set the scope to "chat"
Thanks @salujamanish for reply. Yes am using scope as "chat " still facing error. here is my Java Code and Error stack. please provide me if reference code URL, it help us! /**
*/ package com.org.interviewly.acs;
import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.List;
import com.azure.communication.administration.CommunicationIdentityClient; import com.azure.communication.administration.CommunicationIdentityClientBuilder; import com.azure.communication.administration.CommunicationUserToken; import com.azure.communication.chat.ChatClient; import com.azure.communication.chat.ChatClientBuilder; import com.azure.communication.chat.ChatThreadClient; import com.azure.communication.chat.models.ChatThreadMember; import com.azure.communication.chat.models.CreateChatThreadOptions; import com.azure.communication.common.CommunicationUser; import com.azure.communication.common.CommunicationUserCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
/**
*/ public class InterviewlyACS {
/**
@param args */ public static void main(String[] args) {
System.out.println("Azure Communication Services - Chat Quickstart");
// Your unique Azure Communication service endpoint String endpoint = "https://interviewlycs.communication.azure.com";
// Create an HttpClient builder of your choice and customize it // Use com.azure.core.http.netty.NettyAsyncHttpClientBuilder if that suits your needs NettyAsyncHttpClientBuilder yourHttpClientBuilder = new NettyAsyncHttpClientBuilder(); HttpClient httpClient = yourHttpClientBuilder.build();
String connectionString = "endpoint=https://interviewlycs.communication.azure.com/;accesskey=cn8D9d/gCjctvkz1s2H21j28Z1b7CbMV5pSMSF/m6CMgXGPfNT3U9sfgioMVJFemYR2FJ666V51ytNa9AdKoeA=="; CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClientBuilder() .connectionString(connectionString) .httpClient(httpClient) .buildClient();
CommunicationUser identity = communicationIdentityClient.createUser(); System.out.println("\nCreated an identity with ID: " + identity.getId());
List
// User access token fetched from your trusted service String userAccessToken = token;
// Create a CommunicationUserCredential with the given access token, which is only valid until the token is valid CommunicationUserCredential userCredential = new CommunicationUserCredential(userAccessToken);
// Initialize the chat client final ChatClientBuilder builder = new ChatClientBuilder(); builder.endpoint(endpoint) .credential(userCredential) .httpClient(httpClient); ChatClient chatClient = builder.buildClient();
List
CommunicationUser user1 = new CommunicationUser("Jhon Kerry"); CommunicationUser user2 = new CommunicationUser("Chris Marc");
ChatThreadMember firstThreadMember = new ChatThreadMember() .setUser(user1) .setDisplayName("Member Display Name 1");
ChatThreadMember secondThreadMember = new ChatThreadMember() .setUser(user2) .setDisplayName("Member Display Name 2");
members.add(firstThreadMember); members.add(secondThreadMember);
CreateChatThreadOptions createChatThreadOptions = new CreateChatThreadOptions() .setTopic("Topic") .setMembers(members); ChatThreadClient chatThreadClient = chatClient.createChatThread(createChatThreadOptions); String chatThreadId = chatThreadClient.getChatThreadId(); System.out.println("chatThreadId" + chatThreadId);
chatThreadClient.listMessages().iterableByPage().forEach(resp -> { System.out.printf("Response headers are %s. Url %s and status code %d %n", resp.getHeaders(), resp.getRequest().getUrl(), resp.getStatusCode()); resp.getItems().forEach(message -> { System.out.printf("Message id is %s.", message.getId()); }); });
}
}
Error Stack Exception in thread "main" 19:28:42.328 [reactor-http-nio-1] DEBUG reactor.netty.resources.PooledConnectionProvider - [id: 0xe9f2dddd, L:/192.168.0.136:57996 - R:interviewlycs.communication.azure.com/13.107.213.58:443] Releasing channel 19:28:42.328 [reactor-http-nio-1] DEBUG reactor.netty.resources.PooledConnectionProvider - [id: 0xe9f2dddd, L:/192.168.0.136:57996 - R:interviewlycs.communication.azure.com/13.107.213.58:443] Channel cleaned, now 0 active connections and 1 inactive connections com.azure.communication.chat.models.ErrorException: Status code 400, "{"code":"BadRequest","message":"One or more validation errors occurred.","innerErrors":[{"message":"The value provided for Id is invalid.","target":"Members[0].Id"},{"message":"The value provided for Id is invalid.","target":"Members[1].Id"}]}" at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.azure.core.http.rest.RestProxy.instantiateUnexpectedException(RestProxy.java:334) at com.azure.core.http.rest.RestProxy.lambda$ensureExpectedStatus$5(RestProxy.java:375) at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:118) at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1592) at reactor.core.publisher.MonoProcessor.onNext(MonoProcessor.java:317) at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2148) at reactor.core.publisher.MonoProcessor.onSubscribe(MonoProcessor.java:325) at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:191) at reactor.core.publisher.MonoFlatMap.subscribeOrReturn(MonoFlatMap.java:53) at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:48)
please provide me if reference code URL, it help us!
Describe the bug I am following https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/communication/azure-communication-chat/src/samples/java/com/azure/communication/chat/ReadmeSamples.java to setup chat client for azure communication service using Java Sdk.
I am able to get valid user access token but when I am trying to create chat thread using
createChatThread() function
I am getting 401 exception
Exception or Stack Trace Exception in thread "main" com.azure.communication.chat.models.ErrorException: Status code 401, (empty body) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.azure.core.http.rest.RestProxy.instantiateUnexpectedException(RestProxy.java:334) at com.azure.core.http.rest.RestProxy.lambda$ensureExpectedStatus$8(RestProxy.java:395) at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44) at reactor.core.publisher.Mono.subscribe(Mono.java:4213) at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onComplete(FluxSwitchIfEmpty.java:75) at reactor.core.publisher.MonoFlatMap$FlatMapMain.onComplete(MonoFlatMap.java:174) at reactor.core.publisher.FluxDoFinally$DoFinallySubscriber.onComplete(FluxDoFinally.java:138) at reactor.core.publisher.FluxHandle$HandleSubscriber.onComplete(FluxHandle.java:206) at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onComplete(FluxMap.java:262) at reactor.core.publisher.FluxDoFinally$DoFinallySubscriber.onComplete(FluxDoFinally.java:138) at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:195) at reactor.core.publisher.FluxContextStart$ContextStartSubscriber.onNext(FluxContextStart.java:96) at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1782) at reactor.core.publisher.MonoCollectList$MonoCollectListSubscriber.onComplete(MonoCollectList.java:121) at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:252) at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:136) at reactor.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:374) at reactor.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:373) at reactor.netty.channel.ChannelOperations.terminate(ChannelOperations.java:429) at reactor.netty.http.client.HttpClientOperations.onInboundNext(HttpClientOperations.java:655) at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:96) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1526) at io.netty.handler.ssl.SslHandler.decodeNonJdkCompatible(SslHandler.java:1287) at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1324) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:501) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:440) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) at io.netty.channel.kqueue.AbstractKQueueStreamChannel$KQueueStreamUnsafe.readReady(AbstractKQueueStreamChannel.java:544) at io.netty.channel.kqueue.AbstractKQueueChannel$AbstractKQueueUnsafe.readReady(AbstractKQueueChannel.java:381) at io.netty.channel.kqueue.KQueueEventLoop.processReady(KQueueEventLoop.java:211) at io.netty.channel.kqueue.KQueueEventLoop.run(KQueueEventLoop.java:289) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748) Suppressed: java.lang.Exception: #block terminated with an error at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99) at reactor.core.publisher.Mono.block(Mono.java:1680) at com.azure.communication.chat.ChatClient.createChatThread(ChatClient.java:59) at App.createChatThread(App.java:87) at App.main(App.java:20)
To Reproduce Step 1: Generate user access token for Azure communication trusted service Step 2: Add main function in https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/communication/azure-communication-chat/src/samples/java/com/azure/communication/chat/ReadmeSamples.java Step 3: Update values of endpoint and token. Step 4: call createChatThread() function
Code Snippet ChatThreadClient chatThreadClient = chatClient.createChatThread(createChatThreadOptions);
Expected behavior Function should create a chat thread using the sync chat client.
Setup (please complete the following information):