Skip to content

Channels Service

Channels in team management.

teams_lib_pzsp2_z1.services.channels.ChannelsService

Bases: BaseService

Service for managing Microsoft Teams channels via the Go backend.

This class acts as a high-level Python wrapper. It delegates logical operations to the underlying Go library through the self.client.execute bridge.

Architecture & Caching: The decision to use caching or direct API calls is handled internally by the compiled Go library, based on the configuration provided during Client initialization. This Python class provides a unified interface regardless of the underlying mode.

Concepts: * References: Arguments like team_ref or channel_ref accept either UUIDs or Display Names. The Go backend resolves these automatically. * Identity: Users are identified by UUID or Email.

Source code in teams_lib_pzsp2_z1/services/channels.py
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
class ChannelsService(BaseService):
    """Service for managing Microsoft Teams channels via the Go backend.

    This class acts as a high-level Python wrapper. It delegates logical operations
    to the underlying Go library through the `self.client.execute` bridge.

    **Architecture & Caching:**
    The decision to use caching or direct API calls is handled internally by the
    compiled Go library, based on the configuration provided during Client initialization.
    This Python class provides a unified interface regardless of the underlying mode.

    **Concepts:**
    * **References**: Arguments like `team_ref` or `channel_ref` accept either UUIDs
        or Display Names. The Go backend resolves these automatically.
    * **Identity**: Users are identified by UUID or Email.
    """

    def list_channels(self, team_ref: str) -> list[Channel]:
        """Retrieves all channels associated with a specific team.

        Args:
            team_ref (str): The reference to the team (UUID or Display Name).
        Returns:
            List[Channel]: A list of channel objects found in the team.
        """
        response = self.client.execute(
            cmd_type="request",
            method="listChannels",
            params={
                "teamRef": team_ref,
            },
        )
        return [
            Channel(
                id=channel["ID"],
                name=channel["Name"],
                is_general=(True if channel["IsGeneral"] else False),
            )
            for channel in response
        ]

    def get(self, team_ref: str, channel_ref: str) -> Channel:
        """Retrieves a specific channel by its reference within a team.

        Args:
            team_ref (str): The reference to the team (UUID or Display Name).
            channel_ref (str): The reference to the channel (ID or Display Name).

        Returns:
            Channel: The requested channel object.

        Raises:
            Exception: If the reference is ambiguous or not found (propagated from Go).
        """
        response = self.client.execute(
            cmd_type="request",
            method="getChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
            },
        )

        return Channel(
            id=response["ID"],
            name=response["Name"],
            is_general=(True if response["IsGeneral"] else False),
        )

    def create_standard(self, team_ref: str, display_name: str) -> Channel:
        """Creates a standard (public) channel within a team.

        Args:
            team_ref (str): The reference to the team.
            display_name (str): The display name for the new channel.

        Returns:
            Channel: The newly created channel object.
        """
        response = self.client.execute(
            cmd_type="request",
            method="createStandardChannel",
            params={
                "teamRef": team_ref,
                "name": display_name,
            },
        )

        return Channel(
            id=response["ID"],
            name=response["Name"],
            is_general=(True if response["IsGeneral"] else False),
        )

    def create_private(
        self,
        team_ref: str,
        display_name: str,
        member_refs: list[str],
        owner_refs: list[str],
    ) -> Channel:
        """Creates a private channel restricted to specific members.

        Args:
            team_ref (str): The reference to the team.
            display_name (str): The display name for the new private channel.
            member_refs (list[str]): List of user references (IDs or emails) to add as members.
            owner_refs (list[str]): List of user references to add as owners.
                At least one owner is required.

        Returns:
            Channel: The newly created private channel object.
        """
        response = self.client.execute(
            cmd_type="request",
            method="createPrivateChannel",
            params={
                "teamRef": team_ref,
                "name": display_name,
                "memberRefs": member_refs,
                "ownerRefs": owner_refs,
            },
        )

        return Channel(
            id=response["ID"],
            name=response["Name"],
            is_general=(True if response["IsGeneral"] else False),
        )

    def delete(self, team_ref: str, channel_ref: str) -> bool:
        """Removes a channel from a team.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel to be deleted.

        Returns:
            bool: True if the operation was successful.
        """
        response = self.client.execute(
            cmd_type="request",
            method="deleteChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
            },
        )
        return response == "deleted"

    def send_message(
        self, team_ref: str, channel_ref: str, body: MessageBody
    ) -> Message:
        """Sends a new message to a channel.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.
            body (MessageBody): The message payload containing content, content type
                (Text/HTML), and optional mentions.

        Returns:
            Message: The created message object.
        """
        response = self.client.execute(
            cmd_type="request",
            method="sendMessageToChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
                "body": dict(body),
            },
        )

        return Message(
            id=response["ID"],
            content=response["Content"],
            content_type=MessageContentType(response["ContentType"]),
            created_date_time=response["CreatedDateTime"],
            sender=MessageFrom(
                user_id=response["From"]["UserID"],
                display_name=response["From"]["DisplayName"],
            ),
            reply_count=response["ReplyCount"],
        )

    def list_messages(  # noqa: PLR0913
        self,
        team_ref: str,
        channel_ref: str,
        top: int | None = 10,
        expand_replies: bool = False,
        include_system_messages: bool = False,
        next_link: str | None = None,
    ) -> MessageCollection:
        """Retrieves messages from a channel.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.
            top (Optional[int]): The maximum number of messages to retrieve. Defaults to 10.
            expand_replies (bool): If True, system fetches replies for each message. Defaults to False.
            include_system_messages (bool): If True, includes system-generated messages. Defaults to False.
            next_link (Optional[str]): A link for pagination to fetch the next set of messages.

        Returns:
            MessageCollection: An object containing the list of messages and a next link for pagination.
        """
        response = self.client.execute(
            cmd_type="request",
            method="listMessagesInChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
                "options": {
                    "top": top,
                    "expandReplies": expand_replies,
                    "includeSystem": include_system_messages,
                    "nextLink": next_link,
                },
            },
        )

        return MessageCollection(
            messages=[
                Message(
                    id=msg["ID"],
                    content=msg["Content"],
                    content_type=MessageContentType(msg["ContentType"]),
                    created_date_time=msg["CreatedDateTime"],
                    sender=MessageFrom(
                        user_id=msg["From"]["UserID"],
                        display_name=msg["From"]["DisplayName"],
                    ),
                    reply_count=msg["ReplyCount"],
                )
                for msg in response["Messages"]
            ],
            next_link=response.get("NextLink"),
        )

    def get_message(self, team_ref: str, channel_ref: str, message_id: str) -> Message:
        """Retrieves a specific message by its ID.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.
            message_id (str): The unique identifier of the message.

        Returns:
            Message: The requested message object.
        """
        response = self.client.execute(
            cmd_type="request",
            method="getMessageInChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
                "messageID": message_id,
            },
        )

        return Message(
            id=response["ID"],
            content=response["Content"],
            content_type=MessageContentType(response["ContentType"]),
            created_date_time=response["CreatedDateTime"],
            sender=MessageFrom(
                user_id=response["From"]["UserID"],
                display_name=response["From"]["DisplayName"],
            ),
            reply_count=response["ReplyCount"],
        )

    def list_message_replies(  # noqa: PLR0913
        self,
        team_ref: str,
        channel_ref: str,
        message_id: str,
        top: int | None = 10,
        include_system_messages: bool = False,
        next_link: str | None = None,
    ) -> MessageCollection:
        """Retrieves all replies to a specific message thread.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.
            message_id (str): The ID of the parent message.
            top (Optional[int]): Max number of replies to fetch. Defaults to 10.
            include_system_messages (bool): If True, includes system-generated messages. Defaults to False.
            next_link (Optional[str]): A link for pagination to fetch the next set of replies.

        Returns:
            MessageCollection: An object containing the list of replies and a next link for pagination.
        """
        response = self.client.execute(
            cmd_type="request",
            method="listMessageRepliesInChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
                "messageID": message_id,
                "top": top,
                "includeSystem": include_system_messages,
                "nextLink": next_link,
            },
        )

        return MessageCollection(
            messages=[
                Message(
                    id=msg["ID"],
                    content=msg["Content"],
                    content_type=MessageContentType(msg["ContentType"]),
                    created_date_time=msg["CreatedDateTime"],
                    sender=MessageFrom(
                        user_id=msg["From"]["UserID"],
                        display_name=msg["From"]["DisplayName"],
                    ),
                    reply_count=msg["ReplyCount"],
                )
                for msg in response["Messages"]
            ],
            next_link=response.get("NextLink"),
        )

    def get_message_reply(
        self,
        team_ref: str,
        channel_ref: str,
        message_id: str,
        reply_id: str,
    ) -> Message:
        """Retrieves a specific reply from a thread.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.
            message_id (str): The ID of the parent message.
            reply_id (str): The ID of the reply to retrieve.

        Returns:
            Message: The requested reply object.
        """
        response = self.client.execute(
            cmd_type="request",
            method="getMessageReplyInChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
                "messageID": message_id,
                "replyID": reply_id,
            },
        )

        return Message(
            id=response["ID"],
            content=response["Content"],
            content_type=MessageContentType(response["ContentType"]),
            created_date_time=response["CreatedDateTime"],
            sender=MessageFrom(
                user_id=response["From"]["UserID"],
                display_name=response["From"]["DisplayName"],
            ),
            reply_count=response["ReplyCount"],
        )

    def list_members(self, team_ref: str, channel_ref: str) -> list[Member]:
        """Lists all members of a channel.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.

        Returns:
            List[Member]: A list of channel members.
        """
        response = self.client.execute(
            cmd_type="request",
            method="listChannelMembers",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
            },
        )
        return [Member(
            id=member["ID"],
            user_id=member["UserID"],
            display_name=member["DisplayName"],
            role=member["Role"],
            email=member["Email"],
        ) for member in response]

    def add_member(
        self, team_ref: str, channel_ref: str, user_ref: str, is_owner: bool
    ) -> Member:
        """Adds a user to a channel.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.
            user_ref (str): The user to add (User ID or Email).
            is_owner (bool): Whether to grant Owner privileges.

        Returns:
            Member: The newly added member object.
        """
        response = self.client.execute(
            cmd_type="request",
            method="addMemberToChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
                "userRef": user_ref,
                "isOwner": is_owner,
            },
        )
        return Member(
            id=response["ID"],
            user_id=response["UserID"],
            display_name=response["DisplayName"],
            role=response["Role"],
            email=response["Email"],
        )

    def update_member_role(
        self, team_ref: str, channel_ref: str, user_ref: str, is_owner: bool
    ) -> Member:
        """Updates the role of an existing channel member.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.
            user_ref (str): The user reference (ID or Email).
            is_owner (bool): True for Owner role, False for Member role.

        Returns:
            Member: The updated member object.
        """
        response = self.client.execute(
            cmd_type="request",
            method="updateMemberRoleInChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
                "userRef": user_ref,
                "isOwner": is_owner,
            },
        )
        return Member(
            id=response["ID"],
            user_id=response["UserID"],
            display_name=response["DisplayName"],
            role=response["Role"],
            email=response["Email"],
        )

    def remove_member(self, team_ref: str, channel_ref: str, user_ref: str) -> bool:
        """Removes a user from a channel.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.
            user_ref (str): The user reference (ID or Email) to remove.

        Returns:
            bool: True if the operation was successful.
        """
        response = self.client.execute(
            cmd_type="request",
            method="removeMemberFromChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
                "userRef": user_ref,
            },
        )
        return response == "removed"

    def get_mentions(
        self, team_ref: str, channel_ref: str, raw_mentions: list[str]
    ) -> list[Mention]:
        """Resolves raw mention strings into formal Mention objects.

        This is used to construct the `mentions` field for messages before sending.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.
            raw_mentions (List[str]): A list of raw strings to resolve.
                Supported formats:
                * **Email/User ID**: Resolves to a specific user.
                * **'channel'**: Mentions the current channel.
                * **'team'**: Mentions the parent team.

        Returns:
            List[Mention]: A list of resolved Mention objects ready for the API.
        """
        response = self.client.execute(
            cmd_type="request",
            method="getMentionsInChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
                "rawMentions": raw_mentions,
            },
        )
        return [Mention(
            kind=MentionKind(mention["Kind"]),
            at_id=mention["AtID"],
            text=mention["Text"],
            target_id=mention["TargetID"],
        ) for mention in response]

    def search_messages(self, team_ref: str, channel_ref: str, options: SearchMessagesOptions, config: SearchConfig) -> SearchResults:
        """Searches for messages in a channel based on various criteria.

        Args:
            team_ref (str): The reference to the team.
            channel_ref (str): The reference to the channel.
            options (SearchMessagesOptions): The search options and filters.
            config (SearchConfig): Configuration for the search operation.

        Returns:
            SearchResults: The results of the search operation.
        """
        response = self.client.execute(
            cmd_type="request",
            method="searchMessagesInChannel",
            params={
                "teamRef": team_ref,
                "channelRef": channel_ref,
                "searchMessagesOptions": options.__dict__(),
                "searchConfig": config.__dict__(),
            },
        )

        return SearchResults(
            messages=[
                SearchResult(
                    message=Message(
                        id=msg["Message"]["ID"],
                        content=msg["Message"]["Content"],
                        content_type=MessageContentType(msg["Message"]["ContentType"]),
                        created_date_time=msg["Message"]["CreatedDateTime"],
                        sender=MessageFrom(
                            user_id=msg["Message"]["From"]["UserID"],
                            display_name=msg["Message"]["From"]["DisplayName"],
                        ),
                        reply_count=msg["Message"]["ReplyCount"],
                    ),
                    channel_id=msg.get("ChannelID"),
                    team_id=msg.get("TeamID"),
                    chat_id=msg.get("ChatID"),
                )
                for msg in response["Messages"]
            ] if response.get("Messages") else [],
            next_from=response.get("NextFrom"),
        )

Functions

add_member(team_ref, channel_ref, user_ref, is_owner)

Adds a user to a channel.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required
user_ref str

The user to add (User ID or Email).

required
is_owner bool

Whether to grant Owner privileges.

required

Returns:

Name Type Description
Member Member

The newly added member object.

Source code in teams_lib_pzsp2_z1/services/channels.py
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
def add_member(
    self, team_ref: str, channel_ref: str, user_ref: str, is_owner: bool
) -> Member:
    """Adds a user to a channel.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.
        user_ref (str): The user to add (User ID or Email).
        is_owner (bool): Whether to grant Owner privileges.

    Returns:
        Member: The newly added member object.
    """
    response = self.client.execute(
        cmd_type="request",
        method="addMemberToChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
            "userRef": user_ref,
            "isOwner": is_owner,
        },
    )
    return Member(
        id=response["ID"],
        user_id=response["UserID"],
        display_name=response["DisplayName"],
        role=response["Role"],
        email=response["Email"],
    )

create_private(team_ref, display_name, member_refs, owner_refs)

Creates a private channel restricted to specific members.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
display_name str

The display name for the new private channel.

required
member_refs list[str]

List of user references (IDs or emails) to add as members.

required
owner_refs list[str]

List of user references to add as owners. At least one owner is required.

required

Returns:

Name Type Description
Channel Channel

The newly created private channel object.

Source code in teams_lib_pzsp2_z1/services/channels.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def create_private(
    self,
    team_ref: str,
    display_name: str,
    member_refs: list[str],
    owner_refs: list[str],
) -> Channel:
    """Creates a private channel restricted to specific members.

    Args:
        team_ref (str): The reference to the team.
        display_name (str): The display name for the new private channel.
        member_refs (list[str]): List of user references (IDs or emails) to add as members.
        owner_refs (list[str]): List of user references to add as owners.
            At least one owner is required.

    Returns:
        Channel: The newly created private channel object.
    """
    response = self.client.execute(
        cmd_type="request",
        method="createPrivateChannel",
        params={
            "teamRef": team_ref,
            "name": display_name,
            "memberRefs": member_refs,
            "ownerRefs": owner_refs,
        },
    )

    return Channel(
        id=response["ID"],
        name=response["Name"],
        is_general=(True if response["IsGeneral"] else False),
    )

create_standard(team_ref, display_name)

Creates a standard (public) channel within a team.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
display_name str

The display name for the new channel.

required

Returns:

Name Type Description
Channel Channel

The newly created channel object.

Source code in teams_lib_pzsp2_z1/services/channels.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def create_standard(self, team_ref: str, display_name: str) -> Channel:
    """Creates a standard (public) channel within a team.

    Args:
        team_ref (str): The reference to the team.
        display_name (str): The display name for the new channel.

    Returns:
        Channel: The newly created channel object.
    """
    response = self.client.execute(
        cmd_type="request",
        method="createStandardChannel",
        params={
            "teamRef": team_ref,
            "name": display_name,
        },
    )

    return Channel(
        id=response["ID"],
        name=response["Name"],
        is_general=(True if response["IsGeneral"] else False),
    )

delete(team_ref, channel_ref)

Removes a channel from a team.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel to be deleted.

required

Returns:

Name Type Description
bool bool

True if the operation was successful.

Source code in teams_lib_pzsp2_z1/services/channels.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def delete(self, team_ref: str, channel_ref: str) -> bool:
    """Removes a channel from a team.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel to be deleted.

    Returns:
        bool: True if the operation was successful.
    """
    response = self.client.execute(
        cmd_type="request",
        method="deleteChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
        },
    )
    return response == "deleted"

get(team_ref, channel_ref)

Retrieves a specific channel by its reference within a team.

Parameters:

Name Type Description Default
team_ref str

The reference to the team (UUID or Display Name).

required
channel_ref str

The reference to the channel (ID or Display Name).

required

Returns:

Name Type Description
Channel Channel

The requested channel object.

Raises:

Type Description
Exception

If the reference is ambiguous or not found (propagated from Go).

Source code in teams_lib_pzsp2_z1/services/channels.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def get(self, team_ref: str, channel_ref: str) -> Channel:
    """Retrieves a specific channel by its reference within a team.

    Args:
        team_ref (str): The reference to the team (UUID or Display Name).
        channel_ref (str): The reference to the channel (ID or Display Name).

    Returns:
        Channel: The requested channel object.

    Raises:
        Exception: If the reference is ambiguous or not found (propagated from Go).
    """
    response = self.client.execute(
        cmd_type="request",
        method="getChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
        },
    )

    return Channel(
        id=response["ID"],
        name=response["Name"],
        is_general=(True if response["IsGeneral"] else False),
    )

get_mentions(team_ref, channel_ref, raw_mentions)

Resolves raw mention strings into formal Mention objects.

This is used to construct the mentions field for messages before sending.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required
raw_mentions List[str]

A list of raw strings to resolve. Supported formats: * Email/User ID: Resolves to a specific user. * 'channel': Mentions the current channel. * 'team': Mentions the parent team.

required

Returns:

Type Description
list[Mention]

List[Mention]: A list of resolved Mention objects ready for the API.

Source code in teams_lib_pzsp2_z1/services/channels.py
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
def get_mentions(
    self, team_ref: str, channel_ref: str, raw_mentions: list[str]
) -> list[Mention]:
    """Resolves raw mention strings into formal Mention objects.

    This is used to construct the `mentions` field for messages before sending.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.
        raw_mentions (List[str]): A list of raw strings to resolve.
            Supported formats:
            * **Email/User ID**: Resolves to a specific user.
            * **'channel'**: Mentions the current channel.
            * **'team'**: Mentions the parent team.

    Returns:
        List[Mention]: A list of resolved Mention objects ready for the API.
    """
    response = self.client.execute(
        cmd_type="request",
        method="getMentionsInChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
            "rawMentions": raw_mentions,
        },
    )
    return [Mention(
        kind=MentionKind(mention["Kind"]),
        at_id=mention["AtID"],
        text=mention["Text"],
        target_id=mention["TargetID"],
    ) for mention in response]

get_message(team_ref, channel_ref, message_id)

Retrieves a specific message by its ID.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required
message_id str

The unique identifier of the message.

required

Returns:

Name Type Description
Message Message

The requested message object.

Source code in teams_lib_pzsp2_z1/services/channels.py
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
def get_message(self, team_ref: str, channel_ref: str, message_id: str) -> Message:
    """Retrieves a specific message by its ID.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.
        message_id (str): The unique identifier of the message.

    Returns:
        Message: The requested message object.
    """
    response = self.client.execute(
        cmd_type="request",
        method="getMessageInChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
            "messageID": message_id,
        },
    )

    return Message(
        id=response["ID"],
        content=response["Content"],
        content_type=MessageContentType(response["ContentType"]),
        created_date_time=response["CreatedDateTime"],
        sender=MessageFrom(
            user_id=response["From"]["UserID"],
            display_name=response["From"]["DisplayName"],
        ),
        reply_count=response["ReplyCount"],
    )

get_message_reply(team_ref, channel_ref, message_id, reply_id)

Retrieves a specific reply from a thread.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required
message_id str

The ID of the parent message.

required
reply_id str

The ID of the reply to retrieve.

required

Returns:

Name Type Description
Message Message

The requested reply object.

Source code in teams_lib_pzsp2_z1/services/channels.py
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
def get_message_reply(
    self,
    team_ref: str,
    channel_ref: str,
    message_id: str,
    reply_id: str,
) -> Message:
    """Retrieves a specific reply from a thread.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.
        message_id (str): The ID of the parent message.
        reply_id (str): The ID of the reply to retrieve.

    Returns:
        Message: The requested reply object.
    """
    response = self.client.execute(
        cmd_type="request",
        method="getMessageReplyInChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
            "messageID": message_id,
            "replyID": reply_id,
        },
    )

    return Message(
        id=response["ID"],
        content=response["Content"],
        content_type=MessageContentType(response["ContentType"]),
        created_date_time=response["CreatedDateTime"],
        sender=MessageFrom(
            user_id=response["From"]["UserID"],
            display_name=response["From"]["DisplayName"],
        ),
        reply_count=response["ReplyCount"],
    )

list_channels(team_ref)

Retrieves all channels associated with a specific team.

Parameters:

Name Type Description Default
team_ref str

The reference to the team (UUID or Display Name).

required

Returns: List[Channel]: A list of channel objects found in the team.

Source code in teams_lib_pzsp2_z1/services/channels.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def list_channels(self, team_ref: str) -> list[Channel]:
    """Retrieves all channels associated with a specific team.

    Args:
        team_ref (str): The reference to the team (UUID or Display Name).
    Returns:
        List[Channel]: A list of channel objects found in the team.
    """
    response = self.client.execute(
        cmd_type="request",
        method="listChannels",
        params={
            "teamRef": team_ref,
        },
    )
    return [
        Channel(
            id=channel["ID"],
            name=channel["Name"],
            is_general=(True if channel["IsGeneral"] else False),
        )
        for channel in response
    ]

list_members(team_ref, channel_ref)

Lists all members of a channel.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required

Returns:

Type Description
list[Member]

List[Member]: A list of channel members.

Source code in teams_lib_pzsp2_z1/services/channels.py
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
def list_members(self, team_ref: str, channel_ref: str) -> list[Member]:
    """Lists all members of a channel.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.

    Returns:
        List[Member]: A list of channel members.
    """
    response = self.client.execute(
        cmd_type="request",
        method="listChannelMembers",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
        },
    )
    return [Member(
        id=member["ID"],
        user_id=member["UserID"],
        display_name=member["DisplayName"],
        role=member["Role"],
        email=member["Email"],
    ) for member in response]

list_message_replies(team_ref, channel_ref, message_id, top=10, include_system_messages=False, next_link=None)

Retrieves all replies to a specific message thread.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required
message_id str

The ID of the parent message.

required
top Optional[int]

Max number of replies to fetch. Defaults to 10.

10
include_system_messages bool

If True, includes system-generated messages. Defaults to False.

False
next_link Optional[str]

A link for pagination to fetch the next set of replies.

None

Returns:

Name Type Description
MessageCollection MessageCollection

An object containing the list of replies and a next link for pagination.

Source code in teams_lib_pzsp2_z1/services/channels.py
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
def list_message_replies(  # noqa: PLR0913
    self,
    team_ref: str,
    channel_ref: str,
    message_id: str,
    top: int | None = 10,
    include_system_messages: bool = False,
    next_link: str | None = None,
) -> MessageCollection:
    """Retrieves all replies to a specific message thread.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.
        message_id (str): The ID of the parent message.
        top (Optional[int]): Max number of replies to fetch. Defaults to 10.
        include_system_messages (bool): If True, includes system-generated messages. Defaults to False.
        next_link (Optional[str]): A link for pagination to fetch the next set of replies.

    Returns:
        MessageCollection: An object containing the list of replies and a next link for pagination.
    """
    response = self.client.execute(
        cmd_type="request",
        method="listMessageRepliesInChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
            "messageID": message_id,
            "top": top,
            "includeSystem": include_system_messages,
            "nextLink": next_link,
        },
    )

    return MessageCollection(
        messages=[
            Message(
                id=msg["ID"],
                content=msg["Content"],
                content_type=MessageContentType(msg["ContentType"]),
                created_date_time=msg["CreatedDateTime"],
                sender=MessageFrom(
                    user_id=msg["From"]["UserID"],
                    display_name=msg["From"]["DisplayName"],
                ),
                reply_count=msg["ReplyCount"],
            )
            for msg in response["Messages"]
        ],
        next_link=response.get("NextLink"),
    )

list_messages(team_ref, channel_ref, top=10, expand_replies=False, include_system_messages=False, next_link=None)

Retrieves messages from a channel.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required
top Optional[int]

The maximum number of messages to retrieve. Defaults to 10.

10
expand_replies bool

If True, system fetches replies for each message. Defaults to False.

False
include_system_messages bool

If True, includes system-generated messages. Defaults to False.

False
next_link Optional[str]

A link for pagination to fetch the next set of messages.

None

Returns:

Name Type Description
MessageCollection MessageCollection

An object containing the list of messages and a next link for pagination.

Source code in teams_lib_pzsp2_z1/services/channels.py
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
def list_messages(  # noqa: PLR0913
    self,
    team_ref: str,
    channel_ref: str,
    top: int | None = 10,
    expand_replies: bool = False,
    include_system_messages: bool = False,
    next_link: str | None = None,
) -> MessageCollection:
    """Retrieves messages from a channel.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.
        top (Optional[int]): The maximum number of messages to retrieve. Defaults to 10.
        expand_replies (bool): If True, system fetches replies for each message. Defaults to False.
        include_system_messages (bool): If True, includes system-generated messages. Defaults to False.
        next_link (Optional[str]): A link for pagination to fetch the next set of messages.

    Returns:
        MessageCollection: An object containing the list of messages and a next link for pagination.
    """
    response = self.client.execute(
        cmd_type="request",
        method="listMessagesInChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
            "options": {
                "top": top,
                "expandReplies": expand_replies,
                "includeSystem": include_system_messages,
                "nextLink": next_link,
            },
        },
    )

    return MessageCollection(
        messages=[
            Message(
                id=msg["ID"],
                content=msg["Content"],
                content_type=MessageContentType(msg["ContentType"]),
                created_date_time=msg["CreatedDateTime"],
                sender=MessageFrom(
                    user_id=msg["From"]["UserID"],
                    display_name=msg["From"]["DisplayName"],
                ),
                reply_count=msg["ReplyCount"],
            )
            for msg in response["Messages"]
        ],
        next_link=response.get("NextLink"),
    )

remove_member(team_ref, channel_ref, user_ref)

Removes a user from a channel.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required
user_ref str

The user reference (ID or Email) to remove.

required

Returns:

Name Type Description
bool bool

True if the operation was successful.

Source code in teams_lib_pzsp2_z1/services/channels.py
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
def remove_member(self, team_ref: str, channel_ref: str, user_ref: str) -> bool:
    """Removes a user from a channel.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.
        user_ref (str): The user reference (ID or Email) to remove.

    Returns:
        bool: True if the operation was successful.
    """
    response = self.client.execute(
        cmd_type="request",
        method="removeMemberFromChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
            "userRef": user_ref,
        },
    )
    return response == "removed"

search_messages(team_ref, channel_ref, options, config)

Searches for messages in a channel based on various criteria.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required
options SearchMessagesOptions

The search options and filters.

required
config SearchConfig

Configuration for the search operation.

required

Returns:

Name Type Description
SearchResults SearchResults

The results of the search operation.

Source code in teams_lib_pzsp2_z1/services/channels.py
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
def search_messages(self, team_ref: str, channel_ref: str, options: SearchMessagesOptions, config: SearchConfig) -> SearchResults:
    """Searches for messages in a channel based on various criteria.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.
        options (SearchMessagesOptions): The search options and filters.
        config (SearchConfig): Configuration for the search operation.

    Returns:
        SearchResults: The results of the search operation.
    """
    response = self.client.execute(
        cmd_type="request",
        method="searchMessagesInChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
            "searchMessagesOptions": options.__dict__(),
            "searchConfig": config.__dict__(),
        },
    )

    return SearchResults(
        messages=[
            SearchResult(
                message=Message(
                    id=msg["Message"]["ID"],
                    content=msg["Message"]["Content"],
                    content_type=MessageContentType(msg["Message"]["ContentType"]),
                    created_date_time=msg["Message"]["CreatedDateTime"],
                    sender=MessageFrom(
                        user_id=msg["Message"]["From"]["UserID"],
                        display_name=msg["Message"]["From"]["DisplayName"],
                    ),
                    reply_count=msg["Message"]["ReplyCount"],
                ),
                channel_id=msg.get("ChannelID"),
                team_id=msg.get("TeamID"),
                chat_id=msg.get("ChatID"),
            )
            for msg in response["Messages"]
        ] if response.get("Messages") else [],
        next_from=response.get("NextFrom"),
    )

send_message(team_ref, channel_ref, body)

Sends a new message to a channel.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required
body MessageBody

The message payload containing content, content type (Text/HTML), and optional mentions.

required

Returns:

Name Type Description
Message Message

The created message object.

Source code in teams_lib_pzsp2_z1/services/channels.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
def send_message(
    self, team_ref: str, channel_ref: str, body: MessageBody
) -> Message:
    """Sends a new message to a channel.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.
        body (MessageBody): The message payload containing content, content type
            (Text/HTML), and optional mentions.

    Returns:
        Message: The created message object.
    """
    response = self.client.execute(
        cmd_type="request",
        method="sendMessageToChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
            "body": dict(body),
        },
    )

    return Message(
        id=response["ID"],
        content=response["Content"],
        content_type=MessageContentType(response["ContentType"]),
        created_date_time=response["CreatedDateTime"],
        sender=MessageFrom(
            user_id=response["From"]["UserID"],
            display_name=response["From"]["DisplayName"],
        ),
        reply_count=response["ReplyCount"],
    )

update_member_role(team_ref, channel_ref, user_ref, is_owner)

Updates the role of an existing channel member.

Parameters:

Name Type Description Default
team_ref str

The reference to the team.

required
channel_ref str

The reference to the channel.

required
user_ref str

The user reference (ID or Email).

required
is_owner bool

True for Owner role, False for Member role.

required

Returns:

Name Type Description
Member Member

The updated member object.

Source code in teams_lib_pzsp2_z1/services/channels.py
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
def update_member_role(
    self, team_ref: str, channel_ref: str, user_ref: str, is_owner: bool
) -> Member:
    """Updates the role of an existing channel member.

    Args:
        team_ref (str): The reference to the team.
        channel_ref (str): The reference to the channel.
        user_ref (str): The user reference (ID or Email).
        is_owner (bool): True for Owner role, False for Member role.

    Returns:
        Member: The updated member object.
    """
    response = self.client.execute(
        cmd_type="request",
        method="updateMemberRoleInChannel",
        params={
            "teamRef": team_ref,
            "channelRef": channel_ref,
            "userRef": user_ref,
            "isOwner": is_owner,
        },
    )
    return Member(
        id=response["ID"],
        user_id=response["UserID"],
        display_name=response["DisplayName"],
        role=response["Role"],
        email=response["Email"],
    )