@inkbox/sdk 0.4.5 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +163 -36
  2. package/dist/_http.d.ts +12 -0
  3. package/dist/_http.d.ts.map +1 -1
  4. package/dist/_http.js +23 -2
  5. package/dist/_http.js.map +1 -1
  6. package/dist/agent_identity.d.ts +138 -6
  7. package/dist/agent_identity.d.ts.map +1 -1
  8. package/dist/agent_identity.js +155 -5
  9. package/dist/agent_identity.js.map +1 -1
  10. package/dist/identities/resources/identities.d.ts +11 -1
  11. package/dist/identities/resources/identities.d.ts.map +1 -1
  12. package/dist/identities/resources/identities.js +14 -1
  13. package/dist/identities/resources/identities.js.map +1 -1
  14. package/dist/identities/types.d.ts +15 -6
  15. package/dist/identities/types.d.ts.map +1 -1
  16. package/dist/identities/types.js +2 -4
  17. package/dist/identities/types.js.map +1 -1
  18. package/dist/imessage/resources/contactRules.d.ts +55 -0
  19. package/dist/imessage/resources/contactRules.d.ts.map +1 -0
  20. package/dist/imessage/resources/contactRules.js +85 -0
  21. package/dist/imessage/resources/contactRules.js.map +1 -0
  22. package/dist/imessage/resources/imessages.d.ts +168 -0
  23. package/dist/imessage/resources/imessages.d.ts.map +1 -0
  24. package/dist/imessage/resources/imessages.js +238 -0
  25. package/dist/imessage/resources/imessages.js.map +1 -0
  26. package/dist/imessage/types.d.ts +335 -0
  27. package/dist/imessage/types.d.ts.map +1 -0
  28. package/dist/imessage/types.js +209 -0
  29. package/dist/imessage/types.js.map +1 -0
  30. package/dist/index.d.ts +7 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/inkbox.d.ts +25 -0
  35. package/dist/inkbox.d.ts.map +1 -1
  36. package/dist/inkbox.js +32 -0
  37. package/dist/inkbox.js.map +1 -1
  38. package/dist/mail/resources/mailboxes.d.ts +2 -3
  39. package/dist/mail/resources/mailboxes.d.ts.map +1 -1
  40. package/dist/mail/resources/mailboxes.js +2 -5
  41. package/dist/mail/resources/mailboxes.js.map +1 -1
  42. package/dist/mail/types.d.ts +10 -2
  43. package/dist/mail/types.d.ts.map +1 -1
  44. package/dist/mail/types.js +0 -1
  45. package/dist/mail/types.js.map +1 -1
  46. package/dist/phone/resources/numbers.d.ts +0 -2
  47. package/dist/phone/resources/numbers.d.ts.map +1 -1
  48. package/dist/phone/resources/numbers.js +0 -6
  49. package/dist/phone/resources/numbers.js.map +1 -1
  50. package/dist/phone/resources/texts.d.ts +5 -5
  51. package/dist/phone/resources/texts.js +5 -5
  52. package/dist/phone/types.d.ts +15 -2
  53. package/dist/phone/types.d.ts.map +1 -1
  54. package/dist/phone/types.js +0 -1
  55. package/dist/phone/types.js.map +1 -1
  56. package/dist/webhooks/index.d.ts +8 -0
  57. package/dist/webhooks/index.d.ts.map +1 -0
  58. package/dist/webhooks/index.js +8 -0
  59. package/dist/webhooks/index.js.map +1 -0
  60. package/dist/webhooks/subscriptions.d.ts +96 -0
  61. package/dist/webhooks/subscriptions.d.ts.map +1 -0
  62. package/dist/webhooks/subscriptions.js +168 -0
  63. package/dist/webhooks/subscriptions.js.map +1 -0
  64. package/dist/webhooks/types.d.ts +173 -11
  65. package/dist/webhooks/types.d.ts.map +1 -1
  66. package/package.json +1 -1
@@ -0,0 +1,85 @@
1
+ /**
2
+ * inkbox-imessage/resources/contactRules.ts
3
+ *
4
+ * Per-identity iMessage contact rules (allow/block) + org-wide list.
5
+ *
6
+ * Shared iMessage pool numbers are global infrastructure, so the policy
7
+ * owner is the agent identity being reached — rules are addressed by
8
+ * `agentHandle`, not by a phone-number id.
9
+ */
10
+ import { IMessageRuleMatchType, parseIMessageContactRule, } from "../types.js";
11
+ const ORG_BASE = "/contact-rules";
12
+ function rulePath(agentHandle, ruleId) {
13
+ const base = `/identities/${agentHandle}/contact-rules`;
14
+ return ruleId ? `${base}/${ruleId}` : base;
15
+ }
16
+ export class IMessageContactRulesResource {
17
+ http;
18
+ constructor(http) {
19
+ this.http = http;
20
+ }
21
+ async list(agentHandle, options = {}) {
22
+ const params = {};
23
+ if (options.action !== undefined)
24
+ params.action = options.action;
25
+ if (options.matchType !== undefined)
26
+ params.match_type = options.matchType;
27
+ if (options.limit !== undefined)
28
+ params.limit = options.limit;
29
+ if (options.offset !== undefined)
30
+ params.offset = options.offset;
31
+ const data = await this.http.get(rulePath(agentHandle), params);
32
+ return data.map(parseIMessageContactRule);
33
+ }
34
+ async get(agentHandle, ruleId) {
35
+ const data = await this.http.get(rulePath(agentHandle, ruleId));
36
+ return parseIMessageContactRule(data);
37
+ }
38
+ /**
39
+ * Create a rule. New rules are always `active`; use {@link update}
40
+ * to pause one after creation.
41
+ *
42
+ * @throws {DuplicateContactRuleError} 409 when a non-deleted rule with
43
+ * the same `(matchType, matchTarget)` already exists.
44
+ */
45
+ async create(agentHandle, options) {
46
+ const body = {
47
+ action: options.action,
48
+ match_type: options.matchType ?? IMessageRuleMatchType.EXACT_NUMBER,
49
+ match_target: options.matchTarget,
50
+ };
51
+ const data = await this.http.post(rulePath(agentHandle), body);
52
+ return parseIMessageContactRule(data);
53
+ }
54
+ /** Update `action` or `status` (admin-only). */
55
+ async update(agentHandle, ruleId, options) {
56
+ const body = {};
57
+ if (options.action !== undefined)
58
+ body.action = options.action;
59
+ if (options.status !== undefined)
60
+ body.status = options.status;
61
+ const data = await this.http.patch(rulePath(agentHandle, ruleId), body);
62
+ return parseIMessageContactRule(data);
63
+ }
64
+ /** Delete a rule (admin-only). */
65
+ async delete(agentHandle, ruleId) {
66
+ await this.http.delete(rulePath(agentHandle, ruleId));
67
+ }
68
+ /** Org-wide list of iMessage contact rules (admin-only). */
69
+ async listAll(options = {}) {
70
+ const params = {};
71
+ if (options.agentIdentityId !== undefined)
72
+ params.agent_identity_id = options.agentIdentityId;
73
+ if (options.action !== undefined)
74
+ params.action = options.action;
75
+ if (options.matchType !== undefined)
76
+ params.match_type = options.matchType;
77
+ if (options.limit !== undefined)
78
+ params.limit = options.limit;
79
+ if (options.offset !== undefined)
80
+ params.offset = options.offset;
81
+ const data = await this.http.get(ORG_BASE, params);
82
+ return data.map(parseIMessageContactRule);
83
+ }
84
+ }
85
+ //# sourceMappingURL=contactRules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contactRules.js","sourceRoot":"","sources":["../../../src/imessage/resources/contactRules.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAGL,qBAAqB,EAErB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAErB,MAAM,QAAQ,GAAG,gBAAgB,CAAC;AAElC,SAAS,QAAQ,CAAC,WAAmB,EAAE,MAAe;IACpD,MAAM,IAAI,GAAG,eAAe,WAAW,gBAAgB,CAAC;IACxD,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC;AA4BD,MAAM,OAAO,4BAA4B;IACV;IAA7B,YAA6B,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;IAAG,CAAC;IAEpD,KAAK,CAAC,IAAI,CACR,WAAmB,EACnB,UAA2C,EAAE;QAE7C,MAAM,MAAM,GAAgD,EAAE,CAAC;QAC/D,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;YAAE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QACjE,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS;YAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;QAC3E,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9D,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;YAAE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QACjE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,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CAAC,CAAC;IACxC,CAAC;IAED,kCAAkC;IAClC,KAAK,CAAC,MAAM,CAAC,WAAmB,EAAE,MAAc;QAC9C,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO,CACX,UAA8C,EAAE;QAEhD,MAAM,MAAM,GAAgD,EAAE,CAAC;QAC/D,IAAI,OAAO,CAAC,eAAe,KAAK,SAAS;YAAE,MAAM,CAAC,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC;QAC9F,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;YAAE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QACjE,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS;YAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;QAC3E,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9D,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;YAAE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QACjE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAA2B,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC7E,OAAO,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * inkbox-imessage/resources/imessages.ts
3
+ *
4
+ * iMessage operations: send, list, conversations, reactions, read
5
+ * receipts, typing indicators, media upload.
6
+ *
7
+ * Unlike SMS, iMessage is not scoped to an org-owned phone number.
8
+ * Recipients are connected to an agent identity over a shared pool
9
+ * line by triage, so every method here keys off `conversationId` /
10
+ * `agentIdentityId` rather than a `phoneNumberId`.
11
+ */
12
+ import { HttpTransport } from "../../_http.js";
13
+ import { IMessage, IMessageAssignment, IMessageConversation, IMessageConversationSummary, IMessageMarkReadResult, IMessageMediaUpload, IMessageReaction, IMessageReactionType, IMessageSendStyle, IMessageTriageNumber } from "../types.js";
14
+ export declare class IMessagesResource {
15
+ private readonly http;
16
+ constructor(http: HttpTransport);
17
+ /**
18
+ * Return the active triage line and the connect command.
19
+ *
20
+ * Recipients text the returned `connectCommand` (e.g.
21
+ * `connect @your-handle`) to the triage `number` to get connected to
22
+ * an agent identity. Resolve this at runtime instead of hardcoding
23
+ * the number — the line can change.
24
+ *
25
+ * @throws {InkboxAPIError} 404 when no triage line is active.
26
+ */
27
+ getTriageNumber(): Promise<IMessageTriageNumber>;
28
+ /**
29
+ * Send an outbound iMessage through an existing assignment.
30
+ *
31
+ * Sends only work toward recipients that triage has already connected
32
+ * to the agent identity — there is no cold outreach over iMessage.
33
+ * Inbound replies and reactions arrive via identity-owned webhook
34
+ * subscriptions (`inkbox.webhooks.subscriptions.create({
35
+ * agentIdentityId, url, eventTypes: ["imessage.received", ...] })`).
36
+ *
37
+ * @param options.to - E.164 recipient number. Mutually exclusive with
38
+ * `conversationId`.
39
+ * @param options.conversationId - Existing conversation UUID to reply into.
40
+ * @param options.text - Message body.
41
+ * @param options.mediaUrls - Media URLs (at most one). Use
42
+ * {@link uploadMedia} to turn raw bytes into a sendable URL first.
43
+ * @param options.sendStyle - Optional expressive send style.
44
+ * @param options.agentIdentityId - Identity to send as. Required for
45
+ * org-wide API keys when sending by `to`; ignored for
46
+ * identity-scoped keys (the key's identity wins).
47
+ *
48
+ * @throws {InkboxAPIError} 400 when the identity is not
49
+ * iMessage-enabled; 403 when the recipient is blocked by a contact
50
+ * rule.
51
+ */
52
+ send(options: {
53
+ to?: string | null;
54
+ conversationId?: string | null;
55
+ text?: string | null;
56
+ mediaUrls?: string[] | null;
57
+ sendStyle?: IMessageSendStyle | string | null;
58
+ agentIdentityId?: string | null;
59
+ }): Promise<IMessage>;
60
+ /**
61
+ * List iMessages visible to the caller, newest first.
62
+ *
63
+ * Identity-scoped API keys never see contact-rule-blocked rows
64
+ * regardless of `isBlocked` (filtered server-side). Admin/JWT callers
65
+ * see everything by default.
66
+ *
67
+ * @param options.agentIdentityId - Narrow to one agent identity.
68
+ * Ignored for identity-scoped keys (always their own identity).
69
+ * @param options.conversationId - Narrow to one conversation.
70
+ * @param options.limit - Max results (1–200). Defaults to 50.
71
+ * @param options.offset - Pagination offset. Defaults to 0.
72
+ * @param options.isRead - Filter by read state.
73
+ * @param options.isBlocked - Tri-state filter. `true` for only blocked,
74
+ * `false` for only non-blocked, omit for all.
75
+ */
76
+ list(options?: {
77
+ agentIdentityId?: string;
78
+ conversationId?: string;
79
+ limit?: number;
80
+ offset?: number;
81
+ isRead?: boolean;
82
+ isBlocked?: boolean;
83
+ }): Promise<IMessage[]>;
84
+ /**
85
+ * List active iMessage connections, newest first.
86
+ *
87
+ * One row per recipient currently connected to an agent identity
88
+ * through triage. Released connections are not returned.
89
+ *
90
+ * @param options.agentIdentityId - Narrow to one agent identity.
91
+ * Ignored for identity-scoped keys (always their own identity).
92
+ * @param options.limit - Max results (1–200). Defaults to 50.
93
+ * @param options.offset - Pagination offset. Defaults to 0.
94
+ */
95
+ listAssignments(options?: {
96
+ agentIdentityId?: string;
97
+ limit?: number;
98
+ offset?: number;
99
+ }): Promise<IMessageAssignment[]>;
100
+ /**
101
+ * List iMessage conversations with latest-message preview.
102
+ *
103
+ * @param options.agentIdentityId - Narrow to one agent identity.
104
+ * Ignored for identity-scoped keys (always their own identity).
105
+ * @param options.limit - Max results (1–200). Defaults to 50.
106
+ * @param options.offset - Pagination offset. Defaults to 0.
107
+ * @param options.isBlocked - Tri-state filter applied to the
108
+ * underlying messages. `true` for only blocked, `false` for only
109
+ * non-blocked, omit for all.
110
+ */
111
+ listConversations(options?: {
112
+ agentIdentityId?: string;
113
+ limit?: number;
114
+ offset?: number;
115
+ isBlocked?: boolean;
116
+ }): Promise<IMessageConversationSummary[]>;
117
+ /**
118
+ * Get one iMessage conversation by ID.
119
+ *
120
+ * @param conversationId - UUID of the conversation.
121
+ * @param options.agentIdentityId - Optional identity assertion; 404s
122
+ * when the conversation belongs to a different identity.
123
+ */
124
+ getConversation(conversationId: string, options?: {
125
+ agentIdentityId?: string;
126
+ }): Promise<IMessageConversation>;
127
+ /**
128
+ * Send a tapback reaction to a message.
129
+ *
130
+ * @param options.messageId - UUID of the message being reacted to.
131
+ * @param options.reaction - Tapback kind. Sends accept the classic
132
+ * six; `custom` is inbound-only and rejected with 422.
133
+ * @param options.partIndex - Part of a multi-part message to react to.
134
+ * Defaults to 0.
135
+ */
136
+ sendReaction(options: {
137
+ messageId: string;
138
+ reaction: IMessageReactionType | string;
139
+ partIndex?: number;
140
+ }): Promise<IMessageReaction>;
141
+ /**
142
+ * Send a read receipt and mark inbound messages read locally.
143
+ *
144
+ * @param conversationId - UUID of the conversation.
145
+ * @returns Object with `conversationId` and `updatedCount`.
146
+ */
147
+ markConversationRead(conversationId: string): Promise<IMessageMarkReadResult>;
148
+ /**
149
+ * Show a typing indicator to the conversation's recipient.
150
+ *
151
+ * @param conversationId - UUID of the conversation.
152
+ */
153
+ sendTyping(conversationId: string): Promise<void>;
154
+ /**
155
+ * Upload media and get back a URL usable in `mediaUrls`.
156
+ *
157
+ * @param options.content - Raw file bytes (max 10 MiB).
158
+ * @param options.filename - Original filename, used for type inference.
159
+ * @param options.contentType - Optional MIME type; defaults
160
+ * server-side to `application/octet-stream`.
161
+ */
162
+ uploadMedia(options: {
163
+ content: Uint8Array | Blob;
164
+ filename: string;
165
+ contentType?: string;
166
+ }): Promise<IMessageMediaUpload>;
167
+ }
168
+ //# sourceMappingURL=imessages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imessages.d.ts","sourceRoot":"","sources":["../../../src/imessage/resources/imessages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB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MAAM,CAAC;KACjB,GACA,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAYhC;;;;;;;;;;OAUG;IACG,iBAAiB,CACrB,OAAO,CAAC,EAAE;QACR,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,GACA,OAAO,CAAC,2BAA2B,EAAE,CAAC;IAkBzC;;;;;;OAMG;IACG,eAAe,CACnB,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GACrC,OAAO,CAAC,oBAAoB,CAAC;IAYhC;;;;;;;;OAQG;IACG,YAAY,CAAC,OAAO,EAAE;QAC1B,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAAC;QACxC,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAS7B;;;;;OAKG;IACG,oBAAoB,CACxB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,sBAAsB,CAAC;IAWlC;;;;OAIG;IACG,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD;;;;;;;OAOG;IACG,WAAW,CAAC,OAAO,EAAE;QACzB,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;QAC3B,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAiBjC"}
@@ -0,0 +1,238 @@
1
+ /**
2
+ * inkbox-imessage/resources/imessages.ts
3
+ *
4
+ * iMessage operations: send, list, conversations, reactions, read
5
+ * receipts, typing indicators, media upload.
6
+ *
7
+ * Unlike SMS, iMessage is not scoped to an org-owned phone number.
8
+ * Recipients are connected to an agent identity over a shared pool
9
+ * line by triage, so every method here keys off `conversationId` /
10
+ * `agentIdentityId` rather than a `phoneNumberId`.
11
+ */
12
+ import { parseIMessage, parseIMessageAssignment, parseIMessageConversation, parseIMessageConversationSummary, parseIMessageReaction, parseIMessageTriageNumber, } from "../types.js";
13
+ export class IMessagesResource {
14
+ http;
15
+ constructor(http) {
16
+ this.http = http;
17
+ }
18
+ /**
19
+ * Return the active triage line and the connect command.
20
+ *
21
+ * Recipients text the returned `connectCommand` (e.g.
22
+ * `connect @your-handle`) to the triage `number` to get connected to
23
+ * an agent identity. Resolve this at runtime instead of hardcoding
24
+ * the number — the line can change.
25
+ *
26
+ * @throws {InkboxAPIError} 404 when no triage line is active.
27
+ */
28
+ async getTriageNumber() {
29
+ const data = await this.http.get("/triage-number");
30
+ return parseIMessageTriageNumber(data);
31
+ }
32
+ /**
33
+ * Send an outbound iMessage through an existing assignment.
34
+ *
35
+ * Sends only work toward recipients that triage has already connected
36
+ * to the agent identity — there is no cold outreach over iMessage.
37
+ * Inbound replies and reactions arrive via identity-owned webhook
38
+ * subscriptions (`inkbox.webhooks.subscriptions.create({
39
+ * agentIdentityId, url, eventTypes: ["imessage.received", ...] })`).
40
+ *
41
+ * @param options.to - E.164 recipient number. Mutually exclusive with
42
+ * `conversationId`.
43
+ * @param options.conversationId - Existing conversation UUID to reply into.
44
+ * @param options.text - Message body.
45
+ * @param options.mediaUrls - Media URLs (at most one). Use
46
+ * {@link uploadMedia} to turn raw bytes into a sendable URL first.
47
+ * @param options.sendStyle - Optional expressive send style.
48
+ * @param options.agentIdentityId - Identity to send as. Required for
49
+ * org-wide API keys when sending by `to`; ignored for
50
+ * identity-scoped keys (the key's identity wins).
51
+ *
52
+ * @throws {InkboxAPIError} 400 when the identity is not
53
+ * iMessage-enabled; 403 when the recipient is blocked by a contact
54
+ * rule.
55
+ */
56
+ async send(options) {
57
+ const body = {};
58
+ if (options.to != null) {
59
+ body.to = options.to;
60
+ }
61
+ if (options.conversationId != null) {
62
+ body.conversation_id = options.conversationId;
63
+ }
64
+ if (options.text != null) {
65
+ body.text = options.text;
66
+ }
67
+ if (options.mediaUrls != null) {
68
+ body.media_urls = options.mediaUrls;
69
+ }
70
+ if (options.sendStyle != null) {
71
+ body.send_style = options.sendStyle;
72
+ }
73
+ const params = {};
74
+ if (options.agentIdentityId != null) {
75
+ params["agent_identity_id"] = options.agentIdentityId;
76
+ }
77
+ const data = await this.http.post("/messages", body, { params });
78
+ return parseIMessage(data.message);
79
+ }
80
+ /**
81
+ * List iMessages visible to the caller, newest first.
82
+ *
83
+ * Identity-scoped API keys never see contact-rule-blocked rows
84
+ * regardless of `isBlocked` (filtered server-side). Admin/JWT callers
85
+ * see everything by default.
86
+ *
87
+ * @param options.agentIdentityId - Narrow to one agent identity.
88
+ * Ignored for identity-scoped keys (always their own identity).
89
+ * @param options.conversationId - Narrow to one conversation.
90
+ * @param options.limit - Max results (1–200). Defaults to 50.
91
+ * @param options.offset - Pagination offset. Defaults to 0.
92
+ * @param options.isRead - Filter by read state.
93
+ * @param options.isBlocked - Tri-state filter. `true` for only blocked,
94
+ * `false` for only non-blocked, omit for all.
95
+ */
96
+ async list(options) {
97
+ const params = {
98
+ limit: options?.limit ?? 50,
99
+ offset: options?.offset ?? 0,
100
+ };
101
+ if (options?.agentIdentityId !== undefined) {
102
+ params["agent_identity_id"] = options.agentIdentityId;
103
+ }
104
+ if (options?.conversationId !== undefined) {
105
+ params["conversation_id"] = options.conversationId;
106
+ }
107
+ if (options?.isRead !== undefined) {
108
+ params["is_read"] = options.isRead;
109
+ }
110
+ if (options?.isBlocked !== undefined) {
111
+ params["is_blocked"] = options.isBlocked;
112
+ }
113
+ const data = await this.http.get("/messages", params);
114
+ return data.map(parseIMessage);
115
+ }
116
+ /**
117
+ * List active iMessage connections, newest first.
118
+ *
119
+ * One row per recipient currently connected to an agent identity
120
+ * through triage. Released connections are not returned.
121
+ *
122
+ * @param options.agentIdentityId - Narrow to one agent identity.
123
+ * Ignored for identity-scoped keys (always their own identity).
124
+ * @param options.limit - Max results (1–200). Defaults to 50.
125
+ * @param options.offset - Pagination offset. Defaults to 0.
126
+ */
127
+ async listAssignments(options) {
128
+ const params = {
129
+ limit: options?.limit ?? 50,
130
+ offset: options?.offset ?? 0,
131
+ };
132
+ if (options?.agentIdentityId !== undefined) {
133
+ params["agent_identity_id"] = options.agentIdentityId;
134
+ }
135
+ const data = await this.http.get("/assignments", params);
136
+ return data.map(parseIMessageAssignment);
137
+ }
138
+ /**
139
+ * List iMessage conversations with latest-message preview.
140
+ *
141
+ * @param options.agentIdentityId - Narrow to one agent identity.
142
+ * Ignored for identity-scoped keys (always their own identity).
143
+ * @param options.limit - Max results (1–200). Defaults to 50.
144
+ * @param options.offset - Pagination offset. Defaults to 0.
145
+ * @param options.isBlocked - Tri-state filter applied to the
146
+ * underlying messages. `true` for only blocked, `false` for only
147
+ * non-blocked, omit for all.
148
+ */
149
+ async listConversations(options) {
150
+ const params = {
151
+ limit: options?.limit ?? 50,
152
+ offset: options?.offset ?? 0,
153
+ };
154
+ if (options?.agentIdentityId !== undefined) {
155
+ params["agent_identity_id"] = options.agentIdentityId;
156
+ }
157
+ if (options?.isBlocked !== undefined) {
158
+ params["is_blocked"] = options.isBlocked;
159
+ }
160
+ const data = await this.http.get("/conversations", params);
161
+ return data.map(parseIMessageConversationSummary);
162
+ }
163
+ /**
164
+ * Get one iMessage conversation by ID.
165
+ *
166
+ * @param conversationId - UUID of the conversation.
167
+ * @param options.agentIdentityId - Optional identity assertion; 404s
168
+ * when the conversation belongs to a different identity.
169
+ */
170
+ async getConversation(conversationId, options) {
171
+ const params = {};
172
+ if (options?.agentIdentityId !== undefined) {
173
+ params["agent_identity_id"] = options.agentIdentityId;
174
+ }
175
+ const data = await this.http.get(`/conversations/${conversationId}`, params);
176
+ return parseIMessageConversation(data);
177
+ }
178
+ /**
179
+ * Send a tapback reaction to a message.
180
+ *
181
+ * @param options.messageId - UUID of the message being reacted to.
182
+ * @param options.reaction - Tapback kind. Sends accept the classic
183
+ * six; `custom` is inbound-only and rejected with 422.
184
+ * @param options.partIndex - Part of a multi-part message to react to.
185
+ * Defaults to 0.
186
+ */
187
+ async sendReaction(options) {
188
+ const data = await this.http.post("/reactions", {
189
+ message_id: options.messageId,
190
+ reaction: options.reaction,
191
+ part_index: options.partIndex ?? 0,
192
+ });
193
+ return parseIMessageReaction(data);
194
+ }
195
+ /**
196
+ * Send a read receipt and mark inbound messages read locally.
197
+ *
198
+ * @param conversationId - UUID of the conversation.
199
+ * @returns Object with `conversationId` and `updatedCount`.
200
+ */
201
+ async markConversationRead(conversationId) {
202
+ const data = await this.http.post("/mark-read", { conversation_id: conversationId });
203
+ return {
204
+ conversationId: data.conversation_id,
205
+ updatedCount: data.updated_count,
206
+ };
207
+ }
208
+ /**
209
+ * Show a typing indicator to the conversation's recipient.
210
+ *
211
+ * @param conversationId - UUID of the conversation.
212
+ */
213
+ async sendTyping(conversationId) {
214
+ await this.http.post("/typing", { conversation_id: conversationId });
215
+ }
216
+ /**
217
+ * Upload media and get back a URL usable in `mediaUrls`.
218
+ *
219
+ * @param options.content - Raw file bytes (max 10 MiB).
220
+ * @param options.filename - Original filename, used for type inference.
221
+ * @param options.contentType - Optional MIME type; defaults
222
+ * server-side to `application/octet-stream`.
223
+ */
224
+ async uploadMedia(options) {
225
+ const data = await this.http.postMultipart("/media", {
226
+ fieldName: "file",
227
+ filename: options.filename,
228
+ content: options.content,
229
+ contentType: options.contentType ?? "application/octet-stream",
230
+ });
231
+ return {
232
+ mediaUrl: data.media_url,
233
+ contentType: data.content_type ?? null,
234
+ size: data.size ?? null,
235
+ };
236
+ }
237
+ }
238
+ //# sourceMappingURL=imessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imessages.js","sourceRoot":"","sources":["../../../src/imessage/resources/imessages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAiBL,aAAa,EACb,uBAAuB,EACvB,yBAAyB,EACzB,gCAAgC,EAChC,q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