Skip to content

Commit

Permalink
expose smart message in messages api
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbl committed Apr 3, 2024
1 parent 3674d18 commit 05bb86d
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
withReThrowingDataServiceError,
} from './data-service-api';
import axios from 'axios';
import type { SmartMessageDto } from './smart-message.dto';
export interface DataServiceDialectsApi {
create(command: CreateDialectCommand): Promise<DialectAccountDto>;

Expand Down Expand Up @@ -263,6 +264,7 @@ export class MessageMetadataDto {
title?: string;
tags?: string[];
actions?: MessageActionDto[];
smartMessage?: SmartMessageDto;
notificationTypeId?: string;
}

Expand Down
89 changes: 89 additions & 0 deletions packages/sdk/src/dialect-cloud-api/smart-message-spec.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
export enum SmartMessageStateDto {
Created = 'CREATED',
ReadyForExecution = 'READY_FOR_EXECUTION',
Executing = 'EXECUTING',
Succeeded = 'SUCCEEDED',
Failed = 'FAILED',
Canceled = 'CANCELED',
}

export enum ActionType {
SignTransaction = 'SIGN_TRANSACTION',
OpenLink = 'OPEN_LINK',
Cancel = 'CANCEL', // cancel without a transaction, in other words a noop
}

export class SmartMessageButtonLayoutElementDto {
type!: 'button';
text!: string;
action!: SmartMessageSpecActionDto;
}

export class SmartMessageLabelLayoutElementDto {
type!: 'label';
text!: string;
}

export class SmartMessageSpecOpenLinkActionDto {
type!: ActionType.OpenLink;
link!: string;
}

export class SmartMessageSpecSignTransactionActionDto {
humanReadableId!: string;
type!: ActionType.SignTransaction;
}

export class SmartMessageSpecCancelActionDto {
humanReadableId!: string;
type!: ActionType.Cancel;
}

export type SmartMessageSpecActionDto =
| SmartMessageSpecOpenLinkActionDto
| SmartMessageSpecSignTransactionActionDto
| SmartMessageSpecCancelActionDto;

export type SmartMessageLayoutElementDto =
| SmartMessageButtonLayoutElementDto
| SmartMessageLabelLayoutElementDto;

export class SmartMessageLayoutDto {
icon!: string | null;
description!: string | null;
header!: string | null;
subheader!: string | null;
elements!: SmartMessageLayoutElementDto[][];
}

export class SmartMessageContentDto {
state!: SmartMessageStateDto;
layout!: SmartMessageLayoutDto;
}

export class SmartMessagePreviewParamsDto {
state!: SmartMessageStateDto;
}

export class SmartMessageSystemParamsDto {
state!: SmartMessageStateDto;
workflowStateHumanReadableId!: string;
createdByWalletAddress!: string;
principalWalletAddress!: string;
updatedByWalletAddress!: string;
}

export class CreateSmartMessageTransactionCommandDto {
account!: string;
actionHumanReadableId!: string;
}

export class SmartMessageTransactionDto {
transaction!: string;
message?: string;
}

export class SubmitSmartMessageTransactionCommandDto {
readonly transaction!: string;
readonly actionHumanReadableId!: string;
}
6 changes: 6 additions & 0 deletions packages/sdk/src/dialect-cloud-api/smart-message.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { SmartMessageContentDto } from './smart-message-spec.dto';

export class SmartMessageDto {
id!: string;
content!: SmartMessageContentDto;
}
2 changes: 2 additions & 0 deletions packages/sdk/src/messaging/messaging.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AccountAddress } from '../auth/auth.interface';
import type { SmartMessageDto } from '../dialect-cloud-api/smart-message.dto';

export interface Messaging {
type: string;
Expand Down Expand Up @@ -45,6 +46,7 @@ export interface MessageMetadata {
title?: string;
// tags?: string[];
actions?: MessageAction[];
smartMessage?: SmartMessageDto;
notificationTypeId?: string;
notificationTypeHumanReadableId?: string;
}
Expand Down

0 comments on commit 05bb86d

Please sign in to comment.