From 0e72699cd62288357925167d9b4fbf1ce24bd74e Mon Sep 17 00:00:00 2001 From: Antoine SEIN <142824551+asein-sinch@users.noreply.github.com> Date: Mon, 26 Feb 2024 11:04:20 +0100 Subject: [PATCH] DEVEXP-313: Integrate latest Conversation OAS updates (#28) --- examples/simple-examples/.env.template | 1 + examples/simple-examples/README.md | 95 ++++++------ examples/simple-examples/package.json | 6 + examples/simple-examples/src/config.ts | 4 + .../conversation/conversation/injectEvent.ts | 35 +++++ .../conversation/conversation/listRecent.ts | 74 +++++++++ .../src/conversation/events/delete.ts | 21 +++ .../src/conversation/events/get.ts | 20 +++ .../src/conversation/events/list.ts | 76 +++++++++ .../src/conversation/messages/update.ts | 27 ++++ .../src/services/conversation.service.ts | 3 + .../app-create-request/app-create-request.ts | 10 +- .../app-message-message.ts | 4 +- .../src/models/v1/app-message/app-message.ts | 49 +++--- .../models/v1/app-response/app-response.ts | 23 +-- .../src/models/v1/app-response/index.ts | 2 - .../app-update-request/app-update-request.ts | 10 +- .../models/v1/comment-event/comment-event.ts | 20 +++ .../src/models/v1/comment-event/index.ts | 1 + .../models/v1/contact-event/contact-event.ts | 13 ++ .../src/models/v1/contact-event/index.ts | 1 + .../contact-info-message.ts | 103 ++++++++++++ .../models/v1/contact-info-message/index.ts | 1 + .../contact-message-event.ts | 35 +++++ .../models/v1/contact-message-event/index.ts | 1 + .../conversation-channel-credential.ts | 107 ++++++++++--- .../conversation-channel-credential/index.ts | 19 ++- .../conversation-deleted-event.ts | 5 + .../v1/conversation-deleted-event/index.ts | 1 + .../conversation-event/conversation-event.ts | 42 +++++ .../src/models/v1/conversation-event/index.ts | 1 + .../conversation-message-injected.ts | 25 --- .../v1/conversation-message-injected/index.ts | 1 - .../conversation-message.ts | 23 ++- .../conversation-recent-message.ts | 10 ++ .../v1/conversation-recent-message/index.ts | 1 + .../models/v1/conversation/conversation.ts | 9 +- .../delivery-report-based-fallback.ts | 11 ++ .../delivery-report-based-fallback/index.ts | 1 + packages/conversation/src/models/v1/enums.ts | 4 - .../models/v1/generic-event/generic-event.ts | 3 +- packages/conversation/src/models/v1/index.ts | 14 +- .../index.ts | 1 + .../inject-conversation-event-request.ts | 32 ++++ .../models/v1/inject-event-response/index.ts | 1 + .../inject-event-response.ts | 8 + .../models/v1/inject-message-request/index.ts | 1 + .../inject-message-request.ts | 41 +++++ .../models/v1/message-retry-settings/index.ts | 1 + .../message-retry-settings.ts | 14 ++ .../capability-event/capability-event.ts | 4 +- .../channel-event/channel-event.ts | 4 +- .../contact-create-event.ts | 4 +- .../contact-delete-event.ts | 4 +- .../contact-identities-duplication-event.ts | 4 +- .../contact-merge-event.ts | 4 +- .../contact-update-event.ts | 4 +- .../conversation-callback-event.ts} | 2 +- .../conversation-callback-event/index.ts | 1 + .../conversation-delete-event.ts | 4 +- .../conversation-event/index.ts | 1 - .../conversation-start-event.ts | 4 +- .../conversation-stop-event.ts | 4 +- .../conversation-webhook-event.ts | 2 + .../event-delivery/event-delivery.ts | 4 +- .../event-inbound/event-inbound.ts | 68 +------- .../event-inbound/index.ts | 9 +- .../models/v1/mod-callback-events/index.ts | 1 + .../message-delivery-receipt-event.ts | 4 +- .../message-inbound-event.ts | 4 +- ...ound-smart-conversation-redaction-event.ts | 4 +- .../message-submit-event.ts | 4 +- .../opt-in-event/opt-in-event.ts | 4 +- .../opt-out-event/opt-out-event.ts | 4 +- .../record-notification/index.ts | 1 + .../record-notification.ts | 46 ++++++ .../smart-conversations-event.ts | 4 +- .../unsupported-callback-event.ts | 4 +- .../kakaotalkchat-credentials.ts | 2 +- .../mms-credentials/mms-credentials.ts | 2 +- .../src/models/v1/reason/reason.ts | 6 +- .../models/v1/update-message-request/index.ts | 1 + .../update-message-request.ts | 7 + .../v1/webhook-trigger/webhook-trigger.ts | 3 +- .../rest/v1/callbacks/callbacks-webhook.ts | 6 + .../conversation-api.jest.fixture.ts | 24 ++- .../rest/v1/conversation/conversation-api.ts | 102 +++++++++++- .../rest/v1/events/events-api.jest.fixture.ts | 23 ++- .../src/rest/v1/events/events-api.ts | 127 +++++++++++++++ .../v1/messages/messages-api.jest.fixture.ts | 17 +- .../src/rest/v1/messages/messages-api.ts | 40 +++++ .../v1/conversation/conversation-api.test.ts | 130 ++++++++++++++++ .../tests/rest/v1/events/events-api.test.ts | 146 +++++++++++++++++- .../rest/v1/messages/messages-api.test.ts | 80 ++++++++-- 94 files changed, 1645 insertions(+), 289 deletions(-) create mode 100644 examples/simple-examples/src/conversation/conversation/injectEvent.ts create mode 100644 examples/simple-examples/src/conversation/conversation/listRecent.ts create mode 100644 examples/simple-examples/src/conversation/events/delete.ts create mode 100644 examples/simple-examples/src/conversation/events/get.ts create mode 100644 examples/simple-examples/src/conversation/events/list.ts create mode 100644 examples/simple-examples/src/conversation/messages/update.ts create mode 100644 packages/conversation/src/models/v1/comment-event/comment-event.ts create mode 100644 packages/conversation/src/models/v1/comment-event/index.ts create mode 100644 packages/conversation/src/models/v1/contact-event/contact-event.ts create mode 100644 packages/conversation/src/models/v1/contact-event/index.ts create mode 100644 packages/conversation/src/models/v1/contact-info-message/contact-info-message.ts create mode 100644 packages/conversation/src/models/v1/contact-info-message/index.ts create mode 100644 packages/conversation/src/models/v1/contact-message-event/contact-message-event.ts create mode 100644 packages/conversation/src/models/v1/contact-message-event/index.ts create mode 100644 packages/conversation/src/models/v1/conversation-deleted-event/conversation-deleted-event.ts create mode 100644 packages/conversation/src/models/v1/conversation-deleted-event/index.ts create mode 100644 packages/conversation/src/models/v1/conversation-event/conversation-event.ts create mode 100644 packages/conversation/src/models/v1/conversation-event/index.ts delete mode 100644 packages/conversation/src/models/v1/conversation-message-injected/conversation-message-injected.ts delete mode 100644 packages/conversation/src/models/v1/conversation-message-injected/index.ts create mode 100644 packages/conversation/src/models/v1/conversation-recent-message/conversation-recent-message.ts create mode 100644 packages/conversation/src/models/v1/conversation-recent-message/index.ts create mode 100644 packages/conversation/src/models/v1/delivery-report-based-fallback/delivery-report-based-fallback.ts create mode 100644 packages/conversation/src/models/v1/delivery-report-based-fallback/index.ts create mode 100644 packages/conversation/src/models/v1/inject-conversation-event-request/index.ts create mode 100644 packages/conversation/src/models/v1/inject-conversation-event-request/inject-conversation-event-request.ts create mode 100644 packages/conversation/src/models/v1/inject-event-response/index.ts create mode 100644 packages/conversation/src/models/v1/inject-event-response/inject-event-response.ts create mode 100644 packages/conversation/src/models/v1/inject-message-request/index.ts create mode 100644 packages/conversation/src/models/v1/inject-message-request/inject-message-request.ts create mode 100644 packages/conversation/src/models/v1/message-retry-settings/index.ts create mode 100644 packages/conversation/src/models/v1/message-retry-settings/message-retry-settings.ts rename packages/conversation/src/models/v1/mod-callback-events/{conversation-event/conversation-event.ts => conversation-callback-event/conversation-callback-event.ts} (65%) create mode 100644 packages/conversation/src/models/v1/mod-callback-events/conversation-callback-event/index.ts delete mode 100644 packages/conversation/src/models/v1/mod-callback-events/conversation-event/index.ts create mode 100644 packages/conversation/src/models/v1/mod-callback-events/record-notification/index.ts create mode 100644 packages/conversation/src/models/v1/mod-callback-events/record-notification/record-notification.ts create mode 100644 packages/conversation/src/models/v1/update-message-request/index.ts create mode 100644 packages/conversation/src/models/v1/update-message-request/update-message-request.ts diff --git a/examples/simple-examples/.env.template b/examples/simple-examples/.env.template index 103f3c21..284ca213 100644 --- a/examples/simple-examples/.env.template +++ b/examples/simple-examples/.env.template @@ -34,6 +34,7 @@ CONVERSATION_CONTACT_ID=contact_id to fill with one of the contacts created by t MESSENGER_USER_ID=identity on the MESSENGER channel (can be found on a desktop by selecting a user: the user id will be in the URL) MESSENGER_TOKEN=static_token to define credentials for a MESSENGER channel CONVERSATION_ID=conversation_id to fill with one of the conversations created with the Conversation API +EVENT_ID=event_id to fill with a sent event MESSAGE_ID=message_id to fill with one of the messages sent or injected with the Conversation API TEMPLATE_ID=template_id to fill with one of the templates created with the Templates API (v1 or v2) WEBHOOK_ID=webhook_id to fill with one of the webhooks created with the Conversation API or the Dashboard diff --git a/examples/simple-examples/README.md b/examples/simple-examples/README.md index 3516b29d..975aa2c9 100644 --- a/examples/simple-examples/README.md +++ b/examples/simple-examples/README.md @@ -65,6 +65,7 @@ CONVERSATION_CONTACT_ID=contact_id to fill with one of the contacts created by t MESSENGER_USER_ID=identity on the MESSENGER channel (can be found on a desktop by selecting a user: the user id will be in the URL) MESSENGER_TOKEN=static_token to define credentials for a MESSENGER channel CONVERSATION_ID=conversation_id to fill with one of the conversations created with the Conversation API +EVENT_ID=event_id to fill with a sent event MESSAGE_ID=message_id to fill with one of the messages sent or injected with the Conversation API TEMPLATE_ID=template_id to fill with one of the templates created with the Templates API (v1 or v2) WEBHOOK_ID=webhook_id to fill with one of the webhooks created with the Conversation API or the Dashboard @@ -173,48 +174,54 @@ yarn run numbers:regions:list ### Conversation -| Service | Sample application name and location | Required parameters | -|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| -| App | [./src/conversation/app/create.ts](./src/conversation/app/create.ts) | `MESSENGER_TOKEN` | -| | [./src/conversation/app/delete.ts](./src/conversation/app/delete.ts) | `CONVERSATION_APP_ID` | -| | [./src/conversation/app/get.ts](./src/conversation/app/get.ts) | `CONVERSATION_APP_ID` | -| | [./src/conversation/app/list.ts](./src/conversation/app/list.ts) | | -| | [./src/conversation/app/update.ts](./src/conversation/app/update.ts) | `CONVERSATION_APP_ID` | -| Capability | [./src/conversation/capability/lookup.ts](./src/conversation/capability/lookup.ts) | `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` | -| Contact | [./src/conversation/contact/create.ts](./src/conversation/contact/create.ts) | `CONVERSATION_APP_ID` + `MESSENGER_USER_ID` + `PHONE_NUMBER` | -| | [./src/conversation/contact/delete.ts](./src/conversation/contact/delete.ts) | `CONVERSATION_CONTACT_ID` | -| | [./src/conversation/contact/get.ts](./src/conversation/contact/get.ts) | `CONVERSATION_CONTACT_ID` | -| | [./src/conversation/contact/getChannelProfile.ts](./src/conversation/contact/getChannelProfile.ts) | `CONVERSATION_CONTACT_ID` + `MESSENGER_USER_ID` | -| | [./src/conversation/contact/list.ts](./src/conversation/contact/list.ts) | | -| | [./src/conversation/contact/merge.ts](./src/conversation/contact/merge.ts) | `PHONE_NUMBER` | -| | [./src/conversation/contact/update.ts](./src/conversation/contact/update.ts) | `CONVERSATION_CONTACT_ID` | -| Conversation | [./src/conversation/conversation/create.ts](./src/conversation/conversation/create.ts) | `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` | -| | [./src/conversation/conversation/delete.ts](./src/conversation/conversation/delete.ts) | `CONVERSATION_ID` | -| | [./src/conversation/conversation/get.ts](./src/conversation/conversation/get.ts) | `CONVERSATION_ID` | -| | [./src/conversation/conversation/injectMessage.ts](./src/conversation/conversation/injectMessage.ts) | `CONVERSATION_ID` + `MESSENGER_USER_ID`+ `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` | -| | [./src/conversation/conversation/list.ts](./src/conversation/conversation/list.ts) | `CONVERSATION_APP_ID` | -| | [./src/conversation/conversation/stop.ts](./src/conversation/conversation/stop.ts) | `CONVERSATION_ID` | -| | [./src/conversation/conversation/update.ts](./src/conversation/conversation/update.ts) | `CONVERSATION_ID` | -| Events | [./src/conversation/events/send.ts](./src/conversation/events/send.ts) | `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` | -| Messages | [./src/conversation/messages/delete.ts](./src/conversation/messages/delete.ts) | `MESSAGE_ID` | -| | [./src/conversation/messages/get.ts](./src/conversation/messages/get.ts) | `MESSAGE_ID` | -| | [./src/conversation/messages/list.ts](./src/conversation/messages/list.ts) | `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` + `CONVERSATION_ID` | -| | [./src/conversation/messages/send.ts](./src/conversation/messages/send.ts) | `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` | -| TemplatesV1 | [./src/conversation/templates-v1/create.ts](./src/conversation/templates-v1/create.ts) | | -| | [./src/conversation/templates-v1/delete.ts](./src/conversation/templates-v1/delete.ts) | `TEMPLATE_ID` | -| | [./src/conversation/templates-v1/get.ts](./src/conversation/templates-v1/get.ts) | `TEMPLATE_ID` | -| | [./src/conversation/templates-v1/list.ts](./src/conversation/templates-v1/list.ts) | | -| | [./src/conversation/templates-v1/update.ts](./src/conversation/templates-v1/update.ts) | `TEMPLATE_ID` | -| TemplatesV2 | [./src/conversation/templates-v2/create.ts](./src/conversation/templates-v2/create.ts) | | -| | [./src/conversation/templates-v2/delete.ts](./src/conversation/templates-v2/delete.ts) | `TEMPLATE_ID` | -| | [./src/conversation/templates-v2/get.ts](./src/conversation/templates-v2/get.ts) | `TEMPLATE_ID` | -| | [./src/conversation/templates-v2/list.ts](./src/conversation/templates-v2/list.ts) | | -| | [./src/conversation/templates-v2/list-translations.ts](./src/conversation/templates-v2/list-translations.ts) | `TEMPLATE_ID` | -| | [./src/conversation/templates-v2/update.ts](./src/conversation/templates-v2/update.ts) | `TEMPLATE_ID` | -| Transcoding | [./src/conversation/transcoding/transcode.ts](./src/conversation/transcoding/transcode.ts) | `CONVERSATION_APP_ID` | -| Webhooks | [./src/conversation/webhooks/create.ts](./src/conversation/webhooks/create.ts) | `CONVERSATION_APP_ID` + `WEBHOOK_TARGET` | -| | [./src/conversation/webhooks/delete.ts](./src/conversation/webhooks/delete.ts) | `WEBHOOK_ID` | -| | [./src/conversation/webhooks/get.ts](./src/conversation/webhooks/get.ts) | `WEBHOOK_ID` | -| | [./src/conversation/webhooks/list.ts](./src/conversation/webhooks/list.ts) | `CONVERSATION_APP_ID` | -| | [./src/conversation/webhooks/update.ts](./src/conversation/webhooks/update.ts) | `CONVERSATION_APP_ID` + `WEBHOOK_ID` | +| Service | Sample application name and location | Required parameters | +|--------------|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| +| App | [./src/conversation/app/create.ts](./src/conversation/app/create.ts) | `MESSENGER_TOKEN` | +| | [./src/conversation/app/delete.ts](./src/conversation/app/delete.ts) | `CONVERSATION_APP_ID` | +| | [./src/conversation/app/get.ts](./src/conversation/app/get.ts) | `CONVERSATION_APP_ID` | +| | [./src/conversation/app/list.ts](./src/conversation/app/list.ts) | | +| | [./src/conversation/app/update.ts](./src/conversation/app/update.ts) | `CONVERSATION_APP_ID` | +| Capability | [./src/conversation/capability/lookup.ts](./src/conversation/capability/lookup.ts) | `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` | +| Contact | [./src/conversation/contact/create.ts](./src/conversation/contact/create.ts) | `CONVERSATION_APP_ID` + `MESSENGER_USER_ID` + `PHONE_NUMBER` | +| | [./src/conversation/contact/delete.ts](./src/conversation/contact/delete.ts) | `CONVERSATION_CONTACT_ID` | +| | [./src/conversation/contact/get.ts](./src/conversation/contact/get.ts) | `CONVERSATION_CONTACT_ID` | +| | [./src/conversation/contact/getChannelProfile.ts](./src/conversation/contact/getChannelProfile.ts) | `CONVERSATION_CONTACT_ID` + `MESSENGER_USER_ID` | +| | [./src/conversation/contact/list.ts](./src/conversation/contact/list.ts) | | +| | [./src/conversation/contact/merge.ts](./src/conversation/contact/merge.ts) | `PHONE_NUMBER` | +| | [./src/conversation/contact/update.ts](./src/conversation/contact/update.ts) | `CONVERSATION_CONTACT_ID` | +| Conversation | [./src/conversation/conversation/create.ts](./src/conversation/conversation/create.ts) | `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` | +| | [./src/conversation/conversation/delete.ts](./src/conversation/conversation/delete.ts) | `CONVERSATION_ID` | +| | [./src/conversation/conversation/get.ts](./src/conversation/conversation/get.ts) | `CONVERSATION_ID` | +| | [./src/conversation/conversation/injectEvent.ts](./src/conversation/conversation/injectEvent.ts) | `CONVERSATION_ID` + `CONVERSATION_CONTACT_ID` | +| | [./src/conversation/conversation/injectMessage.ts](./src/conversation/conversation/injectMessage.ts) | `CONVERSATION_ID` + `MESSENGER_USER_ID`+ `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` | +| | [./src/conversation/conversation/list.ts](./src/conversation/conversation/list.ts) | `CONVERSATION_APP_ID` | +| | [./src/conversation/conversation/listRecent.ts](./src/conversation/conversation/listRecent.ts) | `CONVERSATION_APP_ID` | +| | [./src/conversation/conversation/stop.ts](./src/conversation/conversation/stop.ts) | `CONVERSATION_ID` | +| | [./src/conversation/conversation/update.ts](./src/conversation/conversation/update.ts) | `CONVERSATION_ID` | +| Events | [./src/conversation/events/send.ts](./src/conversation/events/send.ts) | `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` | +| | [./src/conversation/events/get.ts](./src/conversation/events/get.ts) | `EVENT_ID` | +| | [./src/conversation/events/list.ts](./src/conversation/events/list.ts) | `CONVERSATION_ID` + `CONVERSATION_CONTACT_ID` | +| | [./src/conversation/events/delete.ts](./src/conversation/events/delete.ts) | `EVENT_ID` | +| Messages | [./src/conversation/messages/delete.ts](./src/conversation/messages/delete.ts) | `MESSAGE_ID` | +| | [./src/conversation/messages/get.ts](./src/conversation/messages/get.ts) | `MESSAGE_ID` | +| | [./src/conversation/messages/list.ts](./src/conversation/messages/list.ts) | `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` + `CONVERSATION_ID` | +| | [./src/conversation/messages/send.ts](./src/conversation/messages/send.ts) | `CONVERSATION_APP_ID` + `CONVERSATION_CONTACT_ID` | +| | [./src/conversation/messages/update.ts](./src/conversation/messages/update.ts) | `MESSAGE_ID` | +| TemplatesV1 | [./src/conversation/templates-v1/create.ts](./src/conversation/templates-v1/create.ts) | | +| | [./src/conversation/templates-v1/delete.ts](./src/conversation/templates-v1/delete.ts) | `TEMPLATE_ID` | +| | [./src/conversation/templates-v1/get.ts](./src/conversation/templates-v1/get.ts) | `TEMPLATE_ID` | +| | [./src/conversation/templates-v1/list.ts](./src/conversation/templates-v1/list.ts) | | +| | [./src/conversation/templates-v1/update.ts](./src/conversation/templates-v1/update.ts) | `TEMPLATE_ID` | +| TemplatesV2 | [./src/conversation/templates-v2/create.ts](./src/conversation/templates-v2/create.ts) | | +| | [./src/conversation/templates-v2/delete.ts](./src/conversation/templates-v2/delete.ts) | `TEMPLATE_ID` | +| | [./src/conversation/templates-v2/get.ts](./src/conversation/templates-v2/get.ts) | `TEMPLATE_ID` | +| | [./src/conversation/templates-v2/list.ts](./src/conversation/templates-v2/list.ts) | | +| | [./src/conversation/templates-v2/list-translations.ts](./src/conversation/templates-v2/list-translations.ts) | `TEMPLATE_ID` | +| | [./src/conversation/templates-v2/update.ts](./src/conversation/templates-v2/update.ts) | `TEMPLATE_ID` | +| Transcoding | [./src/conversation/transcoding/transcode.ts](./src/conversation/transcoding/transcode.ts) | `CONVERSATION_APP_ID` | +| Webhooks | [./src/conversation/webhooks/create.ts](./src/conversation/webhooks/create.ts) | `CONVERSATION_APP_ID` + `WEBHOOK_TARGET` | +| | [./src/conversation/webhooks/delete.ts](./src/conversation/webhooks/delete.ts) | `WEBHOOK_ID` | +| | [./src/conversation/webhooks/get.ts](./src/conversation/webhooks/get.ts) | `WEBHOOK_ID` | +| | [./src/conversation/webhooks/list.ts](./src/conversation/webhooks/list.ts) | `CONVERSATION_APP_ID` | +| | [./src/conversation/webhooks/update.ts](./src/conversation/webhooks/update.ts) | `CONVERSATION_APP_ID` + `WEBHOOK_ID` | diff --git a/examples/simple-examples/package.json b/examples/simple-examples/package.json index ab7efb5b..fd7ddb2b 100644 --- a/examples/simple-examples/package.json +++ b/examples/simple-examples/package.json @@ -23,15 +23,21 @@ "conversation:messages:send": "ts-node src/conversation/messages/send.ts", "conversation:messages:get": "ts-node src/conversation/messages/get.ts", "conversation:messages:list": "ts-node src/conversation/messages/list.ts", + "conversation:messages:update": "ts-node src/conversation/messages/update.ts", "conversation:messages:delete": "ts-node src/conversation/messages/delete.ts", "conversation:conversation:create": "ts-node src/conversation/conversation/create.ts", "conversation:conversation:get": "ts-node src/conversation/conversation/get.ts", "conversation:conversation:list": "ts-node src/conversation/conversation/list.ts", + "conversation:conversation:listRecent": "ts-node src/conversation/conversation/listRecent.ts", + "conversation:conversation:injectEvent": "ts-node src/conversation/conversation/injectEvent.ts", "conversation:conversation:injectMessage": "ts-node src/conversation/conversation/injectMessage.ts", "conversation:conversation:update": "ts-node src/conversation/conversation/update.ts", "conversation:conversation:stop": "ts-node src/conversation/conversation/stop.ts", "conversation:conversation:delete": "ts-node src/conversation/conversation/delete.ts", "conversation:events:send": "ts-node src/conversation/events/send.ts", + "conversation:events:get": "ts-node src/conversation/events/get.ts", + "conversation:events:list": "ts-node src/conversation/events/list.ts", + "conversation:events:delete": "ts-node src/conversation/events/delete.ts", "conversation:transcoding:transcode": "ts-node src/conversation/transcoding/transcode.ts", "conversation:capability:lookup": "ts-node src/conversation/capability/lookup.ts", "conversation:webhooks:create": "ts-node src/conversation/webhooks/create.ts", diff --git a/examples/simple-examples/src/config.ts b/examples/simple-examples/src/config.ts index 3e4c7b56..6925e777 100644 --- a/examples/simple-examples/src/config.ts +++ b/examples/simple-examples/src/config.ts @@ -141,6 +141,10 @@ export const getTemplateIdFromConfig = () => { return readVariable('TEMPLATE_ID'); }; +export const getEventIdFromConfig = () => { + return readVariable('EVENT_ID'); +}; + const readVariable = ( name: string): string => { const value = process.env[name]; if (!value) { diff --git a/examples/simple-examples/src/conversation/conversation/injectEvent.ts b/examples/simple-examples/src/conversation/conversation/injectEvent.ts new file mode 100644 index 00000000..4af09178 --- /dev/null +++ b/examples/simple-examples/src/conversation/conversation/injectEvent.ts @@ -0,0 +1,35 @@ +import { InjectEventRequestData } from '@sinch/sdk-core'; +import { + getContactIdFromConfig, + getConversationIdFromConfig, + initClient, + printFullResponse, +} from '../../config'; + + +(async () => { + console.log('****************************'); + console.log('* Conversation_InjectEvent *'); + console.log('****************************'); + + const conversationId = getConversationIdFromConfig(); + const contactId = getContactIdFromConfig(); + + const requestData: InjectEventRequestData= { + conversation_id: conversationId, + injectConversationEventRequestBody: { + app_event: { + composing_event: {}, + }, + accept_time: new Date(), + conversation_id: conversationId, + contact_id: contactId, + }, + }; + + const sinchClient = initClient(); + const response = await sinchClient.conversation.conversation.injectEvent(requestData); + + printFullResponse(response); + +})(); diff --git a/examples/simple-examples/src/conversation/conversation/listRecent.ts b/examples/simple-examples/src/conversation/conversation/listRecent.ts new file mode 100644 index 00000000..f2fdd738 --- /dev/null +++ b/examples/simple-examples/src/conversation/conversation/listRecent.ts @@ -0,0 +1,74 @@ +import { + ConversationRecentMessage, + ListRecentConversationsRequestData, + PageResult, +} from '@sinch/sdk-core'; +import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; + +const populateConversationsList = ( + conversationPage: PageResult, + conversationList: ConversationRecentMessage[], + conversationDetailsList: string[], +) => { + conversationPage.data.map((recentConversation: ConversationRecentMessage) => { + conversationList.push(recentConversation); + conversationDetailsList.push(`${recentConversation.conversation?.id} - ${recentConversation.conversation?.active_channel}\n - Latest message: ${recentConversation.last_message?.accept_time}`); + }); +}; + +(async () => { + console.log('****************************************'); + console.log('* Conversation_ListRecentConversations *'); + console.log('****************************************'); + + const appId = getAppIdFromConfig(); + + const requestData: ListRecentConversationsRequestData = { + only_active: true, + app_id: appId, + order: 'ASC', + }; + + const sinchClient = initClient(); + + // ---------------------------------------------- + // Method 1: Fetch the data page by page manually + // ---------------------------------------------- + let response = await sinchClient.conversation.conversation.listRecent(requestData); + + const conversationList: ConversationRecentMessage[] = []; + const conversationDetailsList: string[] = []; + + // Loop on all the pages to get all the active numbers + let reachedEndOfPages = false; + while (!reachedEndOfPages) { + populateConversationsList(response, conversationList, conversationDetailsList); + if (response.hasNextPage) { + response = await response.nextPage(); + } else { + reachedEndOfPages = true; + } + } + + const printFormat = getPrintFormat(process.argv); + + if (printFormat === 'pretty') { + console.log(conversationDetailsList.length > 0 + ? 'List of conversations:\n' + conversationDetailsList.join('\n') + : 'Sorry, no conversations were found.'); + } else { + printFullResponse(conversationList); + } + + // --------------------------------------------------------------------- + // Method 2: Use the iterator and fetch data on more pages automatically + // --------------------------------------------------------------------- + for await (const recentConversation of sinchClient.conversation.conversation.listRecent(requestData)) { + if (printFormat === 'pretty') { + console.log(`${recentConversation.conversation?.id} - ${recentConversation.conversation?.active_channel}\n - Latest message: ${recentConversation.last_message?.accept_time}`); + } else { + console.log(recentConversation); + } + } + +})(); diff --git a/examples/simple-examples/src/conversation/events/delete.ts b/examples/simple-examples/src/conversation/events/delete.ts new file mode 100644 index 00000000..8bf353f1 --- /dev/null +++ b/examples/simple-examples/src/conversation/events/delete.ts @@ -0,0 +1,21 @@ +import { DeleteEventRequestData } from '@sinch/sdk-core'; +import { getEventIdFromConfig, initClient, printFullResponse } from '../../config'; + + +(async () => { + console.log('**********************'); + console.log('* Events_DeleteEvent *'); + console.log('**********************'); + + const eventId = getEventIdFromConfig(); + + const requestData: DeleteEventRequestData = { + event_id: eventId, + }; + + const sinchClient = initClient(); + const response = await sinchClient.conversation.events.delete(requestData); + + printFullResponse(response); + +})(); diff --git a/examples/simple-examples/src/conversation/events/get.ts b/examples/simple-examples/src/conversation/events/get.ts new file mode 100644 index 00000000..2a04eb0e --- /dev/null +++ b/examples/simple-examples/src/conversation/events/get.ts @@ -0,0 +1,20 @@ +import { GetEventRequestData } from '@sinch/sdk-core'; +import { getEventIdFromConfig, initClient, printFullResponse } from '../../config'; + +(async () => { + console.log('*******************'); + console.log('* Events_GetEvent *'); + console.log('*******************'); + + const eventId = getEventIdFromConfig(); + + const requestData: GetEventRequestData = { + event_id: eventId, + }; + + const sinchClient = initClient(); + const response = await sinchClient.conversation.events.get(requestData); + + printFullResponse(response); + +})(); diff --git a/examples/simple-examples/src/conversation/events/list.ts b/examples/simple-examples/src/conversation/events/list.ts new file mode 100644 index 00000000..b5f90209 --- /dev/null +++ b/examples/simple-examples/src/conversation/events/list.ts @@ -0,0 +1,76 @@ +import { ConversationEvent, ListEventsRequestData, PageResult } from '@sinch/sdk-core'; +import { + getContactIdFromConfig, + getConversationIdFromConfig, + getPrintFormat, + initClient, + printFullResponse, +} from '../../config'; + +const populateEventsList = ( + eventPage: PageResult, + eventList: ConversationEvent[], + eventDetailsList: string[], +) => { + eventPage.data.map((event: ConversationEvent) => { + eventList.push(event); + eventDetailsList.push(`${event.id} - ${event.accept_time}`); + }); +}; + +(async () => { + console.log('*********************'); + console.log('* Events_ListEvents *'); + console.log('*********************'); + + const contactId = getContactIdFromConfig(); + const conversationId = getConversationIdFromConfig(); + + const requestData: ListEventsRequestData = { + contact_id: contactId, + conversation_id: conversationId, + }; + + const sinchClient = initClient(); + + // ---------------------------------------------- + // Method 1: Fetch the data page by page manually + // ---------------------------------------------- + let response = await sinchClient.conversation.events.list(requestData); + + const eventsList: ConversationEvent[] = []; + const eventsDetailsList: string[] = []; + + // Loop on all the pages to get all the active numbers + let reachedEndOfPages = false; + while (!reachedEndOfPages) { + populateEventsList(response, eventsList, eventsDetailsList); + if (response.hasNextPage) { + response = await response.nextPage(); + } else { + reachedEndOfPages = true; + } + } + + const printFormat = getPrintFormat(process.argv); + + if (printFormat === 'pretty') { + console.log(eventsDetailsList.length > 0 + ? 'List of events:\n' + eventsDetailsList.join('\n') + : 'Sorry, no events were found.'); + } else { + printFullResponse(eventsList); + } + + // --------------------------------------------------------------------- + // Method 2: Use the iterator and fetch data on more pages automatically + // --------------------------------------------------------------------- + for await (const event of sinchClient.conversation.events.list(requestData)) { + if (printFormat === 'pretty') { + console.log(`${event.id} - ${event.accept_time}`); + } else { + console.log(event); + } + } + +})(); diff --git a/examples/simple-examples/src/conversation/messages/update.ts b/examples/simple-examples/src/conversation/messages/update.ts new file mode 100644 index 00000000..88c96267 --- /dev/null +++ b/examples/simple-examples/src/conversation/messages/update.ts @@ -0,0 +1,27 @@ +import { UpdateMessageRequestData } from '@sinch/sdk-core'; +import { + getMessageIdFromConfig, + initClient, + printFullResponse, +} from '../../config'; + +(async () => { + console.log('**************************'); + console.log('* Messages_UpdateMessage *'); + console.log('**************************'); + + const messageId = getMessageIdFromConfig(); + + const requestData: UpdateMessageRequestData = { + message_id: messageId, + updateMessageRequestBody: { + metadata: 'Updated metadata', + }, + }; + + const sinchClient = initClient(); + const response = await sinchClient.conversation.messages.update(requestData); + + printFullResponse(response); + +})(); diff --git a/examples/webhooks/src/services/conversation.service.ts b/examples/webhooks/src/services/conversation.service.ts index 1f47542d..6d2d1244 100644 --- a/examples/webhooks/src/services/conversation.service.ts +++ b/examples/webhooks/src/services/conversation.service.ts @@ -197,6 +197,9 @@ export class ConversationService { console.log(`Additional data:\n${JSON.stringify(channelEvent.additional_data, null, 2)}`); } break; + case 'RECORD_NOTIFICATION': + console.log('\n## RECORD_NOTIFICATION'); + break; case 'UNSUPPORTED': console.log('\n## UNSUPPORTED') const unsupportedCallback = event.unsupported_callback; diff --git a/packages/conversation/src/models/v1/app-create-request/app-create-request.ts b/packages/conversation/src/models/v1/app-create-request/app-create-request.ts index 6cab3293..de0c3814 100644 --- a/packages/conversation/src/models/v1/app-create-request/app-create-request.ts +++ b/packages/conversation/src/models/v1/app-create-request/app-create-request.ts @@ -1,9 +1,11 @@ import { CallbackSettings } from '../callback-settings'; -import { ConversationChannelCredential } from '../conversation-channel-credential'; +import { ConversationChannelCredentialRequest } from '../conversation-channel-credential'; import { DispatchRetentionPolicy } from '../dispatch-retention-policy'; import { RetentionPolicy } from '../retention-policy'; import { SmartConversation } from '../smart-conversation'; import { ConversationMetadataReportView, ProcessingMode } from '../enums'; +import { DeliveryReportBasedFallback } from '../delivery-report-based-fallback'; +import { MessageRetrySettings } from '../message-retry-settings'; /** * The request sent to the API endpoint to create a new app. @@ -11,7 +13,7 @@ import { ConversationMetadataReportView, ProcessingMode } from '../enums'; export interface AppCreateRequest { /** An array of channel credentials. The order of the credentials defines the app channel priority. */ - channel_credentials: ConversationChannelCredential[]; + channel_credentials: ConversationChannelCredentialRequest[]; /** @see ConversationMetadataReportView */ conversation_metadata_report_view?: ConversationMetadataReportView; /** The display name for the app. */ @@ -26,4 +28,8 @@ export interface AppCreateRequest { smart_conversation?: SmartConversation; /** @see CallbackSettings */ callback_settings?: CallbackSettings; + /** @see MessageRetrySettings */ + message_retry_settings?: MessageRetrySettings; + /** @see DeliveryReportBasedFallback */ + delivery_report_based_fallback?: DeliveryReportBasedFallback; } diff --git a/packages/conversation/src/models/v1/app-message-message/app-message-message.ts b/packages/conversation/src/models/v1/app-message-message/app-message-message.ts index 880d2575..883b1b15 100644 --- a/packages/conversation/src/models/v1/app-message-message/app-message-message.ts +++ b/packages/conversation/src/models/v1/app-message-message/app-message-message.ts @@ -6,6 +6,7 @@ import { MediaMessage } from '../media-message'; import { TextMessage } from '../text-message'; import { ListMessage } from '../list-message'; import { TemplateMessage } from '../template-message'; +import { ContactInfoMessage } from '../contact-info-message'; /** The content of the message */ export type AppMessageMessage = @@ -16,4 +17,5 @@ export type AppMessageMessage = | MediaMessage | TemplateMessage | TextMessage - | ListMessage; + | ListMessage + | ContactInfoMessage; diff --git a/packages/conversation/src/models/v1/app-message/app-message.ts b/packages/conversation/src/models/v1/app-message/app-message.ts index 71da85b2..717668aa 100644 --- a/packages/conversation/src/models/v1/app-message/app-message.ts +++ b/packages/conversation/src/models/v1/app-message/app-message.ts @@ -1,13 +1,13 @@ -import { AppMessageMessage } from '../app-message-message'; import { Agent } from '../agent'; -import { LocationMessageItem } from '../location-message'; -import { MediaMessageItem } from '../media-message'; -import { TextMessageItem } from '../text-message'; +import { LocationMessage, LocationMessageItem } from '../location-message'; +import { MediaMessage, MediaMessageItem } from '../media-message'; +import { TextMessage, TextMessageItem } from '../text-message'; import { TemplateMessage } from '../template-message'; -import { CardMessageItem } from '../card-message'; +import { CardMessage, CardMessageItem } from '../card-message'; import { ChoiceMessage } from '../choice-message'; import { CarouselMessage } from '../carousel-message'; import { ListMessage } from '../list-message'; +import { ContactInfoMessage, ContactInfoMessageItem } from '../contact-info-message'; /** * Message originating from an app @@ -20,7 +20,8 @@ export type AppMessage = | AppMessageMediaMessage | AppMessageTemplateMessage | AppMessageTextMessage - | AppMessageListMessage; + | AppMessageListMessage + | AppMessageContactInfoMessage; interface AppMessageCardMessage extends AppMessageBase { /** @see CardMessageItem */ @@ -62,22 +63,32 @@ interface AppMessageListMessage extends AppMessageBase { list_message?: ListMessage; } +interface AppMessageContactInfoMessage extends AppMessageBase { + contact_info_message?: ContactInfoMessageItem; +} + interface AppMessageBase { - /** Optional. Channel specific messages, overriding any transcoding. The key in the map must point to a valid conversation channel as defined by the enum ConversationChannel. */ + /** + * Optional. Channel specific messages, overriding any transcoding. + * The key in the map must point to a valid conversation channel as defined by the enum ConversationChannel. + */ explicit_channel_message?: { [key: string]: string; }; - /** @see AppMessageAdditionalProperties */ - additionalProperties?: AppMessageAdditionalProperties; + /** + * The option to override the omni-channel template configuration with a channel-specific template + * (for channels on which channel-specific templates can be created. For more information, see [Channel Specific Templates](https://developers.sinch.com/docs/conversation/templates/#channel-specific-templates)). + */ + explicit_channel_omni_message?: { [key: string]: OmniMessageOverride; }; /** Identity of a sender */ agent?: Agent | null; - /** */ - explicit_channel_omni_message?: { [key: string]: AppMessageMessage; }; } -/** - * Additional properties of the message. - */ -export interface AppMessageAdditionalProperties { - - /** The `display_name` of the newly created contact in case it doesn't exist. */ - contact_name?: string; -} +type OmniMessageOverride = + CardMessage + | CarouselMessage + | ChoiceMessage + | LocationMessage + | MediaMessage + | TemplateMessage + | TextMessage + | ListMessage + | ContactInfoMessage; diff --git a/packages/conversation/src/models/v1/app-response/app-response.ts b/packages/conversation/src/models/v1/app-response/app-response.ts index 9acaa02d..53d142e6 100644 --- a/packages/conversation/src/models/v1/app-response/app-response.ts +++ b/packages/conversation/src/models/v1/app-response/app-response.ts @@ -1,4 +1,4 @@ -import { ConversationChannelCredential } from '../conversation-channel-credential'; +import { ConversationChannelCredentialResponse } from '../conversation-channel-credential'; import { DispatchRetentionPolicy } from '../dispatch-retention-policy'; import { QueueStats } from '../queue-stats'; import { RateLimits } from '../rate-limits'; @@ -6,6 +6,8 @@ import { RetentionPolicy } from '../retention-policy'; import { SmartConversation } from '../smart-conversation'; import { CallbackSettings } from '../callback-settings'; import { ConversationMetadataReportView, ProcessingMode } from '../enums'; +import { DeliveryReportBasedFallback } from '../delivery-report-based-fallback'; +import { MessageRetrySettings } from '../message-retry-settings'; /** * The response showing information about the app. @@ -13,7 +15,7 @@ import { ConversationMetadataReportView, ProcessingMode } from '../enums'; export interface AppResponse { /** An array of channel credentials. The order of the credentials defines the app channel priority. */ - channel_credentials?: ConversationChannelCredential[]; + channel_credentials?: ConversationChannelCredentialResponse[]; /** @see ConversationMetadataReportView */ conversation_metadata_report_view?: ConversationMetadataReportView; /** The display name for the app. */ @@ -54,20 +56,3 @@ export interface MessageSearch { /** A flag specifying whether this app has enabled Message Search services. */ enabled?: boolean; } - -export interface DeliveryReportBasedFallback { - /** A flag specifying whether this app has enabled fallback upon no positive delivery report feature. Disabled by default */ - enabled?: boolean; - /** The time, in seconds, after which a message without a positive delivery report will fallback to the next channel. The valid values for this field are [60 - 259200]. */ - delivery_report_waiting_time?: number; -} - -export interface MessageRetrySettings { - /** - * The maximum duration, in seconds, for which to retry sending a message in case of a temporary processing failure. Time is counted after the first message processing failure. At least one retry is guaranteed. - * Subsequent retry times are randomized with exponential backoff. If the next retry timestamp exceeds the configured time, one last retry will be performed on the cut-off time. - * If the message has a configured fallback channel, a switch_on_channel will be triggered. - * The valid values for this field are [30 - 3600]. Default value is 3600 (seconds - 1 hour). - */ - retry_duration?: number; -} diff --git a/packages/conversation/src/models/v1/app-response/index.ts b/packages/conversation/src/models/v1/app-response/index.ts index bdc7716f..49ed590b 100644 --- a/packages/conversation/src/models/v1/app-response/index.ts +++ b/packages/conversation/src/models/v1/app-response/index.ts @@ -1,7 +1,5 @@ export type { AppResponse, - DeliveryReportBasedFallback, - MessageRetrySettings, MessageSearch, PersistMessageStatus, } from './app-response'; diff --git a/packages/conversation/src/models/v1/app-update-request/app-update-request.ts b/packages/conversation/src/models/v1/app-update-request/app-update-request.ts index 8c1212b2..03cf5a5a 100644 --- a/packages/conversation/src/models/v1/app-update-request/app-update-request.ts +++ b/packages/conversation/src/models/v1/app-update-request/app-update-request.ts @@ -1,9 +1,11 @@ import { CallbackSettings } from '../callback-settings'; -import { ConversationChannelCredential } from '../conversation-channel-credential'; +import { ConversationChannelCredentialRequest } from '../conversation-channel-credential'; import { DispatchRetentionPolicy } from '../dispatch-retention-policy'; import { RetentionPolicy } from '../retention-policy'; import { SmartConversation } from '../smart-conversation'; import { ConversationMetadataReportView, ProcessingMode } from '../enums'; +import { MessageRetrySettings } from '../message-retry-settings'; +import { DeliveryReportBasedFallback } from '../delivery-report-based-fallback'; /** * The request sent to the API endpoint to update the configuration of an app. @@ -11,7 +13,7 @@ import { ConversationMetadataReportView, ProcessingMode } from '../enums'; export interface AppUpdateRequest { /** An array of channel credentials. The order of the credentials defines the app channel priority. */ - channel_credentials?: ConversationChannelCredential[]; + channel_credentials?: ConversationChannelCredentialRequest[]; /** @see ConversationMetadataReportView */ conversation_metadata_report_view?: ConversationMetadataReportView; /** The display name for the app. */ @@ -26,4 +28,8 @@ export interface AppUpdateRequest { smart_conversation?: SmartConversation; /** @see CallbackSettings */ callback_settings?: CallbackSettings; + /** @see MessageRetrySettings */ + message_retry_settings?: MessageRetrySettings; + /** @see DeliveryReportBasedFallback */ + delivery_report_based_fallback?: DeliveryReportBasedFallback; } diff --git a/packages/conversation/src/models/v1/comment-event/comment-event.ts b/packages/conversation/src/models/v1/comment-event/comment-event.ts new file mode 100644 index 00000000..741259f8 --- /dev/null +++ b/packages/conversation/src/models/v1/comment-event/comment-event.ts @@ -0,0 +1,20 @@ +/** + * Object which contains information of a comment made by a user outside the main conversation context. Currently only supported on Instagram channel, see Instagram Private Replies for more details + */ +export interface CommentEvent { + /** The user sent a comment outside of the main conversation context */ + comment_event: CommentEventItem; +} + +export interface CommentEventItem { + /** Event's ID */ + id?: string; + /** Comment's text */ + text?: string; + /** Either LIVE or FEED. Indicates the type of media on which the comment was made. */ + comment_type?: 'FEED' | 'LIVE'; + /** Instagram's URL of the live broadcast or the post on which the comment was made (permalink). */ + commented_on?: string; + /** Username of the account that commented in the live broadcast or post. */ + user?: string; +} diff --git a/packages/conversation/src/models/v1/comment-event/index.ts b/packages/conversation/src/models/v1/comment-event/index.ts new file mode 100644 index 00000000..f61f1549 --- /dev/null +++ b/packages/conversation/src/models/v1/comment-event/index.ts @@ -0,0 +1 @@ +export type { CommentEvent, CommentEventItem } from './comment-event'; diff --git a/packages/conversation/src/models/v1/contact-event/contact-event.ts b/packages/conversation/src/models/v1/contact-event/contact-event.ts new file mode 100644 index 00000000..ff171470 --- /dev/null +++ b/packages/conversation/src/models/v1/contact-event/contact-event.ts @@ -0,0 +1,13 @@ +import { ComposingEvent } from '../composing-event'; +import { ComposingEndEvent } from '../composing-end-event'; +import { CommentEvent } from '../comment-event'; +import { GenericEvent } from '../generic-event'; +import { ConversationDeletedEvent } from '../conversation-deleted-event'; + +/** Message originating from a contact */ +export type ContactEvent = + ComposingEvent + | ComposingEndEvent + | ConversationDeletedEvent + | CommentEvent + | GenericEvent; diff --git a/packages/conversation/src/models/v1/contact-event/index.ts b/packages/conversation/src/models/v1/contact-event/index.ts new file mode 100644 index 00000000..1d9e9ea1 --- /dev/null +++ b/packages/conversation/src/models/v1/contact-event/index.ts @@ -0,0 +1 @@ +export type { ContactEvent } from './contact-event'; diff --git a/packages/conversation/src/models/v1/contact-info-message/contact-info-message.ts b/packages/conversation/src/models/v1/contact-info-message/contact-info-message.ts new file mode 100644 index 00000000..433e2fef --- /dev/null +++ b/packages/conversation/src/models/v1/contact-info-message/contact-info-message.ts @@ -0,0 +1,103 @@ +/** + * Message containing contact information. + */ +export interface ContactInfoMessage { + + /** @see ContactInfoMessageContactInfoMessage */ + contact_info_message?: ContactInfoMessageItem; +} + +export interface ContactInfoMessageItem { + /** @see NameInfo */ + name: NameInfo; + /** Phone numbers of the contact */ + phone_numbers: PhoneNumberInfo[]; + /** Physical addresses of the contact */ + addresses?: AddressInfo[]; + /** Email addresses of the contact */ + email_addresses?: EmailInfo[]; + /** @see OrganizationInfo */ + organization?: OrganizationInfo; + /** URLs/websites associated with the contact */ + urls?: UrlInfo[]; + /** Date of birth in YYYY-MM-DD format. */ + birthday?: string; +} + +/** + * Name information of the contact. + */ +export interface NameInfo { + /** Full name of the contact. Will be the displayed contact name. Format as desired. */ + full_name: string; + /** First name/given name. */ + first_name?: string; + /** Family name/last name/surname. */ + last_name?: string; + /** Middle name. */ + middle_name?: string; + /** Prefix before the name. e.g. Mr, Mrs, Dr etc. */ + prefix?: string; + /** Suffix after the name. e.g. Jr or PhD */ + suffix?: string; +} + +/** + * Phone numbers of the contact. + */ +export interface PhoneNumberInfo { + /** Phone number with country code included. */ + phone_number: string; + /** Phone number type, e.g. WORK or HOME. */ + type?: string; +} + +/** + * Physical addresses of the contact. + */ +export interface AddressInfo { + /** City Name */ + city?: string; + /** Country Name */ + country?: string; + /** Name of a state or region of a country. */ + state?: string; + /** Zip/postal code */ + zip?: string; + /** Address type, e.g. WORK or HOME */ + type?: string; + /** Two letters country code. */ + country_code?: string; +} + +/** + * Email addresses of the contact. + */ +export interface EmailInfo { + /** Email address. */ + email_address: string; + /** Email address type. e.g. WORK or HOME. */ + type?: string; +} + +/** + * Organization information of the contact. + */ +export interface OrganizationInfo { + /** Company name */ + company?: string; + /** Department at the company */ + department?: string; + /** Corporate title, e.g. Software engineer */ + title?: string; +} + +/** + * A URL/website + */ +export interface UrlInfo { + /** The URL to be referenced */ + url: string; + /** Optional. URL type, e.g. HOME, ORG or SOCIAL */ + type?: string; +} diff --git a/packages/conversation/src/models/v1/contact-info-message/index.ts b/packages/conversation/src/models/v1/contact-info-message/index.ts new file mode 100644 index 00000000..37829bc4 --- /dev/null +++ b/packages/conversation/src/models/v1/contact-info-message/index.ts @@ -0,0 +1 @@ +export type { ContactInfoMessage, ContactInfoMessageItem } from './contact-info-message'; diff --git a/packages/conversation/src/models/v1/contact-message-event/contact-message-event.ts b/packages/conversation/src/models/v1/contact-message-event/contact-message-event.ts new file mode 100644 index 00000000..ec712e56 --- /dev/null +++ b/packages/conversation/src/models/v1/contact-message-event/contact-message-event.ts @@ -0,0 +1,35 @@ +/** + * The content of the event when contact_event is not populated. Note that this object is currently only available to select customers for beta testing. Mutually exclusive with contact_event. + */ +export interface ContactMessageEvent { + + /** Object reflecting the current state of a particular payment flow. */ + payment_status_update_event?: PaymentStatusUpdateEvent; +} + +interface PaymentStatusUpdateEvent { + + /** Unique identifier for the corresponding payment of a particular order. */ + reference_id?: string; + /** The stage the payment has reached within the payment flow. */ + payment_status?: PaymentStatusEnum; + /** The status of the stage detailed in payment_status. */ + payment_transaction_status?: PaymentTransactionStatusEnum; + /** Unique identifier of the payment_transaction_status. */ + payment_transaction_id?: string; +} + +type PaymentStatusEnum = + 'PAYMENT_STATUS_UNKNOWN' + | 'PAYMENT_STATUS_NEW' + | 'PAYMENT_STATUS_PENDING' + | 'PAYMENT_STATUS_CAPTURED' + | 'PAYMENT_STATUS_CANCELED' + | 'PAYMENT_STATUS_FAILED'; + +type PaymentTransactionStatusEnum = + 'PAYMENT_STATUS_TRANSACTION_UNKNOWN' + | 'PAYMENT_STATUS_TRANSACTION_PENDING' + | 'PAYMENT_STATUS_TRANSACTION_FAILED' + | 'PAYMENT_STATUS_TRANSACTION_SUCCESS' + | 'PAYMENT_STATUS_TRANSACTION_CANCELED'; diff --git a/packages/conversation/src/models/v1/contact-message-event/index.ts b/packages/conversation/src/models/v1/contact-message-event/index.ts new file mode 100644 index 00000000..36c08182 --- /dev/null +++ b/packages/conversation/src/models/v1/contact-message-event/index.ts @@ -0,0 +1 @@ +export type { ContactMessageEvent } from './contact-message-event'; diff --git a/packages/conversation/src/models/v1/conversation-channel-credential/conversation-channel-credential.ts b/packages/conversation/src/models/v1/conversation-channel-credential/conversation-channel-credential.ts index 717129f5..469c35d4 100644 --- a/packages/conversation/src/models/v1/conversation-channel-credential/conversation-channel-credential.ts +++ b/packages/conversation/src/models/v1/conversation-channel-credential/conversation-channel-credential.ts @@ -1,4 +1,3 @@ -import { ConversationChannel } from '../conversation-channel'; import { AppleBcCredentials, InstagramCredentials, @@ -16,7 +15,7 @@ import { /** * Enables access to the underlying messaging channel. */ -export type ConversationChannelCredential = +export type ConversationChannelCredentialRequest = ChannelCredentialsAppleBC | ChannelCredentialsInstagram | ChannelCredentialsKakaoTalk @@ -32,103 +31,171 @@ export type ConversationChannelCredential = | ChannelCredentialsWeChat | ChannelCredentialsWhatsApp; -export interface ChannelCredentialsWhatsApp extends ConversationChannelCredentialBase { +/** + * Enables access to the underlying messaging channel. + */ +export type ConversationChannelCredentialResponse = + ChannelCredentialsAppleBCResponse + | ChannelCredentialsInstagramResponse + | ChannelCredentialsKakaoTalkResponse + | ChannelCredentialsKakaoTalkChatResponse + | ChannelCredentialsLineResponse + | ChannelCredentialsMessengerResponse + | ChannelCredentialsMmsResponse + | ChannelCredentialsRcsResponse + | ChannelCredentialsSmsResponse + | ChannelCredentialsTelegramResponse + | ChannelCredentialsViberResponse + | ChannelCredentialsViberBMResponse + | ChannelCredentialsWeChatResponse + | ChannelCredentialsWhatsAppResponse; + +export interface ChannelCredentialsWhatsApp extends ConversationChannelCredentialRequestBase { channel: 'WHATSAPP'; /** @see StaticBearerCredential */ static_bearer: StaticBearerCredential; } -export interface ChannelCredentialsRcs extends ConversationChannelCredentialBase { +export interface ChannelCredentialsWhatsAppResponse + extends ChannelCredentialsWhatsApp, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsRcs extends ConversationChannelCredentialRequestBase { channel: 'RCS'; /** @see StaticBearerCredential */ static_bearer: StaticBearerCredential; } +export interface ChannelCredentialsRcsResponse + extends ChannelCredentialsRcs, ConversationChannelCredentialResponseBase {} + export type ChannelCredentialsSms = ChannelCredentialsSmsWithBearer | ChannelCredentialsSmsWithAppId; -export interface ChannelCredentialsSmsWithBearer extends ConversationChannelCredentialBase { +export type ChannelCredentialsSmsResponse + = ChannelCredentialsSmsWithBearerResponse | ChannelCredentialsSmsWithAppIdResponse; + +export interface ChannelCredentialsSmsWithBearer extends ConversationChannelCredentialRequestBase { channel: 'SMS'; /** @see StaticBearerCredential */ static_bearer: StaticBearerCredential; } -export interface ChannelCredentialsSmsWithAppId extends ConversationChannelCredentialBase { +export interface ChannelCredentialsSmsWithBearerResponse + extends ChannelCredentialsSmsWithBearer, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsSmsWithAppId extends ConversationChannelCredentialRequestBase { channel: 'SMS'; /** @see SMSCredentials */ sms_credentials: SMSCredentials; } -export interface ChannelCredentialsMessenger extends ConversationChannelCredentialBase { +export interface ChannelCredentialsSmsWithAppIdResponse + extends ChannelCredentialsSmsWithAppId, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsMessenger extends ConversationChannelCredentialRequestBase { channel: 'MESSENGER'; /** @see StaticTokenCredential */ static_token: StaticTokenCredential; } -export interface ChannelCredentialsViber extends ConversationChannelCredentialBase { +export interface ChannelCredentialsMessengerResponse + extends ChannelCredentialsMessenger, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsViber extends ConversationChannelCredentialRequestBase { channel: 'VIBER'; /** @see StaticTokenCredential */ static_token: StaticTokenCredential; } -export interface ChannelCredentialsViberBM extends ConversationChannelCredentialBase { +export interface ChannelCredentialsViberResponse + extends ChannelCredentialsViber, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsViberBM extends ConversationChannelCredentialRequestBase { channel: 'VIBERBM'; /** @see StaticBearerCredential */ static_bearer: StaticBearerCredential; } -export interface ChannelCredentialsMms extends ConversationChannelCredentialBase { +export interface ChannelCredentialsViberBMResponse + extends ChannelCredentialsViberBM, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsMms extends ConversationChannelCredentialRequestBase { channel: 'MMS'; /** @see MMSCredentials */ mms_credentials: MMSCredentials; } -export interface ChannelCredentialsInstagram extends ConversationChannelCredentialBase { +export interface ChannelCredentialsMmsResponse + extends ChannelCredentialsMms, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsInstagram extends ConversationChannelCredentialRequestBase { channel: 'INSTAGRAM'; /** @see InstagramCredentials */ instagram_credentials: InstagramCredentials; } -export interface ChannelCredentialsTelegram extends ConversationChannelCredentialBase { +export interface ChannelCredentialsInstagramResponse + extends ChannelCredentialsInstagram, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsTelegram extends ConversationChannelCredentialRequestBase { channel: 'TELEGRAM'; /** @see TelegramCredentials */ telegram_credentials: TelegramCredentials; } -export interface ChannelCredentialsKakaoTalk extends ConversationChannelCredentialBase { +export interface ChannelCredentialsTelegramResponse + extends ChannelCredentialsTelegram, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsKakaoTalk extends ConversationChannelCredentialRequestBase { channel: 'KAKAOTALK'; /** @see KakaoTalkCredentials */ kakaotalk_credentials: KakaoTalkCredentials; } -export interface ChannelCredentialsKakaoTalkChat extends ConversationChannelCredentialBase { +export interface ChannelCredentialsKakaoTalkResponse + extends ChannelCredentialsKakaoTalk, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsKakaoTalkChat extends ConversationChannelCredentialRequestBase { channel: 'KAKAOTALKCHAT'; /** @see KakaoTalkCredentials */ kakaotalkchat_credentials: KakaoTalkChatCredentials; } -export interface ChannelCredentialsLine extends ConversationChannelCredentialBase { +export interface ChannelCredentialsKakaoTalkChatResponse + extends ChannelCredentialsKakaoTalkChat, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsLine extends ConversationChannelCredentialRequestBase { channel: 'LINE'; /** @see LineCredentials */ line_credentials: LineCredentials; } -export interface ChannelCredentialsWeChat extends ConversationChannelCredentialBase { +export interface ChannelCredentialsLineResponse + extends ChannelCredentialsLine, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsWeChat extends ConversationChannelCredentialRequestBase { channel: 'WECHAT'; /** @see WeChatCredentials */ wechat_credentials: WeChatCredentials; } -export interface ChannelCredentialsAppleBC extends ConversationChannelCredentialBase { +export interface ChannelCredentialsWeChatResponse + extends ChannelCredentialsWeChat, ConversationChannelCredentialResponseBase {} + +export interface ChannelCredentialsAppleBC extends ConversationChannelCredentialRequestBase { channel: 'APPLEBC'; /** @see AppleBcCredentials */ applebc_credentials: AppleBcCredentials; } -interface ConversationChannelCredentialBase { - /** @see ConversationChannel */ - channel: ConversationChannel; +export interface ChannelCredentialsAppleBCResponse + extends ChannelCredentialsAppleBC, ConversationChannelCredentialResponseBase {} + +interface ConversationChannelCredentialRequestBase { /** The secret used to verify the channel callbacks for channels which support callback verification. The callback verification is not needed for Sinch-managed channels because the callbacks are not leaving Sinch internal networks. Max length is 256 characters. Note: leaving channel_callback_secret empty for channels with callback verification will disable the verification. */ callback_secret?: string; +} + +interface ConversationChannelCredentialResponseBase { /** * Output only. The state of the channel credentials integration. * When a channel is activated, the user is prompted for credentials that must be validated and in some cases exchanged by a long-lived token (Instagram). diff --git a/packages/conversation/src/models/v1/conversation-channel-credential/index.ts b/packages/conversation/src/models/v1/conversation-channel-credential/index.ts index 3a9afc37..3a0f7ce3 100644 --- a/packages/conversation/src/models/v1/conversation-channel-credential/index.ts +++ b/packages/conversation/src/models/v1/conversation-channel-credential/index.ts @@ -1,5 +1,5 @@ export type { - ConversationChannelCredential, + ConversationChannelCredentialResponse, ChannelIntegrationState, ChannelCredentialsAppleBC, ChannelCredentialsInstagram, @@ -17,4 +17,21 @@ export type { ChannelCredentialsWhatsApp, ChannelCredentialsSmsWithBearer, ChannelCredentialsSmsWithAppId, + ConversationChannelCredentialRequest, + ChannelCredentialsAppleBCResponse, + ChannelCredentialsInstagramResponse, + ChannelCredentialsKakaoTalkResponse, + ChannelCredentialsKakaoTalkChatResponse, + ChannelCredentialsLineResponse, + ChannelCredentialsMessengerResponse, + ChannelCredentialsMmsResponse, + ChannelCredentialsRcsResponse, + ChannelCredentialsSmsResponse, + ChannelCredentialsTelegramResponse, + ChannelCredentialsViberResponse, + ChannelCredentialsViberBMResponse, + ChannelCredentialsWeChatResponse, + ChannelCredentialsWhatsAppResponse, + ChannelCredentialsSmsWithBearerResponse, + ChannelCredentialsSmsWithAppIdResponse, } from './conversation-channel-credential'; diff --git a/packages/conversation/src/models/v1/conversation-deleted-event/conversation-deleted-event.ts b/packages/conversation/src/models/v1/conversation-deleted-event/conversation-deleted-event.ts new file mode 100644 index 00000000..fa62ac29 --- /dev/null +++ b/packages/conversation/src/models/v1/conversation-deleted-event/conversation-deleted-event.ts @@ -0,0 +1,5 @@ +export interface ConversationDeletedEvent { + + /** An empty object. Represents a conversation deleted by the contact. */ + conversation_deleted_event?: Record; +} diff --git a/packages/conversation/src/models/v1/conversation-deleted-event/index.ts b/packages/conversation/src/models/v1/conversation-deleted-event/index.ts new file mode 100644 index 00000000..0c20d8af --- /dev/null +++ b/packages/conversation/src/models/v1/conversation-deleted-event/index.ts @@ -0,0 +1 @@ +export type { ConversationDeletedEvent } from './conversation-deleted-event'; diff --git a/packages/conversation/src/models/v1/conversation-event/conversation-event.ts b/packages/conversation/src/models/v1/conversation-event/conversation-event.ts new file mode 100644 index 00000000..94115a4c --- /dev/null +++ b/packages/conversation/src/models/v1/conversation-event/conversation-event.ts @@ -0,0 +1,42 @@ +import { ChannelIdentity } from '../channel-identity'; +import { ConversationDirection, ProcessingMode } from '../enums'; +import { AppEvent } from '../app-event'; +import { ContactEvent } from '../contact-event'; +import { ContactMessageEvent } from '../contact-message-event'; + +/** + * An event on a particular channel. + */ +export type ConversationEvent = + ConversationAppEvent + | ConversationContactEvent + | ConversationContactMessageEvent; + +interface ConversationEventBase { + /** @see ConversationDirection */ + direction?: ConversationDirection; + /** The ID of the event. */ + id: string; + /** Optional. The ID of the event's conversation. Will not be present for apps in Dispatch Mode. */ + conversation_id?: string; + /** Optional. The ID of the contact. Will not be present for apps in Dispatch Mode. */ + contact_id?: string; + /** @see ChannelIdentity */ + channel_identity: ChannelIdentity; + /** */ + accept_time?: Date; + /** Whether or not Conversation API should store contacts and conversations for the app. For more information, see [Processing Modes](../../../../../conversation/processing-modes/). */ + processing_mode: ProcessingMode; +} + +interface ConversationAppEvent extends ConversationEventBase { + app_event: AppEvent; +} + +interface ConversationContactEvent extends ConversationEventBase { + contact_event: ContactEvent; +} + +interface ConversationContactMessageEvent extends ConversationEventBase { + contact_message_event: ContactMessageEvent; +} diff --git a/packages/conversation/src/models/v1/conversation-event/index.ts b/packages/conversation/src/models/v1/conversation-event/index.ts new file mode 100644 index 00000000..1ed64419 --- /dev/null +++ b/packages/conversation/src/models/v1/conversation-event/index.ts @@ -0,0 +1 @@ +export type { ConversationEvent } from './conversation-event'; diff --git a/packages/conversation/src/models/v1/conversation-message-injected/conversation-message-injected.ts b/packages/conversation/src/models/v1/conversation-message-injected/conversation-message-injected.ts deleted file mode 100644 index 0fef2a76..00000000 --- a/packages/conversation/src/models/v1/conversation-message-injected/conversation-message-injected.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { AppMessage } from '../app-message'; -import { ChannelIdentity } from '../channel-identity'; -import { ContactMessage } from '../contact-message'; -import { ConversationDirection } from '../enums'; - -/** - * A message on a particular channel. - */ -export interface ConversationMessageInjected { - - /** The processed time of the message in UTC timezone. Must be less than current_time and greater than (current_time - 30 days) */ - accept_time?: Date; - /** @see AppMessage */ - app_message?: AppMessage; - /** @see ChannelIdentity */ - channel_identity?: ChannelIdentity; - /** The ID of the contact registered in the conversation provided. */ - contact_id?: string; - /** @see ContactMessage */ - contact_message?: ContactMessage; - /** @see ConversationDirection */ - direction?: ConversationDirection; - /** Optional. Metadata associated with the contact. Up to 1024 characters long. */ - metadata?: string; -} diff --git a/packages/conversation/src/models/v1/conversation-message-injected/index.ts b/packages/conversation/src/models/v1/conversation-message-injected/index.ts deleted file mode 100644 index d7b56ce0..00000000 --- a/packages/conversation/src/models/v1/conversation-message-injected/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { ConversationMessageInjected } from './conversation-message-injected'; diff --git a/packages/conversation/src/models/v1/conversation-message/conversation-message.ts b/packages/conversation/src/models/v1/conversation-message/conversation-message.ts index 4a582556..1ee98551 100644 --- a/packages/conversation/src/models/v1/conversation-message/conversation-message.ts +++ b/packages/conversation/src/models/v1/conversation-message/conversation-message.ts @@ -6,18 +6,15 @@ import { ConversationDirection, ProcessingMode } from '../enums'; /** * A message on a particular channel. */ -export interface ConversationMessage { +export type ConversationMessage = ConversationAppMessage | ConversationContactMessage; +interface ConversationMessageBase { /** Output only. The time Conversation API processed the message. */ accept_time?: Date; - /** @see AppMessage */ - app_message?: AppMessage; /** @see ChannelIdentity */ channel_identity?: ChannelIdentity; /** The ID of the contact. */ contact_id?: string; - /** @see ContactMessage */ - contact_message?: ContactMessage; /** The ID of the conversation. */ conversation_id?: string; /** @see ConversationDirection */ @@ -28,7 +25,7 @@ export interface ConversationMessage { metadata?: string; /** Output only. Flag for whether this message was injected. */ injected?: boolean; - /** For Contact Messages the sender ID that the contact sent the message to. For App Messages the sender that was used to send the message, if applicable. */ + /** For Contact Messages the sender ID is the contact sent the message to. For App Messages the sender that was used to send the message, if applicable. */ sender_id?: string; /** Output only. The processing mode. */ processing_mode?: ProcessingMode; @@ -36,7 +33,7 @@ export interface ConversationMessage { message_status?: MessageStatus | null; } -export interface MessageStatus { +interface MessageStatus { /** Status of the message */ status: Status; /** Timestamp at which the current status occurred */ @@ -45,7 +42,7 @@ export interface MessageStatus { reason?: string } -export type Status = +type Status = 'STATUS_UNSPECIFIED' | 'QUEUED' | 'QUEUED_ON_CHANNEL' @@ -54,3 +51,13 @@ export type Status = | 'FAILED' | 'SWITCHING_CHANNEL' | 'RECEIVED'; + +interface ConversationAppMessage extends ConversationMessageBase { + /** @see AppMessage */ + app_message?: AppMessage; +} + +interface ConversationContactMessage extends ConversationMessageBase { + /** @see ContactMessage */ + contact_message?: ContactMessage; +} diff --git a/packages/conversation/src/models/v1/conversation-recent-message/conversation-recent-message.ts b/packages/conversation/src/models/v1/conversation-recent-message/conversation-recent-message.ts new file mode 100644 index 00000000..9d22188c --- /dev/null +++ b/packages/conversation/src/models/v1/conversation-recent-message/conversation-recent-message.ts @@ -0,0 +1,10 @@ +import { Conversation } from '../conversation'; +import { ConversationMessage } from '../conversation-message'; + +export interface ConversationRecentMessage { + + /** @see Conversation */ + conversation?: Conversation; + /** @see ConversationMessage */ + last_message?: ConversationMessage; +} diff --git a/packages/conversation/src/models/v1/conversation-recent-message/index.ts b/packages/conversation/src/models/v1/conversation-recent-message/index.ts new file mode 100644 index 00000000..673f5f72 --- /dev/null +++ b/packages/conversation/src/models/v1/conversation-recent-message/index.ts @@ -0,0 +1 @@ +export type { ConversationRecentMessage } from './conversation-recent-message'; diff --git a/packages/conversation/src/models/v1/conversation/conversation.ts b/packages/conversation/src/models/v1/conversation/conversation.ts index 4bfde51d..5a8fa064 100644 --- a/packages/conversation/src/models/v1/conversation/conversation.ts +++ b/packages/conversation/src/models/v1/conversation/conversation.ts @@ -17,10 +17,15 @@ export interface Conversation { id?: string; /** The timestamp of the latest message in the conversation. The timestamp will be Thursday January 01, 1970 00:00:00 UTC if the conversation contains no messages. */ last_received?: Date; - /** Arbitrary data set by the Conversation API clients. Up to 1024 characters long. */ + /** + * Arbitrary data set by the Conversation API clients. Up to 1024 characters long. + * NOTE: This field has been deprecated due to changes in the system architecture or functionality. + * It is no longer actively maintained and may be removed in future versions. Please avoid relying on this field in new code. + * @deprecated + */ metadata?: string; /** Arbitrary data set by the Conversation API clients and/or provided in the `conversation_metadata` field of a SendMessageRequest. A valid JSON object. */ metadata_json?: object; - /** Up to 128 characters long */ + /** Arbitrary correlation ID related to the MT message set by the Conversation API user. Up to 128 characters long. */ correlation_id?: string; } diff --git a/packages/conversation/src/models/v1/delivery-report-based-fallback/delivery-report-based-fallback.ts b/packages/conversation/src/models/v1/delivery-report-based-fallback/delivery-report-based-fallback.ts new file mode 100644 index 00000000..20ea44b4 --- /dev/null +++ b/packages/conversation/src/models/v1/delivery-report-based-fallback/delivery-report-based-fallback.ts @@ -0,0 +1,11 @@ + +/** + * This object contains additional settings related to [delivery report based fallback](../../../../../conversation/keyconcepts/#delivery-report-base-message-fallback). Note that this **paid** functionality is available for open beta testing. + */ +export interface DeliveryReportBasedFallback { + + /** Optional. A flag specifying whether this app has enabled fallback message delivery upon no positive delivery report. This feature is applicable only to messages which are sent to a recipient with more than one channel identity. Identities must be defined on channels which support at least the \'DELIVERED\' message state. **Please note that this functionality requires payment.** */ + enabled?: boolean; + /** Optional. The time, in seconds, after which a message without a positive delivery report will fallback to the next channel. The valid values for this field are [60 - 259200]. */ + delivery_report_waiting_time?: number; +} diff --git a/packages/conversation/src/models/v1/delivery-report-based-fallback/index.ts b/packages/conversation/src/models/v1/delivery-report-based-fallback/index.ts new file mode 100644 index 00000000..7adcf45b --- /dev/null +++ b/packages/conversation/src/models/v1/delivery-report-based-fallback/index.ts @@ -0,0 +1 @@ +export type { DeliveryReportBasedFallback } from './delivery-report-based-fallback'; diff --git a/packages/conversation/src/models/v1/enums.ts b/packages/conversation/src/models/v1/enums.ts index 27013a18..1a57f48b 100644 --- a/packages/conversation/src/models/v1/enums.ts +++ b/packages/conversation/src/models/v1/enums.ts @@ -1,7 +1,3 @@ -export type { - PaymentStatusEnum as PaymentStatusUpdateEventPaymentStatusEnum, - PaymentTransactionStatusEnum as PaymentStatusUpdateEventPaymentTransactionStatusEnum, -} from './mod-callback-events/event-inbound/event-inbound'; export type { SentimentResult as MachineLearningSentimentEnum, EvaluationEnum as OffensiveAnalysisEvaluationEnum, diff --git a/packages/conversation/src/models/v1/generic-event/generic-event.ts b/packages/conversation/src/models/v1/generic-event/generic-event.ts index ba798d21..62f9a59b 100644 --- a/packages/conversation/src/models/v1/generic-event/generic-event.ts +++ b/packages/conversation/src/models/v1/generic-event/generic-event.ts @@ -1,9 +1,10 @@ export interface GenericEvent { - /** @see GenericEvent */ + /** Event that contains only a flexible payload field. */ generic_event?: GenericEventItem; } export interface GenericEventItem { + /** Arbitrary data set to the event. A valid JSON object */ payload: object; } diff --git a/packages/conversation/src/models/v1/index.ts b/packages/conversation/src/models/v1/index.ts index 44718df9..865c0693 100644 --- a/packages/conversation/src/models/v1/index.ts +++ b/packages/conversation/src/models/v1/index.ts @@ -19,27 +19,37 @@ export * from './choice'; export * from './choice-message'; export * from './choice-response-message'; export * from './client-credentials'; +export * from './comment-event'; export * from './comment-reply-event'; export * from './composing-end-event'; export * from './composing-event'; export * from './contact'; export * from './contact-create-request'; +export * from './contact-event'; export * from './contact-id'; +export * from './contact-info-message'; export * from './contact-language'; export * from './contact-message'; +export * from './contact-message-event'; export * from './conversation'; export * from './conversation-channel'; export * from './conversation-channel-credential'; +export * from './conversation-deleted-event'; +export * from './conversation-event'; export * from './conversation-message'; -export * from './conversation-message-injected'; +export * from './conversation-recent-message'; export * from './coordinates'; export * from './create-conversation-request'; +export * from './delivery-report-based-fallback'; export * from './dispatch-retention-policy'; export * from './fallback-message'; export * from './generic-event'; export * from './get-channel-profile-request'; export * from './get-channel-profile-response'; export * from './identified-by'; +export * from './inject-conversation-event-request'; +export * from './inject-event-response'; +export * from './inject-message-request'; export * from './list-apps-response'; export * from './list-message'; export * from './list-message-message-properties'; @@ -50,6 +60,7 @@ export * from './media-card-message'; export * from './media-carousel-message'; export * from './media-message'; export * from './merge-contact-request'; +export * from './message-retry-settings'; export * from './product'; export * from './error-detail'; export * from './lookup-capability'; @@ -72,6 +83,7 @@ export * from './template-variable'; export * from './text-message'; export * from './transcode-message-request'; export * from './transcode-message-response'; +export * from './update-message-request'; export * from './url-message'; export * from './v1-list-templates-response'; export * from './v1-template'; diff --git a/packages/conversation/src/models/v1/inject-conversation-event-request/index.ts b/packages/conversation/src/models/v1/inject-conversation-event-request/index.ts new file mode 100644 index 00000000..7d444a63 --- /dev/null +++ b/packages/conversation/src/models/v1/inject-conversation-event-request/index.ts @@ -0,0 +1 @@ +export type { InjectConversationEventRequest } from './inject-conversation-event-request'; diff --git a/packages/conversation/src/models/v1/inject-conversation-event-request/inject-conversation-event-request.ts b/packages/conversation/src/models/v1/inject-conversation-event-request/inject-conversation-event-request.ts new file mode 100644 index 00000000..2144d3c2 --- /dev/null +++ b/packages/conversation/src/models/v1/inject-conversation-event-request/inject-conversation-event-request.ts @@ -0,0 +1,32 @@ +import { ChannelIdentity } from '../channel-identity'; +import { AppEvent } from '../app-event'; +import { ContactEvent } from '../contact-event'; +import { ProcessingMode } from '../enums'; + +/** + * Inject Event request + */ +export type InjectConversationEventRequest = InjectConversationAppEvent | InjectConversationContactEvent; + +interface InjectConversationEventBase { + /** Optional. The ID of the event\'s conversation. Will not be present for apps in Dispatch Mode. */ + conversation_id?: string; + /** Optional. The ID of the contact. Will not be present for apps in Dispatch Mode. */ + contact_id?: string; + /** @see ChannelIdentity */ + channel_identity?: ChannelIdentity; + /** The processed time of the message in UTC timezone. Must be less than current_time and greater than (current_time - 30 days). */ + accept_time: Date; + /** Whether or not Conversation API should store contacts and conversations for the app. For more information, see [Processing Modes](../../../../../conversation/processing-modes/). */ + processing_mode?: ProcessingMode; +} + +interface InjectConversationAppEvent extends InjectConversationEventBase { + /** @see AppEvent */ + app_event: AppEvent; +} + +interface InjectConversationContactEvent extends InjectConversationEventBase { + /** @see AppEvent */ + contact_event: ContactEvent +} diff --git a/packages/conversation/src/models/v1/inject-event-response/index.ts b/packages/conversation/src/models/v1/inject-event-response/index.ts new file mode 100644 index 00000000..349c8b4e --- /dev/null +++ b/packages/conversation/src/models/v1/inject-event-response/index.ts @@ -0,0 +1 @@ +export type { InjectEventResponse } from './inject-event-response'; diff --git a/packages/conversation/src/models/v1/inject-event-response/inject-event-response.ts b/packages/conversation/src/models/v1/inject-event-response/inject-event-response.ts new file mode 100644 index 00000000..5ddb9370 --- /dev/null +++ b/packages/conversation/src/models/v1/inject-event-response/inject-event-response.ts @@ -0,0 +1,8 @@ + +export interface InjectEventResponse { + + /** Event id. */ + event_id?: string; + /** @see string */ + accepted_time?: Date; +} diff --git a/packages/conversation/src/models/v1/inject-message-request/index.ts b/packages/conversation/src/models/v1/inject-message-request/index.ts new file mode 100644 index 00000000..660d6169 --- /dev/null +++ b/packages/conversation/src/models/v1/inject-message-request/index.ts @@ -0,0 +1 @@ +export type { InjectMessageRequest } from './inject-message-request'; diff --git a/packages/conversation/src/models/v1/inject-message-request/inject-message-request.ts b/packages/conversation/src/models/v1/inject-message-request/inject-message-request.ts new file mode 100644 index 00000000..dfff0080 --- /dev/null +++ b/packages/conversation/src/models/v1/inject-message-request/inject-message-request.ts @@ -0,0 +1,41 @@ +import { AppMessage } from '../app-message'; +import { ChannelIdentity } from '../channel-identity'; +import { ContactMessage } from '../contact-message'; +import { ConversationDirection, ProcessingMode } from '../enums'; + +/** + * A message on a particular channel. + */ +export type InjectMessageRequest = InjectAppMessageRequest | InjectContactMessageRequest; + +interface InjectMessageRequestBase { + + /** The processed time of the message in UTC timezone. Must be less than current_time and greater than (current_time - 30 days) */ + accept_time?: Date; + /** @see ChannelIdentity */ + channel_identity?: ChannelIdentity; + /** The ID of the contact registered in the conversation provided. */ + contact_id?: string; + /** @see ConversationDirection */ + direction?: ConversationDirection; + /** The ID of the conversation. */ + conversation_id?: string; + /** Flag for whether this message was injected. */ + injected?: boolean; + /** For Contact Messages the sender ID is the contact sent the message to. For App Messages the sender that was used to send the message, if applicable. */ + sender_id?: string; + /** Whether or not Conversation API should store contacts and conversations for the app. For more information, see [Processing Modes](../../../../../conversation/processing-modes/). */ + processing_mode?: ProcessingMode; + /** Optional. Metadata associated with the contact. Up to 1024 characters long. */ + metadata?: string; +} + +interface InjectAppMessageRequest extends InjectMessageRequestBase { + /** @see AppMessage */ + app_message?: AppMessage; +} + +interface InjectContactMessageRequest extends InjectMessageRequestBase { + /** @see ContactMessage */ + contact_message?: ContactMessage; +} diff --git a/packages/conversation/src/models/v1/message-retry-settings/index.ts b/packages/conversation/src/models/v1/message-retry-settings/index.ts new file mode 100644 index 00000000..5c23f364 --- /dev/null +++ b/packages/conversation/src/models/v1/message-retry-settings/index.ts @@ -0,0 +1 @@ +export type { MessageRetrySettings } from './message-retry-settings'; diff --git a/packages/conversation/src/models/v1/message-retry-settings/message-retry-settings.ts b/packages/conversation/src/models/v1/message-retry-settings/message-retry-settings.ts new file mode 100644 index 00000000..6c763544 --- /dev/null +++ b/packages/conversation/src/models/v1/message-retry-settings/message-retry-settings.ts @@ -0,0 +1,14 @@ + +/** + * This object contains settings related to message retry mechanism. + */ +export interface MessageRetrySettings { + + /** + * The maximum duration, in seconds, for which to retry sending a message in case of a temporary processing failure. Time is counted after the first message processing failure. At least one retry is guaranteed. + * Subsequent retry times are randomized with exponential backoff. If the next retry timestamp exceeds the configured time, one last retry will be performed on the cut-off time. + * If the message has a configured fallback channel, a switch_on_channel will be triggered. + * The valid values for this field are [30 - 3600]. Default value is 3600 (seconds - 1 hour). + */ + retry_duration?: number; +} diff --git a/packages/conversation/src/models/v1/mod-callback-events/capability-event/capability-event.ts b/packages/conversation/src/models/v1/mod-callback-events/capability-event/capability-event.ts index 233d8420..327cda2c 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/capability-event/capability-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/capability-event/capability-event.ts @@ -1,11 +1,11 @@ import { ConversationChannel } from '../../conversation-channel'; import { Reason } from '../../reason'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback is used to deliver the results of the asynchronous capability checks. */ -export interface CapabilityEvent extends ConversationEvent { +export interface CapabilityEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/channel-event/channel-event.ts b/packages/conversation/src/models/v1/mod-callback-events/channel-event/channel-event.ts index 8b95f9e6..fb2ac2ae 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/channel-event/channel-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/channel-event/channel-event.ts @@ -1,10 +1,10 @@ import { ConversationChannel } from '../../conversation-channel'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback is used to deliver notifications regarding channel-specific information and updates. For example, if your are using the WhatsApp channel of the Conversation API, and your quality rating has been changed to GREEN, a POST would be made to the CHANNEL_EVENT webhook. */ -export interface ChannelEvent extends ConversationEvent { +export interface ChannelEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/contact-create-event/contact-create-event.ts b/packages/conversation/src/models/v1/mod-callback-events/contact-create-event/contact-create-event.ts index e3d12a75..f565f134 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/contact-create-event/contact-create-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/contact-create-event/contact-create-event.ts @@ -1,10 +1,10 @@ import { ContactNotification } from '../contact-notification'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback is sent when a new contact is created. */ -export interface ContactCreateEvent extends ConversationEvent { +export interface ContactCreateEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/contact-delete-event/contact-delete-event.ts b/packages/conversation/src/models/v1/mod-callback-events/contact-delete-event/contact-delete-event.ts index ef4f9263..a4c4cbf6 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/contact-delete-event/contact-delete-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/contact-delete-event/contact-delete-event.ts @@ -1,10 +1,10 @@ import { ContactNotification } from '../contact-notification'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback is sent when a new contact is deleted. */ -export interface ContactDeleteEvent extends ConversationEvent { +export interface ContactDeleteEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/contact-identities-duplication-event/contact-identities-duplication-event.ts b/packages/conversation/src/models/v1/mod-callback-events/contact-identities-duplication-event/contact-identities-duplication-event.ts index 055f413f..3605c122 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/contact-identities-duplication-event/contact-identities-duplication-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/contact-identities-duplication-event/contact-identities-duplication-event.ts @@ -1,10 +1,10 @@ import { ConversationChannel } from '../../conversation-channel'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback is sent when duplicates of channel identities are found between multiple contacts in the contact database during message and event processing. */ -export interface ContactIdentitiesDuplicationEvent extends ConversationEvent { +export interface ContactIdentitiesDuplicationEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/contact-merge-event/contact-merge-event.ts b/packages/conversation/src/models/v1/mod-callback-events/contact-merge-event/contact-merge-event.ts index cc74b054..824c9338 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/contact-merge-event/contact-merge-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/contact-merge-event/contact-merge-event.ts @@ -1,10 +1,10 @@ import { Contact } from '../../contact'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback is sent when two contacts are merged. */ -export interface ContactMergeEvent extends ConversationEvent { +export interface ContactMergeEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/contact-update-event/contact-update-event.ts b/packages/conversation/src/models/v1/mod-callback-events/contact-update-event/contact-update-event.ts index 719f0169..e5a1af19 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/contact-update-event/contact-update-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/contact-update-event/contact-update-event.ts @@ -1,10 +1,10 @@ import { ContactNotification } from '../contact-notification'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback is sent when a new contact is updated. */ -export interface ContactUpdateEvent extends ConversationEvent{ +export interface ContactUpdateEvent extends ConversationCallbackEvent{ /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/conversation-event/conversation-event.ts b/packages/conversation/src/models/v1/mod-callback-events/conversation-callback-event/conversation-callback-event.ts similarity index 65% rename from packages/conversation/src/models/v1/mod-callback-events/conversation-event/conversation-event.ts rename to packages/conversation/src/models/v1/mod-callback-events/conversation-callback-event/conversation-callback-event.ts index d6feeb32..8c31b3b5 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/conversation-event/conversation-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/conversation-callback-event/conversation-callback-event.ts @@ -1,5 +1,5 @@ import { WebhookTrigger } from '../../webhook-trigger'; -export interface ConversationEvent { +export interface ConversationCallbackEvent { trigger: WebhookTrigger; } diff --git a/packages/conversation/src/models/v1/mod-callback-events/conversation-callback-event/index.ts b/packages/conversation/src/models/v1/mod-callback-events/conversation-callback-event/index.ts new file mode 100644 index 00000000..2d95caea --- /dev/null +++ b/packages/conversation/src/models/v1/mod-callback-events/conversation-callback-event/index.ts @@ -0,0 +1 @@ +export { ConversationCallbackEvent } from './conversation-callback-event'; diff --git a/packages/conversation/src/models/v1/mod-callback-events/conversation-delete-event/conversation-delete-event.ts b/packages/conversation/src/models/v1/mod-callback-events/conversation-delete-event/conversation-delete-event.ts index 4979d938..75472520 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/conversation-delete-event/conversation-delete-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/conversation-delete-event/conversation-delete-event.ts @@ -1,10 +1,10 @@ import { Conversation } from '../../conversation'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback is sent when a conversation between the subscribed app and a contact is deleted. */ -export interface ConversationDeleteEvent extends ConversationEvent { +export interface ConversationDeleteEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/conversation-event/index.ts b/packages/conversation/src/models/v1/mod-callback-events/conversation-event/index.ts deleted file mode 100644 index 782519a5..00000000 --- a/packages/conversation/src/models/v1/mod-callback-events/conversation-event/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { ConversationEvent } from './conversation-event'; diff --git a/packages/conversation/src/models/v1/mod-callback-events/conversation-start-event/conversation-start-event.ts b/packages/conversation/src/models/v1/mod-callback-events/conversation-start-event/conversation-start-event.ts index 395ede02..df2d8197 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/conversation-start-event/conversation-start-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/conversation-start-event/conversation-start-event.ts @@ -1,10 +1,10 @@ import { Conversation } from '../../conversation'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback is sent when a new conversation between the subscribed app and a contact is started. */ -export interface ConversationStartEvent extends ConversationEvent { +export interface ConversationStartEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/conversation-stop-event/conversation-stop-event.ts b/packages/conversation/src/models/v1/mod-callback-events/conversation-stop-event/conversation-stop-event.ts index f382b33c..bbcee752 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/conversation-stop-event/conversation-stop-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/conversation-stop-event/conversation-stop-event.ts @@ -1,10 +1,10 @@ import { Conversation } from '../../conversation'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback is sent when a conversation between the subscribed app and a contact is stopped. */ -export interface ConversationStopEvent extends ConversationEvent { +export interface ConversationStopEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/conversation-webhook-event/conversation-webhook-event.ts b/packages/conversation/src/models/v1/mod-callback-events/conversation-webhook-event/conversation-webhook-event.ts index 15dea601..3fde71ca 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/conversation-webhook-event/conversation-webhook-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/conversation-webhook-event/conversation-webhook-event.ts @@ -18,6 +18,7 @@ import { OptOutEvent } from '../opt-out-event'; import { ChannelEvent } from '../channel-event'; import { UnsupportedCallbackEvent } from '../unsupported-callback-event'; import { SmartConversationsEvent } from '../smart-conversations-event'; +import { RecordNotificationEvent } from '../record-notification'; export type ConversationWebhookEvent = MessageInboundEvent @@ -39,4 +40,5 @@ export type ConversationWebhookEvent = | OptOutEvent | ChannelEvent | SmartConversationsEvent + | RecordNotificationEvent | UnsupportedCallbackEvent; diff --git a/packages/conversation/src/models/v1/mod-callback-events/event-delivery/event-delivery.ts b/packages/conversation/src/models/v1/mod-callback-events/event-delivery/event-delivery.ts index 67257cb2..1ead2b75 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/event-delivery/event-delivery.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/event-delivery/event-delivery.ts @@ -1,9 +1,9 @@ import { ChannelIdentity } from '../../channel-identity'; import { Reason } from '../../reason'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; import { DeliveryStatus, ProcessingMode } from '../../enums'; -export interface EventDelivery extends ConversationEvent{ +export interface EventDelivery extends ConversationCallbackEvent{ /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/event-inbound/event-inbound.ts b/packages/conversation/src/models/v1/mod-callback-events/event-inbound/event-inbound.ts index 546238ee..7d1e03df 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/event-inbound/event-inbound.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/event-inbound/event-inbound.ts @@ -1,8 +1,10 @@ import { ChannelIdentity } from '../../channel-identity'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; import { ProcessingMode } from '../../enums'; +import { ContactEvent } from '../../contact-event'; +import { ContactMessageEvent } from '../../contact-message-event'; -export interface EventInbound extends ConversationEvent { +export interface EventInbound extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; @@ -43,65 +45,3 @@ export interface EventInboundEvent { /** @see ProcessingMode */ processing_mode?: ProcessingMode; } - -export interface ContactEvent { - - /** Empty object denoting the contact is composing a message. */ - composing_event?: object; - /** @see CommentEvent */ - comment_event?: CommentEvent; -} - -/** - * Object which contains information of a comment made by a user outside the main conversation context. Currently only supported on Instagram channel, see Instagram Private Replies for more details - */ -export interface CommentEvent { - /** Event\'s ID */ - id?: string; - /** Comment\'s text */ - text?: string; - /** Either LIVE or FEED. Indicates the type of media on which the comment was made. */ - comment_type?: 'FEED' | 'LIVE'; - /** Instagram\'s URL of the live broadcast or the post on which the comment was made (permalink). */ - commented_on?: string; - /** Username of the account that commented in the live broadcast or post. */ - user?: string; -} - -/** - * The content of the event when contact_event is not populated. Note that this object is currently only available to select customers for beta testing. Mutually exclusive with contact_event. - */ -export interface ContactMessageEvent { - - /** @see ContactMessageEventPaymentStatusUpdateEvent */ - payment_status_update_event?: PaymentStatusUpdateEvent; -} - -/** - * Object reflecting the current state of a particular payment flow. - */ -export interface PaymentStatusUpdateEvent { - - /** Unique identifier for the corresponding payment of a particular order. */ - reference_id?: string; - /** The stage the payment has reached within the payment flow. */ - payment_status?: PaymentStatusEnum; - /** The status of the stage detailed in payment_status. */ - payment_transaction_status?: PaymentTransactionStatusEnum; - /** Unique identifier of the payment_transaction_status. */ - payment_transaction_id?: string; -} -export type PaymentStatusEnum = - 'PAYMENT_STATUS_UNKNOWN' - | 'PAYMENT_STATUS_NEW' - | 'PAYMENT_STATUS_PENDING' - | 'PAYMENT_STATUS_CAPTURED' - | 'PAYMENT_STATUS_CANCELED' - | 'PAYMENT_STATUS_FAILED'; - -export type PaymentTransactionStatusEnum = - 'PAYMENT_STATUS_TRANSACTION_UNKNOWN' - | 'PAYMENT_STATUS_TRANSACTION_PENDING' - | 'PAYMENT_STATUS_TRANSACTION_FAILED' - | 'PAYMENT_STATUS_TRANSACTION_SUCCESS' - | 'PAYMENT_STATUS_TRANSACTION_CANCELED'; diff --git a/packages/conversation/src/models/v1/mod-callback-events/event-inbound/index.ts b/packages/conversation/src/models/v1/mod-callback-events/event-inbound/index.ts index 5f7f4f04..9456d333 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/event-inbound/index.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/event-inbound/index.ts @@ -1,8 +1 @@ -export type { - EventInbound, - EventInboundEvent, - ContactEvent, - CommentEvent, - ContactMessageEvent, - PaymentStatusUpdateEvent, -} from './event-inbound'; +export type { EventInbound, EventInboundEvent } from './event-inbound'; diff --git a/packages/conversation/src/models/v1/mod-callback-events/index.ts b/packages/conversation/src/models/v1/mod-callback-events/index.ts index cdfbe384..79dbc51c 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/index.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/index.ts @@ -17,6 +17,7 @@ export * from './message-inbound-event-item'; export * from './message-inbound-smart-conversation-redaction-event'; export * from './opt-in-event'; export * from './opt-out-event'; +export * from './record-notification'; export * from './message-delivery-receipt-event'; export * from './message-submit-event'; export * from './smart-conversations-event'; diff --git a/packages/conversation/src/models/v1/mod-callback-events/message-delivery-receipt-event/message-delivery-receipt-event.ts b/packages/conversation/src/models/v1/mod-callback-events/message-delivery-receipt-event/message-delivery-receipt-event.ts index cb82f2fc..2102adf1 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/message-delivery-receipt-event/message-delivery-receipt-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/message-delivery-receipt-event/message-delivery-receipt-event.ts @@ -1,12 +1,12 @@ import { ChannelIdentity } from '../../channel-identity'; import { Reason } from '../../reason'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; import { DeliveryStatus, ProcessingMode } from '../../enums'; /** * This callback notifies the API clients about status changes of already sent app message. */ -export interface MessageDeliveryReceiptEvent extends ConversationEvent { +export interface MessageDeliveryReceiptEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/message-inbound-event/message-inbound-event.ts b/packages/conversation/src/models/v1/mod-callback-events/message-inbound-event/message-inbound-event.ts index fc3b7342..802db790 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/message-inbound-event/message-inbound-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/message-inbound-event/message-inbound-event.ts @@ -1,10 +1,10 @@ import { MessageInboundEventItem } from '../message-inbound-event-item'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback delivers contact (end-user) messages to the API clients. */ -export interface MessageInboundEvent extends ConversationEvent { +export interface MessageInboundEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/message-inbound-smart-conversation-redaction-event/message-inbound-smart-conversation-redaction-event.ts b/packages/conversation/src/models/v1/mod-callback-events/message-inbound-smart-conversation-redaction-event/message-inbound-smart-conversation-redaction-event.ts index c54b9149..fe4d5b0b 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/message-inbound-smart-conversation-redaction-event/message-inbound-smart-conversation-redaction-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/message-inbound-smart-conversation-redaction-event/message-inbound-smart-conversation-redaction-event.ts @@ -1,10 +1,10 @@ import { MessageInboundEventItem } from '../message-inbound-event-item'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * This callback delivers contact (end-user) messages to the API clients. The content of the message goes through an A.I. analysis and is redacted if required. */ -export interface MessageInboundSmartConversationRedactionEvent extends ConversationEvent { +export interface MessageInboundSmartConversationRedactionEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/message-submit-event/message-submit-event.ts b/packages/conversation/src/models/v1/mod-callback-events/message-submit-event/message-submit-event.ts index f349d54e..269d59a4 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/message-submit-event/message-submit-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/message-submit-event/message-submit-event.ts @@ -1,12 +1,12 @@ import { ChannelIdentity } from '../../channel-identity'; import { ContactMessage } from '../../contact-message'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; import { ProcessingMode } from '../../enums'; /** * This callback provides a notification to the API clients that the corresponding app message was submitted to a channel. This notification is created before any confirmation from Delivery Receipts. */ -export interface MessageSubmitEvent extends ConversationEvent { +export interface MessageSubmitEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/opt-in-event/opt-in-event.ts b/packages/conversation/src/models/v1/mod-callback-events/opt-in-event/opt-in-event.ts index 47f7a321..30d7f15a 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/opt-in-event/opt-in-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/opt-in-event/opt-in-event.ts @@ -1,11 +1,11 @@ import { ConversationChannel } from '../../conversation-channel'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; import { ProcessingMode } from '../../enums'; /** * This callback is used to deliver opt-in notifications from the channels. */ -export interface OptInEvent extends ConversationEvent { +export interface OptInEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/opt-out-event/opt-out-event.ts b/packages/conversation/src/models/v1/mod-callback-events/opt-out-event/opt-out-event.ts index b49bf771..c6286298 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/opt-out-event/opt-out-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/opt-out-event/opt-out-event.ts @@ -1,11 +1,11 @@ import { ConversationChannel } from '../../conversation-channel'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; import { ProcessingMode } from '../../enums'; /** * This callback is used to deliver opt-out notifications from the channels. */ -export interface OptOutEvent extends ConversationEvent { +export interface OptOutEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/record-notification/index.ts b/packages/conversation/src/models/v1/mod-callback-events/record-notification/index.ts new file mode 100644 index 00000000..73402c55 --- /dev/null +++ b/packages/conversation/src/models/v1/mod-callback-events/record-notification/index.ts @@ -0,0 +1 @@ +export type { RecordNotificationEvent, RecordNotification } from './record-notification'; diff --git a/packages/conversation/src/models/v1/mod-callback-events/record-notification/record-notification.ts b/packages/conversation/src/models/v1/mod-callback-events/record-notification/record-notification.ts new file mode 100644 index 00000000..b862c479 --- /dev/null +++ b/packages/conversation/src/models/v1/mod-callback-events/record-notification/record-notification.ts @@ -0,0 +1,46 @@ +import { ConversationCallbackEvent } from '../conversation-callback-event'; +import { ChannelIdentity } from '../../channel-identity'; +import { ProcessingMode } from '../../enums'; +import { Reason } from '../../reason'; + +export interface RecordNotificationEvent extends ConversationCallbackEvent { + + /** Id of the subscribed app. */ + app_id?: string; + /** Timestamp marking when the channel callback was accepted/received by the Conversation API. */ + accepted_time?: Date; + /** Timestamp of the event as provided by the underlying channels. */ + event_time?: Date; + /** The project ID of the app which has subscribed for the callback. */ + project_id?: string; + /** Context-dependent metadata. Refer to specific callback's documentation for exact information provided. */ + message_metadata?: string; + /** The value provided in field correlation_id of a send message request. */ + correlation_id?: string; + /** @see SmartConversationNotification */ + record_notification?: RecordNotification; + /** Name of the trigger responsible for this event. */ + trigger: 'RECORD_NOTIFICATION'; +} + +export interface RecordNotification { + /** Required. The ID of the entity. */ + entityId: string; + /** Required. The stored status. */ + recordStatus: RecordStatus; + /** Required. The processing mode. */ + processingMode: ProcessingMode; + /** The channel and contact channel identity of the entity. */ + channelIdentity?: ChannelIdentity + /** Optional. The ID of the contact. Will not be present for apps in Dispatch Mode. */ + contactId: string; + /** Optional. The ID of the conversation. Will not be present for apps in Dispatch Mode. */ + conversationId: string; + /** Optional. A reason will be present if the status is FAILED. */ + reason: Reason; +} + + +type RecordStatus = 'RECORD_STATUS_UNSPECIFIED' + | 'EVENT_RECORD_STORED' + | 'UNRECOGNIZED'; diff --git a/packages/conversation/src/models/v1/mod-callback-events/smart-conversations-event/smart-conversations-event.ts b/packages/conversation/src/models/v1/mod-callback-events/smart-conversations-event/smart-conversations-event.ts index 4c4bfb48..4c6de56d 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/smart-conversations-event/smart-conversations-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/smart-conversations-event/smart-conversations-event.ts @@ -1,10 +1,10 @@ import { ConversationChannel } from '../../conversation-channel'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; /** * When using the Smart Conversations functionality, Machine Learning and Artificial Intelligence analyses are delivered through specific callbacks on the Conversation API. */ -export interface SmartConversationsEvent extends ConversationEvent{ +export interface SmartConversationsEvent extends ConversationCallbackEvent{ /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-callback-events/unsupported-callback-event/unsupported-callback-event.ts b/packages/conversation/src/models/v1/mod-callback-events/unsupported-callback-event/unsupported-callback-event.ts index 0a602d0e..d2b59066 100644 --- a/packages/conversation/src/models/v1/mod-callback-events/unsupported-callback-event/unsupported-callback-event.ts +++ b/packages/conversation/src/models/v1/mod-callback-events/unsupported-callback-event/unsupported-callback-event.ts @@ -1,12 +1,12 @@ import { ConversationChannel } from '../../conversation-channel'; import { ChannelIdentity } from '../../channel-identity'; -import { ConversationEvent } from '../conversation-event'; +import { ConversationCallbackEvent } from '../conversation-callback-event'; import { ProcessingMode } from '../../enums'; /** * Some of the callbacks received from the underlying channels might be specific to a single channel or may not have a proper mapping in Conversation API yet. */ -export interface UnsupportedCallbackEvent extends ConversationEvent { +export interface UnsupportedCallbackEvent extends ConversationCallbackEvent { /** Id of the subscribed app. */ app_id?: string; diff --git a/packages/conversation/src/models/v1/mod-credentials/kakaotalkchat-credentials/kakaotalkchat-credentials.ts b/packages/conversation/src/models/v1/mod-credentials/kakaotalkchat-credentials/kakaotalkchat-credentials.ts index 3b5b32eb..3a8716af 100644 --- a/packages/conversation/src/models/v1/mod-credentials/kakaotalkchat-credentials/kakaotalkchat-credentials.ts +++ b/packages/conversation/src/models/v1/mod-credentials/kakaotalkchat-credentials/kakaotalkchat-credentials.ts @@ -3,7 +3,7 @@ */ export interface KakaoTalkChatCredentials { - /** KakaoTalk Business Channel ID. */ + /** KakaoTalk Plus friend ID. */ kakaotalk_plus_friend_id: string; /** InfoBank API KEY. */ api_key?: string diff --git a/packages/conversation/src/models/v1/mod-credentials/mms-credentials/mms-credentials.ts b/packages/conversation/src/models/v1/mod-credentials/mms-credentials/mms-credentials.ts index 1cd34b37..8e9464ef 100644 --- a/packages/conversation/src/models/v1/mod-credentials/mms-credentials/mms-credentials.ts +++ b/packages/conversation/src/models/v1/mod-credentials/mms-credentials/mms-credentials.ts @@ -11,6 +11,6 @@ export interface MMSCredentials { api_key: string; /** @see BasicAuthCredential */ basic_auth: BasicAuthCredential; - /** Default Sender (shortcode or longnumber), will be used when {{YOUR_MMS_SENDER}} in a message is empty */ + /** Default Sender (shortcode or longnumber), will be used when MMS_SENDER property not set */ default_sender?: string; } diff --git a/packages/conversation/src/models/v1/reason/reason.ts b/packages/conversation/src/models/v1/reason/reason.ts index ea73407a..de7212cf 100644 --- a/packages/conversation/src/models/v1/reason/reason.ts +++ b/packages/conversation/src/models/v1/reason/reason.ts @@ -32,7 +32,11 @@ export type ReasonCode = 'UNKNOWN' | 'CHANNEL_REJECT' | 'NO_PERMISSION' | 'NO_PROFILE_AVAILABLE' - | 'UNSUPPORTED_OPERATION'; + | 'UNSUPPORTED_OPERATION' + | 'INACTIVE_CREDENTIAL' + | 'MESSAGE_EXPIRED' + | 'MESSAGE_SPLIT_REQUIRED' + | 'DELIVERY_REPORT_TIME_OUT'; export type ReasonSubCode = 'UNSPECIFIED_SUB_CODE' | 'ATTACHMENT_REJECTED' diff --git a/packages/conversation/src/models/v1/update-message-request/index.ts b/packages/conversation/src/models/v1/update-message-request/index.ts new file mode 100644 index 00000000..05bba6ca --- /dev/null +++ b/packages/conversation/src/models/v1/update-message-request/index.ts @@ -0,0 +1 @@ +export type { UpdateMessageRequest } from './update-message-request'; diff --git a/packages/conversation/src/models/v1/update-message-request/update-message-request.ts b/packages/conversation/src/models/v1/update-message-request/update-message-request.ts new file mode 100644 index 00000000..6862924f --- /dev/null +++ b/packages/conversation/src/models/v1/update-message-request/update-message-request.ts @@ -0,0 +1,7 @@ +/** + * Update certain fields of a message. For now only metadata update is allowed. + */ +export interface UpdateMessageRequest { + /** The new metadata value */ + metadata: string; +} diff --git a/packages/conversation/src/models/v1/webhook-trigger/webhook-trigger.ts b/packages/conversation/src/models/v1/webhook-trigger/webhook-trigger.ts index 44aa0792..aebf34bb 100644 --- a/packages/conversation/src/models/v1/webhook-trigger/webhook-trigger.ts +++ b/packages/conversation/src/models/v1/webhook-trigger/webhook-trigger.ts @@ -39,4 +39,5 @@ export type WebhookTrigger = 'UNSPECIFIED_TRIGGER' | 'OPT_IN' | 'OPT_OUT' | 'CHANNEL_EVENT' - | 'CAPABILITY'; + | 'CAPABILITY' + | 'RECORD_NOTIFICATION'; diff --git a/packages/conversation/src/rest/v1/callbacks/callbacks-webhook.ts b/packages/conversation/src/rest/v1/callbacks/callbacks-webhook.ts index de2ee88d..1f396c7a 100644 --- a/packages/conversation/src/rest/v1/callbacks/callbacks-webhook.ts +++ b/packages/conversation/src/rest/v1/callbacks/callbacks-webhook.ts @@ -17,6 +17,7 @@ import { MessageSubmitEvent, OptInEvent, OptOutEvent, + RecordNotificationEvent, SmartConversationsEvent, UnsupportedCallbackEvent, WebhookTrigger, @@ -185,6 +186,11 @@ export class ConversationCallbackWebhooks implements CallbackProcessor> { @@ -16,6 +27,10 @@ export class ConversationApiFixture implements Partial * Fixture associated to function get */ public get: jest.Mock, [GetConversationRequestData]> = jest.fn(); + /** + * Fixture associated to function injectEvent + */ + public injectEvent: jest.Mock, [InjectEventRequestData]> = jest.fn(); /** * Fixture associated to function injectMessage */ @@ -24,6 +39,11 @@ export class ConversationApiFixture implements Partial * Fixture associated to function list */ public list: jest.Mock, [ListConversationsRequestData]> = jest.fn(); + /** + * Fixture associated to function list + */ + public listRecent: jest.Mock, [ListRecentConversationsRequestData]> + = jest.fn(); /** * Fixture associated to function stopActive */ diff --git a/packages/conversation/src/rest/v1/conversation/conversation-api.ts b/packages/conversation/src/rest/v1/conversation/conversation-api.ts index 75a50ad4..6988754f 100644 --- a/packages/conversation/src/rest/v1/conversation/conversation-api.ts +++ b/packages/conversation/src/rest/v1/conversation/conversation-api.ts @@ -10,9 +10,12 @@ import { import { Conversation, ConversationChannel, - ConversationMessageInjected, + InjectMessageRequest, ConversationMetadataUpdateStrategy, + ConversationRecentMessage, CreateConversationRequest, + InjectEventResponse, + InjectConversationEventRequest, } from '../../../models'; import { ConversationDomainApi } from '../conversation-domain-api'; @@ -28,11 +31,17 @@ export interface GetConversationRequestData { /** The unique ID of the conversation. This is generated by the system. */ 'conversation_id': string; } +export interface InjectEventRequestData { + /** The unique ID of the conversation. This is generated by the system. */ + 'conversation_id': string; + /** Inject event request */ + 'injectConversationEventRequestBody': InjectConversationEventRequest; +} export interface InjectMessageRequestData { /** Required. The ID of the conversation. */ 'conversation_id': string; /** Message to be injected. */ - 'injectMessageRequestBody': ConversationMessageInjected; + 'injectMessageRequestBody': InjectMessageRequest; } export interface ListConversationsRequestData { /** Required. True if only active conversations should be listed. */ @@ -48,6 +57,18 @@ export interface ListConversationsRequestData { /** Only fetch conversations from the `active_channel` */ 'active_channel'?: ConversationChannel; } +export interface ListRecentConversationsRequestData { + /** The application ID */ + 'app_id': string; + /** True if only active conversations should be listed. Default is false. */ + 'only_active'?: boolean; + /** The maximum number of conversations to fetch. Defaults to 10 and the maximum value is 50. */ + 'page_size'?: number; + /** Next page token previously returned if any. When specifying this token, make sure to use the same values for the other parameters from the request that originated the token, otherwise the paged results may be inconsistent. */ + 'page_token'?: string; + /** Whether to sort conversations by newest message first or oldest. Default is DESC (newest first) */ + 'order'?: 'ASC' | 'DESC'; +} export interface StopActiveConversationRequestData { /** The unique ID of the conversation. This is generated by the system. */ 'conversation_id': string; @@ -157,6 +178,35 @@ export class ConversationApi extends ConversationDomainApi { }); } + /** + * Inject an event + * This operation injects a conversation event into a specific conversation. + * @param { InjectEventRequestData } data - The data to provide to the API call. + */ + public async injectEvent(data: InjectEventRequestData): Promise { + this.client = this.getSinchClient(); + const getParams = this.client.extractQueryParams(data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + const body: RequestBody = data['injectConversationEventRequestBody'] + ? JSON.stringify(data['injectConversationEventRequestBody']) + : '{}'; + const basePathUrl = `${this.client.apiClientOptions.basePath}/v1/projects/${this.client.apiClientOptions.projectId}/conversations/${data['conversation_id']}:inject-event`; + + const requestOptions = await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined); + const url = this.client.prepareUrl(requestOptions.basePath, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'InjectEvent', + }); + } + /** * Inject messages * This operation injects a conversation message in to a specific conversation. @@ -234,6 +284,54 @@ export class ConversationApi extends ConversationDomainApi { return listPromise as ApiListPromise; } + /** + * List recent conversations + * This operation lists conversations and their most recent message, ordered by when the most recent message was sent for that conversation. + * @param { ListRecentConversationsRequestData } data - The data to provide to the API call. + * @return {ApiListPromise} + */ + public listRecent(data: ListRecentConversationsRequestData): ApiListPromise { + this.client = this.getSinchClient(); + const getParams = this.client.extractQueryParams(data, [ + 'app_id', + 'only_active', + 'page_size', + 'page_token', + 'order', + ]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + const body: RequestBody = ''; + const basePathUrl = `${this.client.apiClientOptions.basePath}/v1/projects/${this.client.apiClientOptions.projectId}/conversations:recent`; + + const requestOptionsPromise = this.client.prepareOptions(basePathUrl, 'GET', getParams, headers, body || undefined); + + const operationProperties: PaginatedApiProperties = { + pagination: PaginationEnum.TOKEN, + apiName: this.apiName, + operationId: 'ListRecentConversations', + dataKey: 'conversations', + }; + + // Create the promise containing the response wrapped as a PageResult + const listPromise = buildPageResultPromise( + this.client, + requestOptionsPromise, + operationProperties); + + // Add properties to the Promise to offer the possibility to use it as an iterator + Object.assign( + listPromise, + createIteratorMethodsForPagination( + this.client, requestOptionsPromise, listPromise, operationProperties), + ); + + return listPromise as ApiListPromise; + } + /** * Stop conversation * This operation stops the referenced conversation, if the conversation is still active. A new conversation will be created if a new message is exchanged between the app or contact that was part of the stopped conversation. diff --git a/packages/conversation/src/rest/v1/events/events-api.jest.fixture.ts b/packages/conversation/src/rest/v1/events/events-api.jest.fixture.ts index 6a6294f6..c28f9efa 100644 --- a/packages/conversation/src/rest/v1/events/events-api.jest.fixture.ts +++ b/packages/conversation/src/rest/v1/events/events-api.jest.fixture.ts @@ -1,8 +1,27 @@ -import { SendEventResponse } from '../../../models'; -import { EventsApi, SendEventRequestData } from './events-api'; +import { ConversationEvent, SendEventResponse } from '../../../models'; +import { + DeleteEventRequestData, + EventsApi, + GetEventRequestData, + ListEventsRequestData, + SendEventRequestData, +} from './events-api'; +import { ApiListPromise } from '@sinch/sdk-client'; export class EventsApiFixture implements Partial> { + /** + * Fixture associated to function delete + */ + public delete: jest.Mock, [DeleteEventRequestData]> = jest.fn(); + /** + * Fixture associated to function get + */ + public get: jest.Mock, [GetEventRequestData]> = jest.fn(); + /** + * Fixture associated to function list + */ + public list: jest.Mock, [ListEventsRequestData]> = jest.fn(); /** * Fixture associated to function send */ diff --git a/packages/conversation/src/rest/v1/events/events-api.ts b/packages/conversation/src/rest/v1/events/events-api.ts index fb49739e..16fefa49 100644 --- a/packages/conversation/src/rest/v1/events/events-api.ts +++ b/packages/conversation/src/rest/v1/events/events-api.ts @@ -1,13 +1,38 @@ import { + ApiListPromise, + buildPageResultPromise, + createIteratorMethodsForPagination, + PaginatedApiProperties, + PaginationEnum, RequestBody, SinchClientParameters, } from '@sinch/sdk-client'; import { + Conversation, + ConversationEvent, SendEventRequest, SendEventResponse, } from '../../../models'; import { ConversationDomainApi } from '../conversation-domain-api'; +export interface DeleteEventRequestData { + /** The unique ID of the event. */ + 'event_id': string; +} +export interface GetEventRequestData { + /** The unique ID of the event. */ + 'event_id': string; +} +export interface ListEventsRequestData { + /** Resource name (id) of the conversation. One of conversation_id or contact_id needs to be present. */ + 'conversation_id'?: string; + /** Resource name (id) of the contact. One of conversation_id or contact_id needs to be present. */ + 'contact_id'?: string; + /** Maximum number of events to fetch. Defaults to 10 and the maximum is 20. */ + 'page_size'?: number; + /** Next page token previously returned if any. When specifying this token, make sure to use the same values for the other parameters from the request that originated the token, otherwise the paged results may be inconsistent. */ + 'page_token'?: string; +} export interface SendEventRequestData { /** The event to be sent. */ 'sendEventRequestBody': SendEventRequest; @@ -24,6 +49,108 @@ export class EventsApi extends ConversationDomainApi { super(sinchClientParameters, 'EventsApi'); } + /** + * Delete an event + * Delete a specific event by its ID. + * @param { DeleteEventRequestData } data - The data to provide to the API call. + */ + public async delete(data: DeleteEventRequestData): Promise { + this.client = this.getSinchClient(); + const getParams = this.client.extractQueryParams(data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + const body: RequestBody = ''; + const basePathUrl = `${this.client.apiClientOptions.basePath}/v1/projects/${this.client.apiClientOptions.projectId}/events/${data['event_id']}`; + + const requestOptions + = await this.client.prepareOptions(basePathUrl, 'DELETE', getParams, headers, body || undefined); + const url = this.client.prepareUrl(requestOptions.basePath, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'DeleteEvents', + }); + } + + /** + * Get an event + * Get event from ID + * @param { GetEventRequestData } data - The data to provide to the API call. + */ + public async get(data: GetEventRequestData): Promise { + this.client = this.getSinchClient(); + const getParams = this.client.extractQueryParams(data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + const body: RequestBody = ''; + const basePathUrl = `${this.client.apiClientOptions.basePath}/v1/projects/${this.client.apiClientOptions.projectId}/events/${data['event_id']}`; + + const requestOptions = await this.client.prepareOptions(basePathUrl, 'GET', getParams, headers, body || undefined); + const url = this.client.prepareUrl(requestOptions.basePath, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'GetEvent', + }); + } + + /** + * List events + * List all events in a project + * @param { ListEventsRequestData } data - The data to provide to the API call. + * @return {ApiListPromise} + */ + public list(data: ListEventsRequestData): ApiListPromise { + this.client = this.getSinchClient(); + const getParams = this.client.extractQueryParams(data, [ + 'conversation_id', + 'contact_id', + 'page_size', + 'page_token', + ]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + const body: RequestBody = ''; + const basePathUrl = `${this.client.apiClientOptions.basePath}/v1/projects/${this.client.apiClientOptions.projectId}/events`; + + const requestOptionsPromise = this.client.prepareOptions(basePathUrl, 'GET', getParams, headers, body || undefined); + + const operationProperties: PaginatedApiProperties = { + pagination: PaginationEnum.TOKEN, + apiName: this.apiName, + operationId: 'ListEvents', + dataKey: 'events', + }; + + // Create the promise containing the response wrapped as a PageResult + const listPromise = buildPageResultPromise( + this.client, + requestOptionsPromise, + operationProperties); + + // Add properties to the Promise to offer the possibility to use it as an iterator + Object.assign( + listPromise, + createIteratorMethodsForPagination( + this.client, requestOptionsPromise, listPromise, operationProperties), + ); + + return listPromise as ApiListPromise; + } + /** * Send an event * Sends an event to the referenced contact from the referenced app. Note that this operation enqueues the event in a queue so a successful response only indicates that the event has been queued. diff --git a/packages/conversation/src/rest/v1/messages/messages-api.jest.fixture.ts b/packages/conversation/src/rest/v1/messages/messages-api.jest.fixture.ts index f60793e7..144ef78f 100644 --- a/packages/conversation/src/rest/v1/messages/messages-api.jest.fixture.ts +++ b/packages/conversation/src/rest/v1/messages/messages-api.jest.fixture.ts @@ -1,6 +1,12 @@ -import { ConversationMessage } from '../../../models'; -import { SendMessageResponse } from '../../../models'; -import { MessagesApi, DeleteMessageRequestData, GetMessageRequestData, ListMessagesRequestData, SendMessageRequestData } from './messages-api'; +import { ConversationMessage, SendMessageResponse } from '../../../models'; +import { + MessagesApi, + DeleteMessageRequestData, + GetMessageRequestData, + ListMessagesRequestData, + SendMessageRequestData, + UpdateMessageRequestData, +} from './messages-api'; import { ApiListPromise } from '@sinch/sdk-client'; export class MessagesApiFixture implements Partial> { @@ -21,5 +27,8 @@ export class MessagesApiFixture implements Partial> { * Fixture associated to function send */ public send: jest.Mock, [SendMessageRequestData]> = jest.fn(); + /** + * Fixture associated to function update + */ + public update: jest.Mock, [UpdateMessageRequestData]> = jest.fn(); } - diff --git a/packages/conversation/src/rest/v1/messages/messages-api.ts b/packages/conversation/src/rest/v1/messages/messages-api.ts index 3ab17e90..7ad02616 100644 --- a/packages/conversation/src/rest/v1/messages/messages-api.ts +++ b/packages/conversation/src/rest/v1/messages/messages-api.ts @@ -13,6 +13,7 @@ import { ConversationMessagesView, SendMessageRequest, SendMessageResponse, + UpdateMessageRequest, } from '../../../models'; import { ConversationDomainApi } from '../conversation-domain-api'; import { MessageSource } from '../enums'; @@ -59,6 +60,14 @@ export interface SendMessageRequestData { /** This is the request body for sending a message. `app_id`, `recipient`, and `message` are all required fields. */ 'sendMessageRequestBody': SendMessageRequest; } +export interface UpdateMessageRequestData { + /** The unique ID of the message. */ + 'message_id': string; + /** Update message metadata request. */ + 'updateMessageRequestBody': UpdateMessageRequest; + /** Specifies the message source for which the request will be processed. Used for operations on messages in Dispatch Mode. For more information, see [Processing Modes](../../../../../conversation/processing-modes/). */ + 'messages_source'?: 'CONVERSATION_SOURCE' | 'DISPATCH_SOURCE'; +} export class MessagesApi extends ConversationDomainApi { @@ -211,4 +220,35 @@ export class MessagesApi extends ConversationDomainApi { }); } + /** + * Update message metadata + * Update a specific message metadata by its ID. + * @param { UpdateMessageRequestData } data - The data to provide to the API call. + */ + public async update(data: UpdateMessageRequestData): Promise { + this.client = this.getSinchClient(); + data['messages_source'] = data['messages_source'] !== undefined ? data['messages_source'] : 'CONVERSATION_SOURCE'; + const getParams = this.client.extractQueryParams(data, ['messages_source']); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + const body: RequestBody = data['updateMessageRequestBody'] + ? JSON.stringify(data['updateMessageRequestBody']) + : '{}'; + const basePathUrl = `${this.client.apiClientOptions.basePath}/v1/projects/${this.client.apiClientOptions.projectId}/messages/${data['message_id']}`; + + const requestOptions + = await this.client.prepareOptions(basePathUrl, 'PATCH', getParams, headers, body || undefined); + const url = this.client.prepareUrl(requestOptions.basePath, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'UpdateMessageMetadata', + }); + } + } diff --git a/packages/conversation/tests/rest/v1/conversation/conversation-api.test.ts b/packages/conversation/tests/rest/v1/conversation/conversation-api.test.ts index 1ab7976b..dbb72001 100644 --- a/packages/conversation/tests/rest/v1/conversation/conversation-api.test.ts +++ b/packages/conversation/tests/rest/v1/conversation/conversation-api.test.ts @@ -10,6 +10,10 @@ import { ListConversationsRequestData, StopActiveConversationRequestData, UpdateConversationRequestData, + ListRecentConversationsRequestData, + ConversationRecentMessage, + InjectEventRequestData, + InjectEventResponse, } from '../../../../src'; describe('ConversationApi', () => { @@ -92,6 +96,48 @@ describe('ConversationApi', () => { }); }); + describe ('injectEvent', () => { + it('should make a POST request to inject a conversation event into a specific conversation', async () => { + // Given + const requestData: InjectEventRequestData = { + conversation_id: 'conversation_id', + injectConversationEventRequestBody: { + app_event: { + agent_joined_event: { + agent: { + display_name: 'agent_name', + type: 'BOT', + picture_url: 'picture_url', + }, + }, + }, + conversation_id: 'conversation_id', + contact_id: 'contact_id', + channel_identity: { + channel: 'MESSENGER', + identity: 'identity', + app_id: 'app_id', + }, + accept_time: new Date('2019-08-24T14:15:22Z'), + processing_mode: 'CONVERSATION', + }, + }; + const expectedResponse: InjectEventResponse = { + event_id: 'event_id', + accepted_time: new Date('2019-08-24T14:15:22Z'), + }; + + // When + fixture.injectEvent.mockResolvedValue(expectedResponse); + conversationApi.injectEvent = fixture.injectEvent; + const response = await conversationApi.injectEvent(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.injectEvent).toHaveBeenCalledWith(requestData); + }); + }); + describe ('injectMessage', () => { it('should make a POST request to inject a conversation message in to a specific conversation', async () => { // Given @@ -151,6 +197,90 @@ describe('ConversationApi', () => { }); }); + describe ('listRecentConversations', () => { + it('should make a GET request to list conversations and their most recent message', async () => { + // Given + const requestData: ListRecentConversationsRequestData = { + app_id: 'app_id', + order: 'ASC', + }; + const mockData: ConversationRecentMessage[] = [ + { + conversation: { + active: true, + active_channel: 'WHATSAPP', + app_id: 'app_id', + contact_id: 'contact_id', + id: 'conversation_id', + last_received: new Date('2019-08-24T14:15:22Z'), + metadata: 'metadata', + metadata_json: {}, + correlation_id: 'correlation_id', + }, + last_message: { + app_message: { + card_message: { + choices: [], + description: 'description', + height: 'UNSPECIFIED_HEIGHT', + media_message: { + url: 'url', + }, + title: 'title', + }, + explicit_channel_message: {}, + explicit_channel_omni_message: { + property1: { + card_message: {}, + }, + property2: { + text_message: { + text: 'text message', + }, + }, + }, + agent: { + display_name: 'agent_name', + type: 'UNKNOWN_AGENT_TYPE', + picture_url: 'picture_url', + }, + }, + accept_time: new Date('2019-08-24T14:15:22Z'), + channel_identity: { + identity: 'identity', + channel: 'WHATSAPP', + app_id: 'app_id', + }, + contact_id: 'contact_id', + conversation_id: 'conversation_id', + direction: 'UNDEFINED_DIRECTION', + id: 'message_id', + metadata: 'metadata', + injected: true, + sender_id: 'sender_id', + processing_mode: 'CONVERSATION', + }, + }, + ]; + const expectedResponse = { + data: mockData, + hasNextPage: false, + nextPageValue: '', + nextPage: jest.fn(), + }; + + // When + fixture.listRecent.mockResolvedValue(expectedResponse); + conversationApi.listRecent = fixture.listRecent; + const response = await conversationApi.listRecent(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(response.data).toBeDefined(); + expect(fixture.listRecent).toHaveBeenCalledWith(requestData); + }); + }); + describe ('stopActiveConversation', () => { it('should make a POST request to stop the referenced conversation', async () => { // Given diff --git a/packages/conversation/tests/rest/v1/events/events-api.test.ts b/packages/conversation/tests/rest/v1/events/events-api.test.ts index 79530ccc..5d60b631 100644 --- a/packages/conversation/tests/rest/v1/events/events-api.test.ts +++ b/packages/conversation/tests/rest/v1/events/events-api.test.ts @@ -1,6 +1,15 @@ import { SinchClientParameters } from '@sinch/sdk-client'; -import { GenericEvent, SendEventRequestData, SendEventResponse } from '../../../../src'; -import { EventsApi, EventsApiFixture } from '../../../../src'; +import { + ConversationEvent, + DeleteEventRequestData, + EventsApi, + EventsApiFixture, + GenericEvent, + GetEventRequestData, + ListEventsRequestData, + SendEventRequestData, + SendEventResponse, +} from '../../../../src'; describe('EventsApi', () => { let eventsApi: EventsApi; @@ -17,6 +26,139 @@ describe('EventsApi', () => { eventsApi = new EventsApi(credentials); }); + describe ('deleteEvents', () => { + it('should make a DELETE request to delete a specific event by its ID', async () => { + // Given + const requestData: DeleteEventRequestData = { + event_id: 'event_id', + }; + const expectedResponse: any = {}; + + // When + fixture.delete.mockResolvedValue(expectedResponse); + eventsApi.delete = fixture.delete; + const response = await eventsApi.delete(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.delete).toHaveBeenCalledWith(requestData); + }); + }); + + describe ('getEvent', () => { + it('should make a GET request to retrieve an event from its ID', async () => { + // Given + const requestData: GetEventRequestData = { + event_id: 'event_id', + }; + const expectedResponse: ConversationEvent = { + id: 'event_id', + channel_identity: { + identity: 'identity', + app_id: 'app_id', + channel: 'WHATSAPP', + }, + processing_mode: 'CONVERSATION', + direction: 'TO_APP', + app_event: { + composing_event: {}, + }, + contact_id: 'contact_id', + conversation_id: 'conversation_id', + accept_time: new Date('2019-08-24T14:15:22Z'), + }; + + // When + fixture.get.mockResolvedValue(expectedResponse); + eventsApi.get = fixture.get; + const response = await eventsApi.get(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.get).toHaveBeenCalledWith(requestData); + }); + }); + + describe ('listEvents', () => { + it('should make a GET request to list all events in a project', async () => { + // Given + const requestData: ListEventsRequestData = { + contact_id: 'contact_id', + conversation_id: 'conversation_id', + }; + const mockData: ConversationEvent[] = [ + { + id: 'app_event_id', + channel_identity: { + identity: 'identity', + app_id: 'app_id', + channel: 'WHATSAPP', + }, + processing_mode: 'CONVERSATION', + direction: 'TO_CONTACT', + app_event: { + composing_event: {}, + }, + contact_id: 'contact_id', + conversation_id: 'conversation_id', + accept_time: new Date('2019-08-24T14:15:22Z'), + }, + { + id: 'contact_event_id', + channel_identity: { + identity: 'identity', + app_id: 'app_id', + channel: 'WHATSAPP', + }, + processing_mode: 'CONVERSATION', + direction: 'TO_APP', + contact_event: { + conversation_deleted_event: {}, + }, + contact_id: 'contact_id', + conversation_id: 'conversation_id', + accept_time: new Date('2019-08-24T14:15:22Z'), + }, + { + id: 'contact_message_event_id', + channel_identity: { + identity: 'identity', + app_id: 'app_id', + channel: 'WHATSAPP', + }, + processing_mode: 'CONVERSATION', + direction: 'TO_APP', + contact_message_event: { + payment_status_update_event: { + payment_status: 'PAYMENT_STATUS_CAPTURED', + payment_transaction_status: 'PAYMENT_STATUS_TRANSACTION_SUCCESS', + payment_transaction_id: 'transaction_id', + reference_id: 'reference_id', + }, + }, + contact_id: 'contact_id', + conversation_id: 'conversation_id', + accept_time: new Date('2019-08-24T14:15:22Z'), + }, + ]; + const expectedResponse = { + data: mockData, + hasNextPage: false, + nextPageValue: '', + nextPage: jest.fn(), + }; + + // When + fixture.list.mockResolvedValue(expectedResponse); + eventsApi.list = fixture.list; + const response = await eventsApi.list(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(response.data).toBeDefined(); + expect(fixture.list).toHaveBeenCalledWith(requestData); + }); + }); describe ('sendEvent', () => { it('should make a POST request to send an event to the referenced contact from the referenced app', async () => { diff --git a/packages/conversation/tests/rest/v1/messages/messages-api.test.ts b/packages/conversation/tests/rest/v1/messages/messages-api.test.ts index 8d1ae6d7..36d787f1 100644 --- a/packages/conversation/tests/rest/v1/messages/messages-api.test.ts +++ b/packages/conversation/tests/rest/v1/messages/messages-api.test.ts @@ -3,10 +3,13 @@ import { ConversationMessage, DeleteMessageRequestData, GetMessageRequestData, - ListMessagesRequestData, SendMessageRequestData, + ListMessagesRequestData, + MessagesApi, + MessagesApiFixture, + SendMessageRequestData, + SendMessageResponse, + UpdateMessageRequestData, } from '../../../../src'; -import { SendMessageResponse } from '../../../../src'; -import { MessagesApi, MessagesApiFixture } from '../../../../src'; describe('MessagesApi', () => { let messagesApi: MessagesApi; @@ -62,9 +65,6 @@ describe('MessagesApi', () => { title: 'title', }, explicit_channel_message: {}, - additionalProperties: { - contact_name: 'contactName', - }, }, channel_identity: { app_id: 'app_id', @@ -168,9 +168,6 @@ describe('MessagesApi', () => { title: 'title', }, explicit_channel_message: {}, - additionalProperties: { - contact_name: 'contact_name', - }, }, channel_identity: { identity: 'identity', @@ -238,4 +235,69 @@ describe('MessagesApi', () => { expect(fixture.send).toHaveBeenCalledWith(requestData); }); }); + + describe ('updateMessageMetadata', () => { + it('should make a PATCH request to update a message', async () => { + // Given + const requestData: UpdateMessageRequestData = { + message_id: 'message_id', + messages_source: 'CONVERSATION_SOURCE', + updateMessageRequestBody: { + metadata: 'new_metadata', + }, + }; + const expectedResponse: ConversationMessage = { + app_message: { + card_message: { + choices: [], + description: 'description', + height: 'UNSPECIFIED_HEIGHT', + media_message: { + url: 'url', + }, + title: 'title', + }, + explicit_channel_message: {}, + explicit_channel_omni_message: { + property1: { + card_message: {}, + }, + property2: { + text_message: { + text: 'text message', + }, + }, + }, + agent: { + display_name: 'agent_name', + type: 'UNKNOWN_AGENT_TYPE', + picture_url: 'picture_url', + }, + }, + accept_time: new Date('2019-08-24T14:15:22Z'), + channel_identity: { + identity: 'identity', + channel: 'WHATSAPP', + app_id: 'app_id', + }, + contact_id: 'contact_id', + conversation_id: 'conversation_id', + direction: 'UNDEFINED_DIRECTION', + id: 'message_id', + metadata: 'new_metadata', + injected: true, + sender_id: 'sender_id', + processing_mode: 'CONVERSATION', + }; + + // When + fixture.update.mockResolvedValue(expectedResponse); + messagesApi.update = fixture.update; + const response = await messagesApi.update(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.update).toHaveBeenCalledWith(requestData); + }); + }); });