@proteos/sdk 0.91.0 → 0.92.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteos/sdk",
3
- "version": "0.91.0",
3
+ "version": "0.92.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "TypeScript SDK for the Proteos platform",
6
6
  "repository": {
@@ -108,6 +108,8 @@ export const PLATFORM_ENTITIES: readonly PlatformEntity[] = [
108
108
  // their preset catalog.
109
109
  { slug: 'sending-rules', name: 'Sending Rules' },
110
110
  { slug: 'email-signatures', name: 'Email Signatures' },
111
+ // Reusable messages and snippets, the organisation's and each person's own.
112
+ { slug: 'message-templates', name: 'Message Templates' },
111
113
  // The channel_action ledger: acts through a connection that are neither a
112
114
  // message nor a reaction (LinkedIn invitations, profile visits, InMail).
113
115
  { slug: 'channel-actions', name: 'Channel Actions' },
@@ -50,6 +50,7 @@ import type {
50
50
  CreateConversationTypeRequest,
51
51
  CreateEmailSignatureRequest,
52
52
  CreateGlossaryTermRequest,
53
+ CreateMessageTemplateRequest,
53
54
  CreateSendingRuleRequest,
54
55
  CreateToneProfileSetupRequest,
55
56
  CreateTranscriptionFromTextRequest,
@@ -92,6 +93,7 @@ import type {
92
93
  ListGlossaryTermsQuery,
93
94
  ListMeetingBotsQuery,
94
95
  ListMessagesQuery,
96
+ ListMessageTemplatesQuery,
95
97
  ListMistranscribedTermsQuery,
96
98
  ListReactionsResponse,
97
99
  ListResponse,
@@ -107,12 +109,15 @@ import type {
107
109
  Message,
108
110
  MessageDraftVersions,
109
111
  MessageSignature,
112
+ MessageTemplate,
110
113
  MintCallTokenRequest,
111
114
  MistranscribedTerm,
112
115
  PerformChannelActionRequest,
113
116
  PhoneNumber,
114
117
  Reaction,
115
118
  RecordPermissionEventRequest,
119
+ RenderedMessageTemplate,
120
+ RenderMessageTemplateRequest,
116
121
  ResolveEmailSignatureQuery,
117
122
  ResolveToneProfileQuery,
118
123
  RespondChannelActionRequest,
@@ -146,6 +151,7 @@ import type {
146
151
  UpdateDraftRequest,
147
152
  UpdateEmailSignatureRequest,
148
153
  UpdateGlossaryTermRequest,
154
+ UpdateMessageTemplateRequest,
149
155
  UpdatePhoneNumberRequest,
150
156
  UpdateSendingRuleRequest,
151
157
  UpdateTranscriptionRequest,
@@ -177,6 +183,8 @@ export class ConversationClient {
177
183
  /** Outbound send constraints: windows, connection limits, frequency caps + presets. */
178
184
  readonly sendingRules: SendingRuleService
179
185
  readonly emailSignatures: EmailSignatureService
186
+ /** Reusable messages and snippets, and rendering one for a recipient. */
187
+ readonly messageTemplates: MessageTemplateService
180
188
  /**
181
189
  * Channel actions: acts performed through a connection that are neither a
182
190
  * message nor a reaction — LinkedIn invitations, profile visits, InMail.
@@ -225,6 +233,7 @@ export class ConversationClient {
225
233
  this.conversationFilters = new ConversationFilterServiceImpl(client)
226
234
  this.sendingRules = new SendingRuleServiceImpl(client)
227
235
  this.emailSignatures = new EmailSignatureServiceImpl(client)
236
+ this.messageTemplates = new MessageTemplateServiceImpl(client)
228
237
  this.channelActions = new ChannelActionServiceImpl(client)
229
238
  this.channelEvents = new ChannelEventServiceImpl(client)
230
239
  this.glossaryTerms = new GlossaryTermServiceImpl(client)
@@ -2026,6 +2035,7 @@ class CallServiceImpl implements CallService {
2026
2035
  }
2027
2036
 
2028
2037
  export type * from './types.js'
2038
+ export { UNSUBSCRIBE_URL_PLACEHOLDER } from './types.js'
2029
2039
  // Re-export voice types (the live dictation stream lives on this service now)
2030
2040
  export type {
2031
2041
  TranscribeStreamOptions,
@@ -2237,6 +2247,82 @@ class EmailSignatureServiceImpl implements EmailSignatureService {
2237
2247
  }
2238
2248
  }
2239
2249
 
2250
+ /**
2251
+ * Message templates: reusable messages and snippets whose subject and body are
2252
+ * Liquid templates. A send or a draft names one with its `template` field.
2253
+ */
2254
+ export interface MessageTemplateService {
2255
+ list(query?: ListMessageTemplatesQuery): Promise<ListResponse<MessageTemplate>>
2256
+ /** By id or by key. */
2257
+ get(idOrKey: string): Promise<MessageTemplate>
2258
+ create(request: CreateMessageTemplateRequest): Promise<MessageTemplate>
2259
+ update(id: string, request: UpdateMessageTemplateRequest): Promise<MessageTemplate>
2260
+ /** Creates or replaces the template a key names; an equivalent body writes nothing. */
2261
+ upsertByKey(
2262
+ key: string,
2263
+ request: Omit<CreateMessageTemplateRequest, 'key'>,
2264
+ ): Promise<MessageTemplate>
2265
+ delete(id: string): Promise<void>
2266
+ /**
2267
+ * Fills in a stored or an inline template: what a send of it would store,
2268
+ * with the signature the email would get.
2269
+ */
2270
+ render(request: RenderMessageTemplateRequest): Promise<RenderedMessageTemplate>
2271
+ }
2272
+
2273
+ class MessageTemplateServiceImpl implements MessageTemplateService {
2274
+ constructor(private readonly client: ProteosClient) {}
2275
+
2276
+ list(query: ListMessageTemplatesQuery = {}): Promise<ListResponse<MessageTemplate>> {
2277
+ return this.client.requestWithQuery('GET', `${CONVERSATION_BASE_PATH}/message-templates`, query)
2278
+ }
2279
+
2280
+ get(idOrKey: string): Promise<MessageTemplate> {
2281
+ return this.client.request(
2282
+ 'GET',
2283
+ `${CONVERSATION_BASE_PATH}/message-templates/${encodeURIComponent(idOrKey)}`,
2284
+ )
2285
+ }
2286
+
2287
+ create(request: CreateMessageTemplateRequest): Promise<MessageTemplate> {
2288
+ return this.client.request('POST', `${CONVERSATION_BASE_PATH}/message-templates`, request)
2289
+ }
2290
+
2291
+ update(id: string, request: UpdateMessageTemplateRequest): Promise<MessageTemplate> {
2292
+ return this.client.request(
2293
+ 'PATCH',
2294
+ `${CONVERSATION_BASE_PATH}/message-templates/${encodeURIComponent(id)}`,
2295
+ request,
2296
+ )
2297
+ }
2298
+
2299
+ upsertByKey(
2300
+ key: string,
2301
+ request: Omit<CreateMessageTemplateRequest, 'key'>,
2302
+ ): Promise<MessageTemplate> {
2303
+ return this.client.request(
2304
+ 'PUT',
2305
+ `${CONVERSATION_BASE_PATH}/message-templates/${encodeURIComponent(key)}`,
2306
+ request,
2307
+ )
2308
+ }
2309
+
2310
+ async delete(id: string): Promise<void> {
2311
+ await this.client.request(
2312
+ 'DELETE',
2313
+ `${CONVERSATION_BASE_PATH}/message-templates/${encodeURIComponent(id)}`,
2314
+ )
2315
+ }
2316
+
2317
+ render(request: RenderMessageTemplateRequest): Promise<RenderedMessageTemplate> {
2318
+ return this.client.request(
2319
+ 'POST',
2320
+ `${CONVERSATION_BASE_PATH}/message-templates/render`,
2321
+ request,
2322
+ )
2323
+ }
2324
+ }
2325
+
2240
2326
  /**
2241
2327
  * Channel actions — the ledger of acts performed through a connection that
2242
2328
  * are neither a message nor a reaction (LinkedIn invitations, profile visits,
@@ -560,6 +560,20 @@ export interface Message {
560
560
  * a send would add now. Never part of `content`.
561
561
  */
562
562
  signature?: MessageSignature
563
+ /**
564
+ * This email is sent with an unsubscribe link of its own. The link exists
565
+ * only in what the recipient gets; `content` keeps `UNSUBSCRIBE_URL_PLACEHOLDER`
566
+ * or nothing.
567
+ */
568
+ has_unsubscribe_link?: boolean
569
+ /** The layout chosen for this email (a message template of kind `layout`). Absent means none. May no longer resolve, which fails the send. */
570
+ layout_id?: string
571
+ /**
572
+ * The frame the email carries around its body. On a sent message, the
573
+ * snapshot of what went out. On a single draft read, what a send would use
574
+ * now. Never part of `content`.
575
+ */
576
+ layout?: MessageLayout
563
577
  /** The platform wrote this message (a send or a draft): its content is what the person wrote, without the quote the email carried. Absent on mail imported from the mailbox. */
564
578
  is_sent_from_platform?: boolean
565
579
  /** The newest entry in this draft's history; absent until its first change. */
@@ -760,6 +774,30 @@ export interface SendMessageRequest {
760
774
  * never part of `content`. Ignored on every channel but email.
761
775
  */
762
776
  signature?: SignatureChoice
777
+ /**
778
+ * Sends a stored message template instead of `content`: its id or key. It is
779
+ * rendered with `variables` at this moment and stored on the message like any
780
+ * content. `subject`, when omitted, is the template's.
781
+ */
782
+ template?: string
783
+ /** The names the template's Liquid reads. Ignored without `template`. */
784
+ variables?: Record<string, unknown>
785
+ /**
786
+ * `link` gives the email an unsubscribe link of its own that records an
787
+ * opt-out in the contact's permission ledger; `none` (or omitted) gives it
788
+ * none. The link replaces every `UNSUBSCRIBE_URL_PLACEHOLDER` in the body
789
+ * (what `{{ unsubscribe_url }}` renders to) and goes into a footer line when
790
+ * the body has none. Email only, to exactly one recipient: anything else is
791
+ * refused with 400 `unsubscribe_not_possible`.
792
+ */
793
+ unsubscribe?: UnsubscribeChoice
794
+ /**
795
+ * Wraps the body in a stored layout when the email is sent: the id or key
796
+ * of a message template of kind `layout`, `none` (or omitted) for no layout.
797
+ * `content` stays as written; the message keeps a snapshot of the layout
798
+ * that went out. Ignored on every channel but email.
799
+ */
800
+ layout?: string
763
801
  /** Reply mode: send into this existing conversation. */
764
802
  conversation_id?: string
765
803
  /**
@@ -881,6 +919,10 @@ export interface UpdateDraftRequest {
881
919
  * carries the `signature` the draft now resolves to.
882
920
  */
883
921
  signature?: SignatureChoice
922
+ /** Replaces the draft's unsubscribe choice. Omit to keep it. */
923
+ unsubscribe?: UnsubscribeChoice
924
+ /** Replaces the draft's layout: `none`, or a layout's id or key. Omit to keep it. */
925
+ layout?: string
884
926
  /** What this edit is in the draft's history. Defaults to `edited`. */
885
927
  version_kind?: Exclude<MessageDraftVersionKind, 'drafted'>
886
928
  /** The reviewer's prompt behind a redraft. */
@@ -2768,6 +2810,13 @@ export interface MergeContactsRequest {
2768
2810
 
2769
2811
  export interface RecordPermissionEventRequest {
2770
2812
  contact_address_id?: string
2813
+ /**
2814
+ * Scopes the event to the contact's address with this value (an email
2815
+ * address, a phone number) when the caller does not know its id. Refused
2816
+ * with 400 when the contact has no such address. Ignored when
2817
+ * `contact_address_id` is set.
2818
+ */
2819
+ address?: string
2771
2820
  event: PermissionEventType
2772
2821
  basis?: string
2773
2822
  source?: PermissionEventSource
@@ -3309,6 +3358,28 @@ export interface MessageSignature {
3309
3358
  text: string
3310
3359
  }
3311
3360
 
3361
+ /** A send's, draft's or draft edit's pick of an unsubscribe link: none, or a link of the email's own. */
3362
+ export type UnsubscribeChoice = 'none' | 'link'
3363
+
3364
+ /**
3365
+ * What `{{ unsubscribe_url }}` renders to before a message exists. A send with
3366
+ * `unsubscribe: 'link'` swaps every occurrence for the recipient's own link;
3367
+ * an email sent without one (a test send, a preview) gets the address of a
3368
+ * page that says so.
3369
+ */
3370
+ export const UNSUBSCRIBE_URL_PLACEHOLDER = 'https://unsubscribe.invalid/link'
3371
+
3372
+ /** The layout an email went out in, as stored on the message: a snapshot, since the layout itself may change or go. */
3373
+ export interface MessageLayout {
3374
+ id: string
3375
+ key?: string
3376
+ name: string
3377
+ /** The frame, with `{{ content }}` where the body goes. */
3378
+ html: string
3379
+ /** The frame of the plain part; absent leaves the text as written. */
3380
+ text?: string
3381
+ }
3382
+
3312
3383
  export interface CreateEmailSignatureRequest {
3313
3384
  name: string
3314
3385
  /** `html` or `text` is required. */
@@ -3343,6 +3414,129 @@ export interface ResolveEmailSignatureQuery {
3343
3414
  is_reply?: boolean
3344
3415
  }
3345
3416
 
3417
+ /**
3418
+ * What a message template holds: a whole message, a piece of a body, or a
3419
+ * layout. A layout is the frame of a designed email: html (and optionally
3420
+ * text) with `{{ content }}` where the body goes. A send names it with
3421
+ * `layout`; it is never sent on its own.
3422
+ */
3423
+ export type MessageTemplateKind = 'message' | 'snippet' | 'layout'
3424
+
3425
+ /**
3426
+ * A reusable message, or a reusable piece of one. `subject`, `html` and `text`
3427
+ * are Liquid templates: `{{ contact.first_name }}` is filled in from the
3428
+ * variables a render or a send passes.
3429
+ *
3430
+ * A template is copied into what uses it (a sequence step, a reply), never
3431
+ * referenced from it. A send that names one renders it at that moment.
3432
+ */
3433
+ export interface MessageTemplate {
3434
+ id: string
3435
+ org_id: string
3436
+ /** The name modules and workflows use; absent for a template nothing refers to. */
3437
+ key?: string
3438
+ name: string
3439
+ description?: string
3440
+ kind: MessageTemplateKind
3441
+ /** The one channel it is written for; absent for any. */
3442
+ channel?: Channel
3443
+ /** The language it is written in, such as `de` or `en-GB`. */
3444
+ language?: string
3445
+ tags: string[]
3446
+ /** A snippet has none. */
3447
+ subject?: string
3448
+ /** Sanitized like every stored email html, its Liquid kept as written. Empty for a text-only template. */
3449
+ html: string
3450
+ /** The plain body; derived from `html` unless `is_text_custom`. */
3451
+ text: string
3452
+ is_text_custom: boolean
3453
+ /** The person it belongs to; absent for the organisation. */
3454
+ owned_by?: UserRef
3455
+ /** The module that deployed it; absent for one made by hand. */
3456
+ module_slug?: string
3457
+ is_archived: boolean
3458
+ created_at: string
3459
+ created_by: UserRef
3460
+ updated_at: string
3461
+ updated_by: UserRef
3462
+ }
3463
+
3464
+ export interface CreateMessageTemplateRequest {
3465
+ key?: string
3466
+ name: string
3467
+ description?: string
3468
+ /** Defaults to `message`. */
3469
+ kind?: MessageTemplateKind
3470
+ /** Empty or omitted writes it for any channel. */
3471
+ channel?: Channel | ''
3472
+ language?: string
3473
+ tags?: string[]
3474
+ subject?: string
3475
+ /** `html` or `text` is required. */
3476
+ html?: string
3477
+ /** Left empty, it is derived from `html`. */
3478
+ text?: string
3479
+ /** Empty or omitted makes it the organisation's. */
3480
+ owned_by_id?: string
3481
+ module_slug?: string
3482
+ is_archived?: boolean
3483
+ }
3484
+
3485
+ /**
3486
+ * Omitted fields keep what is stored. `text` sent empty goes back to being
3487
+ * derived; `key` sent empty takes the name away.
3488
+ */
3489
+ export type UpdateMessageTemplateRequest = Partial<
3490
+ Omit<CreateMessageTemplateRequest, 'module_slug'>
3491
+ >
3492
+
3493
+ export interface ListMessageTemplatesQuery extends PaginationQuery {
3494
+ kind?: MessageTemplateKind
3495
+ /** Also finds templates written for any channel. */
3496
+ channel?: Channel
3497
+ language?: string
3498
+ module_slug?: string
3499
+ tag?: string
3500
+ /** Matches the name, the key and the description. */
3501
+ search?: string
3502
+ owned_by_id?: string
3503
+ /** true: the organisation's own; false: everyone's personal ones. */
3504
+ is_organisation?: boolean
3505
+ /** Archived templates are left out unless this is true. */
3506
+ is_archived?: boolean
3507
+ }
3508
+
3509
+ /**
3510
+ * Fills in a template's variables. `template` names a stored template by id
3511
+ * or key; without it `subject`, `html` and `text` are the template itself.
3512
+ */
3513
+ export interface RenderMessageTemplateRequest {
3514
+ template?: string
3515
+ subject?: string
3516
+ html?: string
3517
+ text?: string
3518
+ /** The names the Liquid reads: `{{ contact.first_name }}` reads `variables.contact.first_name`. */
3519
+ variables?: Record<string, unknown>
3520
+ /** Picked as a send picks it, for `connection_id`, `owned_by_id` and `is_reply`. */
3521
+ signature?: SignatureChoice
3522
+ connection_id?: string
3523
+ owned_by_id?: string
3524
+ is_reply?: boolean
3525
+ /** The layout the email would be sent in: its id or key, `none` or omitted for none. The answer carries it beside the body, which comes back without it. */
3526
+ layout?: string
3527
+ }
3528
+
3529
+ /** What a send of the template would store, and the signature that would go below it. */
3530
+ export interface RenderedMessageTemplate {
3531
+ subject: string
3532
+ /** Sanitized, with the editor's look. Empty for a text-only template. */
3533
+ html: string
3534
+ text: string
3535
+ signature: MessageSignature | null
3536
+ /** The frame the email would go out in, `{{ content }}` marking where the body and the signature go. Null or absent without one. */
3537
+ layout?: MessageLayout | null
3538
+ }
3539
+
3346
3540
  export interface SendingRule {
3347
3541
  id: string
3348
3542
  org_id: string
package/src/index.ts CHANGED
@@ -421,6 +421,7 @@ export type {
421
421
  CreateConversationTypeRequest,
422
422
  CreateEmailSignatureRequest,
423
423
  CreateGlossaryTermRequest,
424
+ CreateMessageTemplateRequest,
424
425
  CreateSendingRuleRequest,
425
426
  CreateToneProfileSetupRequest,
426
427
  CreateTranscriptionFromTextRequest,
@@ -479,6 +480,7 @@ export type {
479
480
  ListGlossaryTermsQuery,
480
481
  ListMeetingBotsQuery,
481
482
  ListMessagesQuery,
483
+ ListMessageTemplatesQuery,
482
484
  ListMistranscribedTermsQuery,
483
485
  // Conversation-local page envelope ({meta, data}) — distinct from the
484
486
  // PageIterator-based ListResult used by the other modules.
@@ -503,11 +505,15 @@ export type {
503
505
  MessageDraftVersion,
504
506
  MessageDraftVersionKind,
505
507
  MessageDraftVersions,
508
+ MessageLayout,
506
509
  MessagePreview,
507
510
  MessageRecipient,
508
511
  MessageService,
509
512
  MessageSignature,
510
513
  MessageStatus,
514
+ MessageTemplate,
515
+ MessageTemplateKind,
516
+ MessageTemplateService,
511
517
  MintCallTokenRequest,
512
518
  MistranscribedTerm,
513
519
  MistranscribedTermService,
@@ -527,6 +533,8 @@ export type {
527
533
  RecipientKind,
528
534
  RecipientRole,
529
535
  RecordPermissionEventRequest,
536
+ RenderedMessageTemplate,
537
+ RenderMessageTemplateRequest,
530
538
  ResolveEmailSignatureQuery,
531
539
  ResolveToneProfileQuery,
532
540
  RespondChannelActionRequest,
@@ -563,6 +571,7 @@ export type {
563
571
  TwilioPhoneVoicemailSettings,
564
572
  UnreadCounts,
565
573
  UnreadCountsQuery,
574
+ UnsubscribeChoice,
566
575
  UpdateAgentListenerRequest,
567
576
  UpdateConnectionRequest,
568
577
  UpdateContactGroupRequest,
@@ -579,6 +588,7 @@ export type {
579
588
  UpdateDraftRequest,
580
589
  UpdateEmailSignatureRequest,
581
590
  UpdateGlossaryTermRequest,
591
+ UpdateMessageTemplateRequest,
582
592
  UpdatePhoneNumberRequest,
583
593
  UpdateSendingRuleRequest,
584
594
  UpsertToneProfileRequest,
@@ -590,7 +600,7 @@ export type {
590
600
  WindowRuleConfig,
591
601
  } from './conversation/index.js'
592
602
  // Conversation client (conversation-service)
593
- export { ConversationClient } from './conversation/index.js'
603
+ export { ConversationClient, UNSUBSCRIBE_URL_PLACEHOLDER } from './conversation/index.js'
594
604
  export type {
595
605
  ApproveRecordDraftRequest,
596
606
  BatchTransactionError,