Skip to content

Commit

Permalink
Align Conversation SDK with documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch committed Mar 29, 2024
1 parent 32bf1a7 commit bdcbccd
Show file tree
Hide file tree
Showing 36 changed files with 280 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CarouselMessage, CarouselMessageItem } from '../carousel-message';
import { ListMessage, ListMessageItem } from '../list-message';
import { ContactInfoMessage, ContactInfoMessageItem } from '../contact-info-message';
import { ConversationChannel } from '../conversation-channel';
import { ChannelSpecificMessage } from '../channel-specific-message';

/**
* Message originating from an app
Expand Down Expand Up @@ -153,7 +154,7 @@ interface AppContactInfoMessage extends AppMessageBase {

interface AppMessageBase {
/**
* Optional. Channel specific messages, overriding any transcoding.
* 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 in ConversationChannel ]?: string; };
Expand All @@ -162,6 +163,11 @@ interface AppMessageBase {
* (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 in ChannelSpecificTemplate]?: OmniMessage; };
/**
* Channel specific messages, overriding any transcoding. The structure of this property is more well-defined than the open structure of the `explicit_channel_message` property, and may be easier to use.
* The key in the map must point to a valid conversation channel as defined in the enum `ConversationChannel`.
*/
channel_specific_message?: { [key in ConversationChannel]?: ChannelSpecificMessage; };
/** Identity of a sender */
agent?: Agent | null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { WhatsAppInteractiveNfmReply } from '../whatsapp-interactive-nfm-reply';

/**
* A contact message containing a channel specific message (not supported by OMNI types).
*/
export interface ChannelSpecificContactMessage {
/** The message type. */
message_type: 'nfm_reply';
/** @see WhatsAppInteractiveNfmReplyMessage */
message: WhatsAppInteractiveNfmReplyMessage;
}

/**
* A WhatsApp interactive contact message containing the nfm_reply.
*/
interface WhatsAppInteractiveNfmReplyMessage {
/** The interactive message type. */
type: string;
/** @see WhatsAppInteractiveNfmReply */
nfm_reply: WhatsAppInteractiveNfmReply;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { ChannelSpecificContactMessage } from './channel-specific-contact-message';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { FlowChannelSpecificMessage } from '../flow-channel-specific-message';

/**
* A message containing a channel specific message (not supported by OMNI types).
*/
export interface ChannelSpecificMessage {
/** @see MessageTypeEnum */
message_type: 'FLOWS';
/** @see FlowChannelSpecificMessage */
message: FlowChannelSpecificMessage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { ChannelSpecificMessage } from './channel-specific-message';
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { MediaCardMessage } from '../media-card-message';
import { MediaMessageItem } from '../media-message';
import { ReplyTo } from '../reply-to';
import { TextMessageItem } from '../text-message';
import { ProductResponseMessage } from '../product-response-message';
import { ChannelSpecificContactMessage } from '../channel-specific-contact-message';

/**
* Message originating from a contact
Expand All @@ -15,71 +17,112 @@ export type ContactMessage =
| ContactMessageLocationMessage
| ContactMessageMediaCardMessage
| ContactMessageMediaMessage
| ContactMessageTextMessage;
| ContactMessageTextMessage
| ContactMessageProductResponseMessage
| ContactMessageChannelSpecificContactMessage;

interface ContactMessageChannelSpecificContactMessage extends ContactMessageBase {
/** @see ChannelSpecificContactMessage */
channel_specific_message: ChannelSpecificContactMessage;
// Exclude other message types
choice_response_message?: never;
fallback_message?: never;
location_message?: never;
media_card_message?: never;
media_message?: never;
product_response_message?: never;
text_message?: never

}

interface ContactMessageChoiceResponseMessage extends ContactMessageBase {
/** @see ChoiceResponseMessage */
choice_response_message: ChoiceResponseMessage;
// Exclude other message types
channel_specific_message?: never;
fallback_message?: never;
location_message?: never;
media_card_message?: never;
media_message?: never;
product_response_message?: never;
text_message?: never
}

interface ContactMessageFallbackMessage extends ContactMessageBase {
/** @see FallbackMessage */
fallback_message: FallbackMessage;
// Exclude other message types
channel_specific_message?: never;
choice_response_message?: never;
location_message?: never;
media_card_message?: never;
media_message?: never;
product_response_message?: never;
text_message?: never;
}

interface ContactMessageLocationMessage extends ContactMessageBase {
/** @see LocationMessageItem */
location_message: LocationMessageItem;
// Exclude other message types
channel_specific_message?: never;
choice_response_message?: never;
fallback_message?: never;
media_card_message?: never;
media_message?: never;
product_response_message?: never;
text_message?: never;
}

interface ContactMessageMediaCardMessage extends ContactMessageBase {
/** @see MediaCardMessage */
media_card_message: MediaCardMessage;
// Exclude other message types
channel_specific_message?: never;
choice_response_message?: never;
fallback_message?: never;
location_message?: never;
media_message?: never;
product_response_message?: never;
text_message?: never;
}

interface ContactMessageMediaMessage extends ContactMessageBase {
/** @see MediaMessageItem */
media_message: MediaMessageItem;
// Exclude other message types
channel_specific_message?: never;
choice_response_message?: never;
fallback_message?: never;
location_message?: never;
media_card_message?: never;
product_response_message?: never;
text_message?: never;
}

interface ContactMessageProductResponseMessage extends ContactMessageBase {
/** @see ProductResponseMessage */
product_response_message: ProductResponseMessage
// Exclude other message types
channel_specific_message?: never;
choice_response_message?: never;
fallback_message?: never;
location_message?: never;
media_card_message?: never;
media_message?: never;
text_message?: never
}

interface ContactMessageTextMessage extends ContactMessageBase {
/** @see TextMessageItem */
text_message: TextMessageItem;
// Exclude other message types
channel_specific_message?: never;
choice_response_message?: never;
fallback_message?: never;
location_message?: never;
media_card_message?: never;
product_response_message?: never;
media_message?: never;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
*/
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.** */
/**
* 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]. */
/**
* 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;
}
9 changes: 4 additions & 5 deletions packages/conversation/src/models/v1/enums.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export type {
SentimentResult as MachineLearningSentimentEnum,
EvaluationEnum as OffensiveAnalysisEvaluationEnum,
} from './mod-callback-events/smart-conversations-event/smart-conversations-event';

/**
* NONE - Omit metadata.
* FULL - Include all metadata assigned to the conversation.
*/
export type ConversationMetadataReportView = 'NONE' | 'FULL';

export type ConversationMetadataUpdateStrategy = 'REPLACE' | 'MERGE_PATCH';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { WhatsAppInteractiveBody } from '../whatsapp-interactive-body';
import { WhatsAppInteractiveFooter } from '../whatsapp-interactive-footer';
import { WhatsAppInteractiveTextHeader } from '../whatsapp-interactive-text-header';
import { WhatsAppInteractiveImageHeader } from '../whatsapp-interactive-image-header';
import { WhatsAppInteractiveDocumentHeader } from '../whatsapp-interactive-document-header';
import { WhatsAppInteractiveVideoHeader } from '../whatsapp-interactive-video-header';

/**
* A message type for sending WhatsApp Flows.
*/
export interface FlowChannelSpecificMessage {

/** @see FlowChannelSpecificMessageHeader */
header?: FlowChannelSpecificMessageHeader;
/** @see WhatsAppInteractiveBody */
body?: WhatsAppInteractiveBody;
/** @see WhatsAppInteractiveFooter */
footer?: WhatsAppInteractiveFooter;
/** ID of the Flow. */
flow_id: string;
/** Generated token which is an identifier. */
flow_token?: string;
/** The mode in which the flow is. */
flow_mode?: 'draft' | 'published';
/** Text which is displayed on the Call To Action button (20 characters maximum, emoji not supported). */
flow_cta: string;
/** */
flow_action?: 'navigate' | 'data_exchange';
/** @see FlowChannelSpecificMessageFlowActionPayload */
flow_action_payload?: FlowChannelSpecificMessageFlowActionPayload;
}

type FlowChannelSpecificMessageHeader =
WhatsAppInteractiveTextHeader
| WhatsAppInteractiveImageHeader
| WhatsAppInteractiveDocumentHeader
| WhatsAppInteractiveVideoHeader;

interface FlowChannelSpecificMessageFlowActionPayload {
/** The ID of the screen displayed first. This must be an entry screen. */
screen?: string;
/** Data for the first screen. */
data?: object;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { FlowChannelSpecificMessage } from './flow-channel-specific-message';
13 changes: 13 additions & 0 deletions packages/conversation/src/models/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export * from './channel-identity';
export * from './channel-template-override';
export * from './channel-template-reference';
export * from './channel-recipient-identity';
export * from './channel-specific-contact-message';
export * from './channel-specific-message';
export * from './choice';
export * from './choice-message';
export * from './choice-response-message';
Expand Down Expand Up @@ -43,6 +45,7 @@ export * from './create-conversation-request';
export * from './delivery-report-based-fallback';
export * from './dispatch-retention-policy';
export * from './fallback-message';
export * from './flow-channel-specific-message';
export * from './generic-event';
export * from './get-channel-profile-request';
export * from './get-channel-profile-response';
Expand All @@ -61,6 +64,8 @@ export * from './media-message';
export * from './merge-contact-request';
export * from './message-retry-settings';
export * from './product';
export * from './product-item';
export * from './product-response-message';
export * from './error-detail';
export * from './lookup-capability-request';
export * from './lookup-capability-response';
Expand Down Expand Up @@ -94,6 +99,14 @@ export * from './v2-template-response';
export * from './v2-template-translation';
export * from './webhook';
export * from './webhook-trigger';
export * from './whatsapp-interactive-body';
export * from './whatsapp-interactive-document-header';
export * from './whatsapp-interactive-footer';
export * from './whatsapp-interactive-header-media';
export * from './whatsapp-interactive-image-header';
export * from './whatsapp-interactive-nfm-reply';
export * from './whatsapp-interactive-text-header';
export * from './whatsapp-interactive-video-header';
export * from './enums';
export * from './helper';
export * from './mod-callback-events';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChoiceItem } from '../choice-item';
import { Product } from '../product';

/**
* Section for interactive whatsapp messages containing ListItem
* Section for interactive WhatsApp messages containing ListItem
*/
export interface ListSection {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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.
* 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;
Expand Down
1 change: 1 addition & 0 deletions packages/conversation/src/models/v1/product-item/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { ProductItem } from './product-item';
15 changes: 15 additions & 0 deletions packages/conversation/src/models/v1/product-item/product-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* A message component for interactive messages, containing a product.
*/
export interface ProductItem {
/** Required parameter. The ID for the product. */
id: string;
/** Required parameter. The marketplace to which the product belongs. */
marketplace: string;
/** Output only. The quantity of the chosen product. */
quantity?: number;
/** Output only. The price for one unit of the chosen product. */
item_price?: number;
/** Output only. The currency of the item_price. */
currency?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { ProductResponseMessage } from './product-response-message';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ProductItem } from '../product-item';

/**
* Represents an interactive WhatsApp message containing ProductItem objects
*/
export interface ProductResponseMessage {
/** The selected products. */
products: ProductItem[];
/** Optional parameter. Text that may be sent with selected products. */
text?: string;
/** Optional parameter. The catalog id that the selected products belong to. */
catalog_id?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { WhatsAppInteractiveBody } from './whatsapp-interactive-body';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Body of the interactive message.
*/
export interface WhatsAppInteractiveBody {
/** The content of the message (1024 characters maximum). Emojis and Markdown are supported. */
text: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { WhatsAppInteractiveDocumentHeader } from './whatsapp-interactive-document-header';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { WhatsAppInteractiveHeaderMedia } from '../whatsapp-interactive-header-media';

/**
* Header of the interactive message with document.
*/
export interface WhatsAppInteractiveDocumentHeader {
/** Must be set to document. */
type: 'document';
/** @see WhatsAppInteractiveHeaderMedia */
document: WhatsAppInteractiveHeaderMedia;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { WhatsAppInteractiveFooter } from './whatsapp-interactive-footer';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Footer of the interactive message.
*/
export interface WhatsAppInteractiveFooter {
/** The footer content (60 characters maximum). Emojis, Markdown and links are supported. */
text: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { WhatsAppInteractiveHeaderMedia } from './whatsapp-interactive-header-media';
Loading

0 comments on commit bdcbccd

Please sign in to comment.