-
Notifications
You must be signed in to change notification settings - Fork 6
Create conversation client #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
32b03d7
Create member client
heyitsaamir fc4d514
Create activity client
heyitsaamir 45fc4d3
Create conversation client
heyitsaamir c414744
create mypy
heyitsaamir 59bf263
Fix m
heyitsaamir cde6b6c
update
heyitsaamir 3c4b4ac
BaseClient
heyitsaamir 1a43510
model init
heyitsaamir 239fdc8
model init
heyitsaamir 7e7abcf
model init
heyitsaamir 1f16158
better models
heyitsaamir c5f0a2d
better models
heyitsaamir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,13 @@ authors = [ | |
| { name = "Microsoft", email = "[email protected]" } | ||
| ] | ||
| requires-python = ">=3.12" | ||
| dependencies = [] | ||
| dependencies = [ | ||
| "pydantic>=2.0.0", | ||
| "microsoft-teams-common", | ||
| ] | ||
|
|
||
| [tool.uv.sources] | ||
| "microsoft-teams-common" = { workspace = true } | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/microsoft/teams.py/tree/main/packages/api/src/microsoft/teams/api" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| from .conversation import * # noqa: F403 | ||
| from .conversation import __all__ as conversation_all | ||
|
|
||
| __all__ = [ | ||
| *conversation_all, | ||
| ] |
30 changes: 30 additions & 0 deletions
30
packages/api/src/microsoft/teams/api/clients/base_client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| from typing import Optional, Union | ||
|
|
||
| from microsoft.teams.common.http import Client, ClientOptions | ||
|
|
||
|
|
||
| class BaseClient: | ||
| """Base client""" | ||
|
|
||
| def __init__(self, options: Optional[Union[Client, ClientOptions]] = None) -> None: | ||
| """Initialize the BaseClient. | ||
|
|
||
| Args: | ||
| options: Optional Client or ClientOptions instance. If not provided, a default Client will be created. | ||
| """ | ||
| self._http = Client(options or ClientOptions()) | ||
|
|
||
| @property | ||
| def http(self) -> Client: | ||
| """Get the HTTP client instance.""" | ||
| return self._http | ||
|
|
||
| @http.setter | ||
| def http(self, value: Client) -> None: | ||
| """Set the HTTP client instance.""" | ||
| self._http = value |
18 changes: 18 additions & 0 deletions
18
packages/api/src/microsoft/teams/api/clients/conversation/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| from .activity import ConversationActivityClient | ||
| from .client import ConversationClient | ||
| from .member import ConversationMemberClient | ||
| from .params import CreateConversationParams, GetConversationsParams, GetConversationsResponse | ||
|
|
||
| __all__ = [ | ||
| "ConversationActivityClient", | ||
| "ConversationClient", | ||
| "ConversationMemberClient", | ||
| "CreateConversationParams", | ||
| "GetConversationsParams", | ||
| "GetConversationsResponse", | ||
| ] |
108 changes: 108 additions & 0 deletions
108
packages/api/src/microsoft/teams/api/clients/conversation/activity.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| from typing import List, Optional | ||
|
|
||
| from microsoft.teams.common.http import Client | ||
|
|
||
| from ...models import Account, Activity | ||
| from ..base_client import BaseClient | ||
|
|
||
|
|
||
| class ConversationActivityClient(BaseClient): | ||
| """ | ||
| Client for managing activities in a Teams conversation. | ||
| """ | ||
|
|
||
| def __init__(self, service_url: str, http_client: Optional[Client] = None): | ||
| """ | ||
| Initialize the conversation activity client. | ||
|
|
||
| Args: | ||
| service_url: The base URL for the Teams service | ||
| http_client: Optional HTTP client to use. If not provided, a new one will be created. | ||
| """ | ||
| super().__init__(http_client) | ||
| self.service_url = service_url | ||
|
|
||
| async def create(self, conversation_id: str, activity: Activity) -> Activity: | ||
| """ | ||
| Create a new activity in a conversation. | ||
|
|
||
| Args: | ||
| conversation_id: The ID of the conversation | ||
| activity: The activity to create | ||
|
|
||
| Returns: | ||
| The created activity | ||
| """ | ||
| response = await self.http.post( | ||
| f"{self.service_url}/v3/conversations/{conversation_id}/activities", | ||
| json=activity.model_dump(by_alias=True), | ||
| ) | ||
| return Activity.model_validate(response.json()) | ||
|
|
||
| async def update(self, conversation_id: str, activity_id: str, activity: Activity) -> Activity: | ||
| """ | ||
| Update an existing activity in a conversation. | ||
|
|
||
| Args: | ||
| conversation_id: The ID of the conversation | ||
| activity_id: The ID of the activity to update | ||
| activity: The updated activity data | ||
|
|
||
| Returns: | ||
| The updated activity | ||
| """ | ||
| response = await self.http.put( | ||
| f"{self.service_url}/v3/conversations/{conversation_id}/activities/{activity_id}", | ||
| json=activity.model_dump(by_alias=True), | ||
| ) | ||
| return Activity.model_validate(response.json()) | ||
|
|
||
| async def reply(self, conversation_id: str, activity_id: str, activity: Activity) -> Activity: | ||
| """ | ||
| Reply to an activity in a conversation. | ||
|
|
||
| Args: | ||
| conversation_id: The ID of the conversation | ||
| activity_id: The ID of the activity to reply to | ||
| activity: The reply activity | ||
|
|
||
| Returns: | ||
| The created reply activity | ||
| """ | ||
| activity.reply_to_id = activity_id | ||
| response = await self.http.post( | ||
| f"{self.service_url}/v3/conversations/{conversation_id}/activities/{activity_id}", | ||
| json=activity.model_dump(by_alias=True), | ||
| ) | ||
| return Activity.model_validate(response.json()) | ||
|
|
||
| async def delete(self, conversation_id: str, activity_id: str) -> None: | ||
| """ | ||
| Delete an activity from a conversation. | ||
|
|
||
| Args: | ||
| conversation_id: The ID of the conversation | ||
| activity_id: The ID of the activity to delete | ||
| """ | ||
| await self.http.delete(f"{self.service_url}/v3/conversations/{conversation_id}/activities/{activity_id}") | ||
|
|
||
| async def get_members(self, conversation_id: str, activity_id: str) -> List[Account]: | ||
| """ | ||
| Get the members associated with an activity. | ||
|
|
||
| Args: | ||
| conversation_id: The ID of the conversation | ||
| activity_id: The ID of the activity | ||
|
|
||
| Returns: | ||
| List of Account objects representing the activity members | ||
| """ | ||
| response = await self.http.get( | ||
| f"{self.service_url}/v3/conversations/{conversation_id}/activities/{activity_id}/members" | ||
| ) | ||
| return [Account.model_validate(member) for member in response.json()] |
131 changes: 131 additions & 0 deletions
131
packages/api/src/microsoft/teams/api/clients/conversation/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| from typing import Any, Optional, Union | ||
|
|
||
| from microsoft.teams.common.http import Client, ClientOptions | ||
|
|
||
| from ...models import ConversationResource | ||
| from ..base_client import BaseClient | ||
| from .activity import ConversationActivityClient | ||
| from .member import ConversationMemberClient | ||
| from .params import ( | ||
| CreateConversationParams, | ||
| GetConversationsParams, | ||
| GetConversationsResponse, | ||
| ) | ||
|
|
||
|
|
||
| class ConversationOperations: | ||
| """Base class for conversation operations.""" | ||
|
|
||
| def __init__(self, client: "ConversationClient", conversation_id: str) -> None: | ||
| self._client = client | ||
| self._conversation_id = conversation_id | ||
|
|
||
|
|
||
| class ActivityOperations(ConversationOperations): | ||
| """Operations for managing activities in a conversation.""" | ||
|
|
||
| async def create(self, activity: Any) -> Any: | ||
| return await self._client._activities.create(self._conversation_id, activity) | ||
|
|
||
| async def update(self, activity_id: str, activity: Any) -> Any: | ||
| return await self._client._activities.update(self._conversation_id, activity_id, activity) | ||
|
|
||
| async def reply(self, activity_id: str, activity: Any) -> Any: | ||
| return await self._client._activities.reply(self._conversation_id, activity_id, activity) | ||
|
|
||
| async def delete(self, activity_id: str) -> None: | ||
| await self._client._activities.delete(self._conversation_id, activity_id) | ||
|
|
||
| async def get_members(self, activity_id: str) -> Any: | ||
| return await self._client._activities.get_members(self._conversation_id, activity_id) | ||
|
|
||
|
|
||
| class MemberOperations(ConversationOperations): | ||
| """Operations for managing members in a conversation.""" | ||
|
|
||
| async def get_all(self) -> Any: | ||
| return await self._client._members.get(self._conversation_id) | ||
|
|
||
| async def get(self, member_id: str) -> Any: | ||
| return await self._client._members.get_by_id(self._conversation_id, member_id) | ||
|
|
||
| async def delete(self, member_id: str) -> None: | ||
| await self._client._members.delete(self._conversation_id, member_id) | ||
|
|
||
|
|
||
| class ConversationClient(BaseClient): | ||
| """Client for managing Teams conversations.""" | ||
|
|
||
| def __init__(self, service_url: str, options: Optional[Union[Client, ClientOptions]] = None) -> None: | ||
| """Initialize the client. | ||
|
|
||
| Args: | ||
| service_url: The Teams service URL. | ||
| options: Either an HTTP client instance or client options. If None, a default client is created. | ||
| """ | ||
| super().__init__(options) | ||
| self.service_url = service_url | ||
|
|
||
| self._activities = ConversationActivityClient(service_url, self.http) | ||
| self._members = ConversationMemberClient(service_url, self.http) | ||
|
|
||
| def activities(self, conversation_id: str) -> ActivityOperations: | ||
| """Get activity operations for a conversation. | ||
|
|
||
| Args: | ||
| conversation_id: The ID of the conversation. | ||
|
|
||
| Returns: | ||
| An operations object for managing activities in the conversation. | ||
| """ | ||
| return ActivityOperations(self, conversation_id) | ||
|
|
||
| def members(self, conversation_id: str) -> MemberOperations: | ||
| """Get member operations for a conversation. | ||
|
|
||
| Args: | ||
| conversation_id: The ID of the conversation. | ||
|
|
||
| Returns: | ||
| An operations object for managing members in the conversation. | ||
| """ | ||
| return MemberOperations(self, conversation_id) | ||
|
|
||
| async def get(self, params: Optional[GetConversationsParams] = None) -> GetConversationsResponse: | ||
| """Get a list of conversations. | ||
|
|
||
| Args: | ||
| params: Optional parameters for getting conversations. | ||
|
|
||
| Returns: | ||
| A response containing the list of conversations and a continuation token. | ||
| """ | ||
| query_params = {} | ||
| if params and params.continuation_token: | ||
| query_params["continuationToken"] = params.continuation_token | ||
|
|
||
| response = await self.http.get( | ||
| f"{self.service_url}/v3/conversations", | ||
| params=query_params, | ||
| ) | ||
| return GetConversationsResponse.model_validate(response.json()) | ||
|
|
||
| async def create(self, params: CreateConversationParams) -> ConversationResource: | ||
| """Create a new conversation. | ||
|
|
||
| Args: | ||
| params: Parameters for creating the conversation. | ||
|
|
||
| Returns: | ||
| The created conversation resource. | ||
| """ | ||
| response = await self.http.post( | ||
| f"{self.service_url}/v3/conversations", | ||
| json=params.model_dump(by_alias=True), | ||
| ) | ||
| return ConversationResource.model_validate(response.json()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.