public void constructWithValidId()
        {
            CommunicationUserIdentifier result = new CommunicationUserIdentifier(_id);

            Assert.NotNull(result.Id);
            Assert.NotNull(result.GetHashCode());
        }
        public void compareWithNonUserIdentifier()
        {
            CommunicationUserIdentifier identifier1 = new CommunicationUserIdentifier(_id);
            Object identifier2 = new Object();

            Assert.False(identifier1.Equals(identifier2));
        }
        public void compareEqualUserIdentifiers()
        {
            CommunicationUserIdentifier identifier1 = new CommunicationUserIdentifier(_id);
            CommunicationUserIdentifier identifier2 = new CommunicationUserIdentifier(_id);

            Assert.True(identifier1.Equals(identifier1));
            Assert.True(identifier1.Equals(identifier2));
        }
Beispiel #4
0
        public void DeserializeCommunicationUser()
        {
            CommunicationUserIdentifier identifier = (CommunicationUserIdentifier)CommunicationIdentifierSerializer.Deserialize(
                new CommunicationIdentifierModel(CommunicationIdentifierKind.CommunicationUser)
            {
                Id = "some id",
            });

            CommunicationUserIdentifier expectedIdentifier = new CommunicationUserIdentifier("some id");

            Assert.AreEqual(expectedIdentifier.Id, identifier.Id);
            Assert.AreEqual(expectedIdentifier, identifier);
        }
Beispiel #5
0
        public void DeserializeCommunicationUser()
        {
            CommunicationUserIdentifier identifier = (CommunicationUserIdentifier)CommunicationIdentifierSerializer.Deserialize(
                new CommunicationIdentifierModel
            {
                CommunicationUser = new CommunicationUserIdentifierModel(TestUserId),
                RawId             = TestRawId,
            });

            CommunicationUserIdentifier expectedIdentifier = new CommunicationUserIdentifier(TestUserId);

            Assert.AreEqual(expectedIdentifier.Id, identifier.Id);
            Assert.AreEqual(expectedIdentifier, identifier);
        }
        public async Task <IActionResult> User(InputMessage input)
        {
            User   user             = new User();
            string connectionString = Environment.GetEnvironmentVariable("COMMUNICATION_SERVICES_CONNECTION_STRING");
            var    client           = new CommunicationIdentityClient(connectionString);
            var    identity         = new Azure.Communication.CommunicationUserIdentifier(user.UserID);
            var    tokenResponse    = await client.GetTokenAsync(identity, scopes : new[] { CommunicationTokenScope.Chat });

            user.AccessToken = tokenResponse.Value.Token;
            Console.WriteLine(user.AccessToken);

            Uri endpoint = new Uri("https://haroldtest.communication.azure.com");
            CommunicationTokenCredential communicationTokenCredential = new CommunicationTokenCredential(user.AccessToken);
            ChatClient chatClient = new ChatClient(endpoint, communicationTokenCredential);

            Azure.Pageable <ChatThreadItem> threadItems = chatClient.GetChatThreads();
            List <ChatThreadClient>         ctclients   = new List <ChatThreadClient>();

            foreach (ChatThreadItem item in threadItems)
            {
                ChatThreadClient chatThreadClient = chatClient.GetChatThreadClient(item.Id);
                ctclients.Add(chatThreadClient);
            }

            SendChatMessageResult sendChatMessageResult = await ctclients[input.ThreadIndex].SendMessageAsync(content: input.Message, type: ChatMessageType.Text, senderDisplayName: user.Name);
            string messageId = sendChatMessageResult.Id;

            Console.WriteLine(messageId);

            foreach (ChatThreadItem item in threadItems)
            {
                ChatThreadClient             chatThreadClient = chatClient.GetChatThreadClient(item.Id);
                Azure.Pageable <ChatMessage> messages         = chatThreadClient.GetMessages();
                List <ChatMessage>           messageList      = new List <ChatMessage>();
                foreach (ChatMessage message in messages)
                {
                    messageList.Add(message);
                }
                ChatThread thread = new ChatThread(item.Id, item.Topic, messageList);
                user.Threads.Add(thread);
            }
            Console.WriteLine(user.Threads[0].Topic);
            Console.WriteLine(user.Threads[1].Topic);
            ViewBag.user = user;
            return(View());
        }
        public async Task <IActionResult> User()
        {
            User user = new User();
            async System.Threading.Tasks.Task UserThreads()
            {
                string connectionString = Environment.GetEnvironmentVariable("COMMUNICATION_SERVICES_CONNECTION_STRING");
                var    client           = new CommunicationIdentityClient(connectionString);
                //var identityResponse = await client.CreateUserAsync();
                //var identity = identityResponse.Value;
                //Console.WriteLine(identity);
                var identity      = new Azure.Communication.CommunicationUserIdentifier(user.UserID);
                var tokenResponse = await client.GetTokenAsync(identity, scopes : new[] { CommunicationTokenScope.Chat });

                user.AccessToken = tokenResponse.Value.Token;
                Console.WriteLine(user.AccessToken);

                Uri endpoint = new Uri("https://haroldtest.communication.azure.com");
                CommunicationTokenCredential communicationTokenCredential = new CommunicationTokenCredential(user.AccessToken);
                ChatClient chatClient = new ChatClient(endpoint, communicationTokenCredential);

                Azure.Pageable <ChatThreadItem> threadItems = chatClient.GetChatThreads();
                foreach (ChatThreadItem item in threadItems)
                {
                    ChatThreadClient             chatThreadClient = chatClient.GetChatThreadClient(item.Id);
                    Azure.Pageable <ChatMessage> messages         = chatThreadClient.GetMessages();
                    List <ChatMessage>           messageList      = new List <ChatMessage>();
                    foreach (ChatMessage message in messages)
                    {
                        messageList.Add(message);
                    }
                    ChatThread thread = new ChatThread(item.Id, item.Topic, messageList);
                    user.Threads.Add(thread);
                }
                Console.WriteLine(user.Threads[0].Topic);
                Console.WriteLine(user.Threads[1].Topic);
            }

            await UserThreads();

            Console.WriteLine(user.Threads[0].Topic);
            ViewBag.user = user;
            return(View());
        }