/ src / types.ts
types.ts
  1  /**
  2   * Common Ground Bot SDK Types
  3   */
  4  
  5  // ============================================================================
  6  // Message Content Types (matches CG message body format)
  7  // ============================================================================
  8  
  9  export interface TextContent {
 10    type: 'text';
 11    value: string;
 12    bold?: boolean;
 13    italic?: boolean;
 14    underline?: boolean;
 15    strikethrough?: boolean;
 16    code?: boolean;
 17  }
 18  
 19  export interface LinkContent {
 20    type: 'link';
 21    value: string;
 22    url: string;
 23  }
 24  
 25  export interface MentionContent {
 26    type: 'mention';
 27    userId: string;
 28    alias?: string;
 29  }
 30  
 31  export interface BotMentionContent {
 32    type: 'botMention';
 33    botId: string;
 34    alias?: string;
 35  }
 36  
 37  export interface NewlineContent {
 38    type: 'newline';
 39  }
 40  
 41  export type MessageContentItem = 
 42    | TextContent 
 43    | LinkContent 
 44    | MentionContent 
 45    | BotMentionContent
 46    | NewlineContent;
 47  
 48  export interface MessageBody {
 49    version: '1';
 50    content: MessageContentItem[];
 51  }
 52  
 53  // ============================================================================
 54  // Attachment Types
 55  // ============================================================================
 56  
 57  export interface ImageAttachment {
 58    type: 'image';
 59    fileId: string;
 60    width?: number;
 61    height?: number;
 62  }
 63  
 64  export interface LinkPreviewAttachment {
 65    type: 'linkPreview';
 66    url: string;
 67    title?: string;
 68    description?: string;
 69    imageUrl?: string;
 70  }
 71  
 72  export type Attachment = ImageAttachment | LinkPreviewAttachment;
 73  
 74  // ============================================================================
 75  // API Types
 76  // ============================================================================
 77  
 78  export interface SendMessageOptions {
 79    communityId: string;
 80    channelId: string;
 81    /** Simple text message (converted to body internally) */
 82    text?: string;
 83    /** Rich message content */
 84    body?: MessageBody;
 85    /** File attachments */
 86    attachments?: Attachment[];
 87    /** Reply to a specific message */
 88    replyTo?: string;
 89  }
 90  
 91  export interface Message {
 92    id: string;
 93    channelId: string;
 94    body: MessageBody;
 95    attachments: Attachment[];
 96    createdAt: string;
 97    updatedAt: string;
 98    botId: string;
 99    parentMessageId: string | null;
100  }
101  
102  export interface SendMessageResult {
103    message: Message;
104  }
105  
106  // ============================================================================
107  // Webhook Types
108  // ============================================================================
109  
110  export type WebhookEventType = 'BOT_MENTIONED';
111  
112  export interface WebhookCommunity {
113    id: string;
114    name: string;
115    url: string;
116  }
117  
118  export interface WebhookChannel {
119    id: string;
120    name: string;
121    type: 'text' | 'voice';
122    url: string;
123  }
124  
125  export interface WebhookMessage {
126    id: string;
127    body: MessageBody;
128    attachments: Attachment[];
129    createdAt: string;
130    replyToMessageId: string | null;
131    mentionIndex: number;
132  }
133  
134  export interface WebhookSender {
135    id: string;
136    displayName: string;
137    username: string;
138    avatarUrl: string | null;
139  }
140  
141  export interface WebhookMentionedBot {
142    id: string;
143    name: string;
144  }
145  
146  export interface WebhookEvent {
147    event: WebhookEventType;
148    eventId: string;
149    timestamp: string;
150    apiVersion: '1';
151    community: WebhookCommunity;
152    channel: WebhookChannel;
153    message: WebhookMessage;
154    sender: WebhookSender;
155    mentionedBot: WebhookMentionedBot;
156  }
157  
158  // ============================================================================
159  // Client Configuration
160  // ============================================================================
161  
162  export interface BotClientConfig {
163    /** Bot authentication token (defaults to BOT_TOKEN env var) */
164    token?: string;
165    /** API base URL (defaults to CG_BASE_URL env var or production) */
166    baseUrl?: string;
167    /** Request timeout in milliseconds (default: 30000) */
168    timeout?: number;
169  }
170  
171  // ============================================================================
172  // Error Types
173  // ============================================================================
174  
175  export interface ApiErrorResponse {
176    error: string;
177    message?: string;
178  }
179