Skip to content

Commit 81f1f5c

Browse files
Add manage conversation after sending message
1 parent 7c8cb3d commit 81f1f5c

7 files changed

Lines changed: 60 additions & 4 deletions

File tree

linkedapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
from linkedapi.types import __all__ as _types_all
7272
from linkedapi.webhooks import parse_webhook_event
7373

74-
__version__ = "1.1.2"
74+
__version__ = "1.1.3"
7575
PredefinedOperation = Operation
7676

7777
__all__ = [

linkedapi/mappers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from linkedapi.mappers.array import ArrayWorkflowMapper
22
from linkedapi.mappers.base import BaseMapper, MappedResponse
3+
from linkedapi.mappers.send_message import SendMessageMapper
34
from linkedapi.mappers.simple import SimpleWorkflowMapper
45
from linkedapi.mappers.then import ActionConfig, ResponseMapping, ThenWorkflowMapper
56
from linkedapi.mappers.void import VoidWorkflowMapper
@@ -10,6 +11,7 @@
1011
"BaseMapper",
1112
"MappedResponse",
1213
"ResponseMapping",
14+
"SendMessageMapper",
1315
"SimpleWorkflowMapper",
1416
"ThenWorkflowMapper",
1517
"VoidWorkflowMapper",

linkedapi/mappers/send_message.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
5+
from linkedapi.mappers.base import (
6+
BaseMapper,
7+
MappedResponse,
8+
as_action_dict,
9+
collect_action_errors,
10+
)
11+
from linkedapi.types import WorkflowCompletion, WorkflowDefinition, serialize_model
12+
from linkedapi.types.message import SendMessageParams
13+
14+
15+
class SendMessageMapper(BaseMapper[SendMessageParams, None]):
16+
def map_request(self, params: SendMessageParams | None = None) -> WorkflowDefinition:
17+
serialized = serialize_model(params)
18+
manage_conversation = serialized.pop("manageConversation", None)
19+
definition: dict[str, Any] = {"actionType": "st.sendMessage", **serialized}
20+
# The child st.manageConversation acts on the conversation this message was sent into, so it
21+
# carries only `operation` — no threadId. Core rejects a threadId on a child manageConversation.
22+
# Guard on `operation` so an empty passthrough (e.g. Make sending {"operation": ""}) is ignored.
23+
if manage_conversation and manage_conversation.get("operation"):
24+
definition["then"] = {
25+
"actionType": "st.manageConversation",
26+
"operation": manage_conversation["operation"],
27+
}
28+
return definition
29+
30+
def map_response(self, completion: WorkflowCompletion) -> MappedResponse[None]:
31+
if isinstance(completion, list):
32+
errors = collect_action_errors(
33+
[as_action_dict(action).get("error") for action in completion]
34+
)
35+
return MappedResponse(data=None, errors=errors)
36+
37+
action = as_action_dict(completion)
38+
raw_errors: list[Any] = [action.get("error")]
39+
40+
single_data = action.get("data")
41+
if single_data is not None:
42+
then_actions = as_action_dict(single_data).get("then")
43+
if then_actions:
44+
child_actions = then_actions if isinstance(then_actions, list) else [then_actions]
45+
raw_errors.extend(as_action_dict(child).get("error") for child in child_actions)
46+
47+
return MappedResponse(data=None, errors=collect_action_errors(raw_errors))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

33
from linkedapi.core import Operation
4-
from linkedapi.mappers import VoidWorkflowMapper
4+
from linkedapi.mappers import SendMessageMapper
55
from linkedapi.types import SendMessageParams
66

77

88
class SendMessage(Operation[SendMessageParams, None]):
99
"""Send a standard LinkedIn message."""
1010

1111
operation_name = "sendMessage"
12-
mapper = VoidWorkflowMapper[SendMessageParams]("st.sendMessage")
12+
mapper = SendMessageMapper()

linkedapi/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
NvSendMessageParams,
111111
NvSyncConversationParams,
112112
NvSyncInboxParams,
113+
SendMessageManageConversation,
113114
SendMessageParams,
114115
SyncConversationParams,
115116
SyncInboxParams,
@@ -375,6 +376,7 @@
375376
"SearchPeopleResult",
376377
"SeatType",
377378
"SendConnectionRequestParams",
379+
"SendMessageManageConversation",
378380
"SendMessageParams",
379381
"SetLimitEntry",
380382
"SetLimitsParams",

linkedapi/types/message.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
MessageSender = Literal["us", "them"]
1010

1111

12+
class SendMessageManageConversation(LinkedApiModel):
13+
operation: str
14+
15+
1216
class SendMessageParams(BaseActionParams):
1317
text: str
1418
person_url: str | None = None
1519
thread_id: str | None = None
20+
manage_conversation: SendMessageManageConversation | None = None
1621

1722

1823
class SyncConversationParams(BaseActionParams):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "linkedapi"
7-
version = "1.1.2"
7+
version = "1.1.3"
88
description = "Official synchronous Python SDK for Linked API."
99
readme = "README.md"
1010
requires-python = ">=3.10"

0 commit comments

Comments
 (0)