Beispiel #1
0
    def update_topic(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationTokenCredential, CommunicationTokenRefreshOptions
        refresh_options = CommunicationTokenRefreshOptions(self.token)
        chat_thread_client = ChatThreadClient(self.endpoint, CommunicationTokenCredential(refresh_options), self._thread_id)
        # [START update_topic]
        topic = "updated thread topic"
        chat_thread_client.update_topic(topic=topic)
        # [END update_topic]

        print("update_chat_thread succeeded")
Beispiel #2
0
 def list_read_receipts(self):
     from azure.communication.chat import ChatThreadClient
     from azure.communication.chat import CommunicationUserCredential
     chat_thread_client = ChatThreadClient(
         self.endpoint, CommunicationUserCredential(self.token),
         self._thread_id)
     # [START list_read_receipts]
     read_receipts = chat_thread_client.list_read_receipts()
     print("list_read_receipts succeeded, receipts:")
     for read_receipt in read_receipts:
         print(read_receipt)
Beispiel #3
0
 def list_members(self):
     from azure.communication.chat import ChatThreadClient
     from azure.communication.chat import CommunicationUserCredential
     chat_thread_client = ChatThreadClient(
         self.endpoint, CommunicationUserCredential(self.token),
         self._thread_id)
     # [START list_members]
     chat_thread_members = chat_thread_client.list_members()
     print("list_chat_members succeeded, members: ")
     for chat_thread_member in chat_thread_members:
         print(chat_thread_member)
Beispiel #4
0
    def remove_participant(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationTokenCredential, CommunicationUserIdentifier, CommunicationTokenRefreshOptions
        refresh_options = CommunicationTokenRefreshOptions(self.token)
        chat_thread_client = ChatThreadClient(self.endpoint, CommunicationTokenCredential(refresh_options), self._thread_id)

        # [START remove_participant]
        chat_thread_client.remove_participant(self.new_user)
        # [END remove_participant]

        print("remove_chat_participant succeeded")
Beispiel #5
0
    def update_message(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationTokenCredential, CommunicationTokenRefreshOptions
        refresh_options = CommunicationTokenRefreshOptions(self.token)
        chat_thread_client = ChatThreadClient(self.endpoint, CommunicationTokenCredential(refresh_options), self._thread_id)
        # [START update_message]
        content = "updated content"
        chat_thread_client.update_message(self._message_id, content=content)
        # [END update_message]

        print("update_chat_message succeeded")
    def send_typing_notification(self):
        from azure.communication.chat import ChatThreadClient, CommunicationTokenCredential, CommunicationTokenRefreshOptions
        refresh_options = CommunicationTokenRefreshOptions(self.token)
        chat_thread_client = ChatThreadClient(
            self.endpoint, CommunicationTokenCredential(refresh_options),
            self._thread_id)
        # [START send_typing_notification]
        chat_thread_client.send_typing_notification()
        # [END send_typing_notification]

        print("send_typing_notification succeeded")
Beispiel #7
0
    def get_message(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationTokenCredential, CommunicationTokenRefreshOptions
        refresh_options = CommunicationTokenRefreshOptions(self.token)
        chat_thread_client = ChatThreadClient(self.endpoint, CommunicationTokenCredential(refresh_options), self._thread_id)
        # [START get_message]
        chat_message = chat_thread_client.get_message(self._message_id)
        # [END get_message]

        print("get_chat_message succeeded, message id:", chat_message.id, \
            "content: ", chat_message.content)
Beispiel #8
0
    def send_read_receipt(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationUserCredential
        chat_thread_client = ChatThreadClient(
            self.endpoint, CommunicationUserCredential(self.token),
            self._thread_id)
        # [START send_read_receipt]
        chat_thread_client.send_read_receipt(self._message_id)
        # [END send_read_receipt]

        print("send_read_receipt succeeded")
 def delete_message(self):
     from azure.communication.chat import ChatThreadClient
     from azure.communication.chat import CommunicationTokenCredential, CommunicationTokenRefreshOptions
     refresh_options = CommunicationTokenRefreshOptions(self.token)
     chat_thread_client = ChatThreadClient(
         self.endpoint, CommunicationTokenCredential(refresh_options),
         self._thread_id)
     # [START delete_message]
     chat_thread_client.delete_message(self._message_id)
     # [END delete_message]
     print("delete_chat_message succeeded")
 def list_members(self):
     from azure.communication.chat import ChatThreadClient
     from azure.communication.chat import CommunicationTokenCredential, CommunicationTokenRefreshOptions
     refresh_options = CommunicationTokenRefreshOptions(self.token)
     chat_thread_client = ChatThreadClient(
         self.endpoint, CommunicationTokenCredential(refresh_options),
         self._thread_id)
     # [START list_members]
     chat_thread_members = chat_thread_client.list_members()
     print("list_chat_members succeeded, members: ")
     for chat_thread_member in chat_thread_members:
         print(chat_thread_member)
Beispiel #11
0
    def remove_member(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationUserCredential, CommunicationUser
        chat_thread_client = ChatThreadClient(
            self.endpoint, CommunicationUserCredential(self.token),
            self._thread_id)

        # [START remove_member]
        chat_thread_client.remove_member(self.new_user)
        # [END remove_member]

        print("remove_chat_member succeeded")
Beispiel #12
0
    def update_thread(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationUserCredential
        chat_thread_client = ChatThreadClient(
            self.endpoint, CommunicationUserCredential(self.token),
            self._thread_id)
        # [START update_thread]
        topic = "updated thread topic"
        chat_thread_client.update_thread(topic=topic)
        # [END update_thread]

        print("update_chat_thread succeeded")
Beispiel #13
0
    def get_message(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationUserCredential
        chat_thread_client = ChatThreadClient(
            self.endpoint, CommunicationUserCredential(self.token),
            self._thread_id)
        # [START get_message]
        chat_message = chat_thread_client.get_message(self._message_id)
        # [END get_message]

        print("get_chat_message succeeded, message id:", chat_message.id, \
            "content: ", chat_message.content)
    def send_read_receipt(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationTokenCredential, CommunicationTokenRefreshOptions
        refresh_options = CommunicationTokenRefreshOptions(self.token)
        chat_thread_client = ChatThreadClient(
            self.endpoint, CommunicationTokenCredential(refresh_options),
            self._thread_id)
        # [START send_read_receipt]
        chat_thread_client.send_read_receipt(self._message_id)
        # [END send_read_receipt]

        print("send_read_receipt succeeded")
 def list_read_receipts(self):
     from azure.communication.chat import ChatThreadClient
     from azure.communication.chat import CommunicationTokenCredential, CommunicationTokenRefreshOptions
     refresh_options = CommunicationTokenRefreshOptions(self.token)
     chat_thread_client = ChatThreadClient(
         self.endpoint, CommunicationTokenCredential(refresh_options),
         self._thread_id)
     # [START list_read_receipts]
     read_receipts = chat_thread_client.list_read_receipts()
     print("list_read_receipts succeeded, receipts:")
     for read_receipt in read_receipts:
         print(read_receipt)
Beispiel #16
0
    def update_message(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationUserCredential
        chat_thread_client = ChatThreadClient(
            self.endpoint, CommunicationUserCredential(self.token),
            self._thread_id)
        # [START update_message]
        content = "updated content"
        chat_thread_client.update_message(self._message_id, content=content)
        # [END update_message]

        print("update_chat_message succeeded")
Beispiel #17
0
    def test_send_typing_notification(self):
        thread_id = "19:[email protected]"
        raised = False

        def mock_send(*_, **__):
            return mock_response(status_code=200)
        chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.credential, thread_id, transport=Mock(send=mock_send))

        try:
            chat_thread_client.send_typing_notification()
        except:
            raised = True

        self.assertFalse(raised, 'Expected is no excpetion raised')
    def test_list_participants_with_results_per_page(self):
        thread_id = "19:[email protected]"
        participant_id_1 = "8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-5399-552c-b274-5a3a0d0000dc"
        participant_id_2 = "8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-9d32-35c9-557d-5a3a0d0002f1"
        raised = False

        def mock_send(*_, **__):
            return mock_response(status_code=200,
                                 json_payload={
                                     "value": [{
                                         "communicationIdentifier": {
                                             "rawId": participant_id_1,
                                             "communicationUser": {
                                                 "id": participant_id_1
                                             }
                                         },
                                         "displayName":
                                         "Bob",
                                         "shareHistoryTime":
                                         "2020-10-30T10:50:50Z"
                                     }, {
                                         "communicationIdentifier": {
                                             "rawId": participant_id_2,
                                             "communicationUser": {
                                                 "id": participant_id_2
                                             }
                                         },
                                         "displayName":
                                         "Bob",
                                         "shareHistoryTime":
                                         "2020-10-30T10:50:50Z"
                                     }]
                                 })

        chat_thread_client = ChatThreadClient("https://endpoint",
                                              TestChatThreadClient.credential,
                                              thread_id,
                                              transport=Mock(send=mock_send))

        chat_thread_participants = None
        try:
            chat_thread_participants = chat_thread_client.list_participants(
                results_per_page=2)
        except:
            raised = True

        self.assertFalse(raised, 'Expected is no excpetion raised')
        for chat_thread_participant_page in chat_thread_participants.by_page():
            l = list(chat_thread_participant_page)
            assert len(l) == 2
Beispiel #19
0
    def list_messages(self):
        from azure.communication.chat import ChatThreadClient
        from azure.communication.chat import CommunicationTokenCredential, CommunicationTokenRefreshOptions
        refresh_options = CommunicationTokenRefreshOptions(self.token)
        chat_thread_client = ChatThreadClient(self.endpoint, CommunicationTokenCredential(refresh_options), self._thread_id)
        # [START list_messages]
        from datetime import datetime, timedelta
        start_time = datetime.utcnow() - timedelta(days=1)
        chat_messages = chat_thread_client.list_messages(results_per_page=1, start_time=start_time)

        print("list_messages succeeded with results_per_page is 1, and start time is yesterday UTC")
        for chat_message_page in chat_messages.by_page():
            l = list(chat_message_page)
            print("page size: ", len(l))
Beispiel #20
0
    def test_add_participants_w_failed_participants_returns_nonempty_list(
            self):
        thread_id = "19:[email protected]"
        new_participant_id = "8:acs:57b9bac9-df6c-4d39-a73b-26e944adf6ea_9b0110-08007f1041"
        raised = False
        error_message = "some error message"

        def mock_send(*_, **__):
            return mock_response(status_code=201,
                                 json_payload={
                                     "errors": {
                                         "invalidParticipants": [{
                                             "code": "string",
                                             "message": error_message,
                                             "target": new_participant_id,
                                             "details": []
                                         }]
                                     }
                                 })

        chat_thread_client = ChatThreadClient("https://endpoint",
                                              TestChatThreadClient.credential,
                                              thread_id,
                                              transport=Mock(send=mock_send))

        new_participant = ChatThreadParticipant(
            user=CommunicationUserIdentifier(new_participant_id),
            display_name='name',
            share_history_time=datetime.utcnow())
        participants = [new_participant]

        try:
            result = chat_thread_client.add_participants(participants)
        except:
            raised = True

        self.assertFalse(raised, 'Expected is no excpetion raised')
        self.assertTrue(len(result) == 1)

        failed_participant = result[0][0]
        communication_error = result[0][1]

        self.assertEqual(new_participant.user.identifier,
                         failed_participant.user.identifier)
        self.assertEqual(new_participant.display_name,
                         failed_participant.display_name)
        self.assertEqual(new_participant.share_history_time,
                         failed_participant.share_history_time)
        self.assertEqual(error_message, communication_error.message)
Beispiel #21
0
    def test_delete_message(self):
        thread_id = "19:[email protected]"
        message_id='1596823919339'
        raised = False

        def mock_send(*_, **__):
            return mock_response(status_code=204)
        chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.credential, thread_id, transport=Mock(send=mock_send))

        try:
            chat_thread_client.delete_message(message_id)
        except:
            raised = True

        self.assertFalse(raised, 'Expected is no excpetion raised')
Beispiel #22
0
    def test_remove_member(self):
        thread_id = "19:[email protected]"
        member_id="8:acs:57b9bac9-df6c-4d39-a73b-26e944adf6ea_9b0110-08007f1041"
        raised = False

        def mock_send(*_, **__):
            return mock_response(status_code=204)
        chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.credential, thread_id, transport=Mock(send=mock_send))

        try:
            chat_thread_client.remove_member(CommunicationUserIdentifier(member_id))
        except:
            raised = True

        self.assertFalse(raised, 'Expected is no excpetion raised')
Beispiel #23
0
    def test_send_message_w_type(self):
        thread_id = "19:[email protected]"
        message_id='1596823919339'
        raised = False
        message_str = "Hi I am Bob."

        chat_message_types = [ChatMessageType.TEXT, ChatMessageType.HTML, "text", "html"]

        for chat_message_type in chat_message_types:

            def mock_send(*_, **__):
                return mock_response(status_code=201, json_payload={
                    "id": message_id,
                    "type": chat_message_type,
                    "sequenceId": "3",
                    "version": message_id,
                    "content": {
                        "message": message_str,
                        "topic": "Lunch Chat thread",
                        "participants": [
                            {
                                "id": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_0e59221d-0c1d-46ae-9544-c963ce56c10b",
                                "displayName": "Bob",
                                "shareHistoryTime": "2020-10-30T10:50:50Z"
                            }
                        ],
                        "initiator": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_0e59221d-0c1d-46ae-9544-c963ce56c10b"
                    },
                    "senderDisplayName": "Bob",
                    "createdOn": "2021-01-27T01:37:33Z",
                    "senderId": "8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-e155-1f06-1db7-3a3a0d00004b"
                })

            chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.credential, thread_id,
                                                  transport=Mock(send=mock_send))

            try:
                content='hello world'
                sender_display_name='sender name'
                create_message_result_id = chat_thread_client.send_message(
                    content=content,
                    chat_message_type=chat_message_type,
                    sender_display_name=sender_display_name)
            except:
                raised = True

            self.assertFalse(raised, 'Expected is no excpetion raised')
            assert create_message_result_id == message_id
Beispiel #24
0
 def add_participant(self):
     from azure.communication.chat import ChatThreadClient, CommunicationTokenCredential, \
         CommunicationTokenRefreshOptions
     refresh_options = CommunicationTokenRefreshOptions(self.token)
     chat_thread_client = ChatThreadClient(self.endpoint, CommunicationTokenCredential(refresh_options),
                                           self._thread_id)
     # [START add_participant]
     from azure.communication.chat import ChatThreadParticipant
     from datetime import datetime
     new_chat_thread_participant = ChatThreadParticipant(
             user=self.new_user,
             display_name='name',
             share_history_time=datetime.utcnow())
     chat_thread_client.add_participant(new_chat_thread_participant)
     # [END add_participant]
     print("add_chat_participant succeeded")
Beispiel #25
0
    def add_members(self):
        from azure.communication.chat import ChatThreadClient, CommunicationUserCredential
        chat_thread_client = ChatThreadClient(
            self.endpoint, CommunicationUserCredential(self.token),
            self._thread_id)

        # [START add_members]
        from azure.communication.chat import ChatThreadMember
        from datetime import datetime
        new_member = ChatThreadMember(user=self.new_user,
                                      display_name='name',
                                      share_history_time=datetime.utcnow())
        thread_members = [new_member]
        chat_thread_client.add_members(thread_members)
        # [END add_members]
        print("add_chat_members succeeded")
Beispiel #26
0
    def test_get_message(self):
        thread_id = "19:[email protected]"
        message_id='1596823919339'
        raised = False

        def mock_send(*_, **__):
            return mock_response(status_code=200, json_payload={"id": message_id})
        chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.credential, thread_id, transport=Mock(send=mock_send))

        message = None
        try:
            message = chat_thread_client.get_message(message_id)
        except:
            raised = True

        self.assertFalse(raised, 'Expected is no excpetion raised')
        assert message.id == message_id
    def test_list_read_receipts_with_results_per_page(self):
        thread_id = "19:[email protected]"
        message_id_1 = "1596823919339"
        message_id_2 = "1596823919340"
        raised = False

        def mock_send(*_, **__):
            return mock_response(status_code=200,
                                 json_payload={
                                     "value": [{
                                         "chatMessageId": message_id_1,
                                         "senderCommunicationIdentifier": {
                                             "rawId": "string",
                                             "communicationUser": {
                                                 "id": "string"
                                             }
                                         }
                                     }, {
                                         "chatMessageId": message_id_2,
                                         "senderCommunicationIdentifier": {
                                             "rawId": "string",
                                             "communicationUser": {
                                                 "id": "string"
                                             }
                                         }
                                     }]
                                 })

        chat_thread_client = ChatThreadClient("https://endpoint",
                                              TestChatThreadClient.credential,
                                              thread_id,
                                              transport=Mock(send=mock_send))

        read_receipts = None
        try:
            read_receipts = chat_thread_client.list_read_receipts(
                results_per_page=2)
        except:
            raised = True

        self.assertFalse(raised, 'Expected is no excpetion raised')
        for read_receipt_page in read_receipts.by_page():
            l = list(read_receipt_page)
            assert len(l) == 2
Beispiel #28
0
    def test_list_read_receipts(self):
        thread_id = "19:[email protected]"
        message_id="1596823919339"
        raised = False

        def mock_send(*_, **__):
            return mock_response(status_code=200, json_payload={"value": [{"chatMessageId": message_id}]})
        chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.credential, thread_id, transport=Mock(send=mock_send))

        read_receipts = None
        try:
            read_receipts = chat_thread_client.list_read_receipts()
        except:
            raised = True

        self.assertFalse(raised, 'Expected is no excpetion raised')
        for read_receipt_page in read_receipts.by_page():
            l = list(read_receipt_page)
            assert len(l) == 1
Beispiel #29
0
    def test_add_participant(self):
        thread_id = "19:[email protected]"
        new_participant_id="8:acs:57b9bac9-df6c-4d39-a73b-26e944adf6ea_9b0110-08007f1041"
        raised = False

        def mock_send(*_, **__):
            return mock_response(status_code=201)
        chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.credential, thread_id, transport=Mock(send=mock_send))

        new_participant = ChatThreadParticipant(
                user=CommunicationUserIdentifier(new_participant_id),
                display_name='name',
                share_history_time=datetime.utcnow())

        try:
            chat_thread_client.add_participant(new_participant)
        except:
            raised = True

        self.assertFalse(raised, 'Expected is no excpetion raised')
Beispiel #30
0
    def test_list_members(self):
        thread_id = "19:[email protected]"
        member_id="8:acs:57b9bac9-df6c-4d39-a73b-26e944adf6ea_9b0110-08007f1041"
        raised = False

        def mock_send(*_, **__):
            return mock_response(status_code=200, json_payload={"value": [{"id": member_id}]})
        chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.credential, thread_id, transport=Mock(send=mock_send))

        chat_thread_members = None
        try:
            chat_thread_members = chat_thread_client.list_members()
        except:
            raised = True

        self.assertFalse(raised, 'Expected is no excpetion raised')
        for chat_thread_member_page in chat_thread_members.by_page():
            l = list(chat_thread_member_page)
            assert len(l) == 1
            l[0].user.id = member_id