Closed skunchakuri closed 3 years ago
@salujamanish even i tried with Java Script still facing below issue. we have tried will all scopes voip, chat and data is not at all accepting. we have blocked here appreciated quick help!
@anuchandy could you please help route this
Looking at the tutorials it seems API requires a communication identifier to add the participants, example here: https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/communication/azure-communication-chat#chat-thread-operations
But I would let @danielgerlag, @juancamilor confirm.
@skunchakuri the members (participants) on the chathread need to be valid users. For instance, try
CommunicationUser user1= communicationIdentityClient.createUser() instead of
CommunicationUser user1 = new CommunicationUser("Jhon Kerry")
Also, I recommend you use the GA version of the library. Please let us know if this does not solve your problem. Cheers, Camilo!
FYI @angiurgiu
@juancamilor tried with CommunicationUser user1= communicationIdentityClient.createUser() but its giving different error. can you please look into it!.
Exception in thread "main" com.azure.communication.chat.models.ErrorException: Status code 400, "{ "Code": "BadRequest", "Message": "Initiator is not a participant of the thread", "InnerErrors": [] }"
Hi @skunchakuri, I think the issue is that you are using an old version of the library which requires the thread creator to be among the list of members that you pass in .setMembers(members)
If you use the GA version of the lib, the request initiator should be added for you to the thread without you explicitly adding them to members.
In your case the initiator is this user you create in the beginning:
CommunicationUser identity = communicationIdentityClient.createUser(); System.out.println("\nCreated an identity with ID: " + identity.getId()); ...... CommunicationUserCredential userCredential = new CommunicationUserCredential(userAccessToken);
// Initialize the chat client final ChatClientBuilder builder = new ChatClientBuilder(); builder.endpoint(endpoint) .credential(userCredential) <---- your request initiator, which also needs to be a part of the thread .httpClient(httpClient);
Thanks @salujamanish for reply. Yes am using scope as "chat " still facing error. here is my Java Code and Error stack.
/**
*/ 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 = "redacted"; CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClientBuilder() .connectionString(connectionString) .httpClient(httpClient) .buildClient();
CommunicationUser identity = communicationIdentityClient.createUser(); System.out.println("\nCreated an identity with ID: " + identity.getId());
List scopes = new ArrayList<>(Arrays.asList("chat"));
CommunicationUserToken response = communicationIdentityClient.issueToken(identity, scopes);
OffsetDateTime expiresOn = response.getExpiresOn();
String token = response.getToken();
System.out.println("\nIssued an access token with 'chat' scope that expires at: " + expiresOn + ": " + token);
// 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 members = new ArrayList();
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)