import { Chat } from './chat' ; import { ChatType } from './chat-type' ; import { AttachmentContent , ChatContent , TextContent } from './content' ; /**
 * Build Chat object from existing chat or create new.
 */ export class ChatBuilder { private _contents : ChatContent [ ] ; constructor ( ) { this . _contents = [ ] ; } param { string } text return { this } text ( text ) { return this . append ( new TextContent ( text ) ) ; } param { Record < string , unknown > } attachment return { this } attachment ( attachment ) { return this . append ( new AttachmentContent ( attachment ) ) ; } param { ChatContent } content return { this } append ( content ) { this . _contents . push ( content ) ; return this ; } param { boolean } flag return { this } shout ( flag ) { return this . attachment ( { shout : flag } ) ; } param { Chat | ChatType } data return { Chat } build ( data ) { let chat ; if ( typeof data === 'object' ) { chat = data as Chat ; } else if ( typeof data === 'number' ) { chat = { type : data , text : '' , attachment : { } , } ; } else { throw new Error ( 'Unknown ChatType or Chat object supplied' ) ; } if ( ! chat . attachment ) chat . attachment = { } ; for ( const content of this . _contents ) { content . append ( chat ) ; } return chat ; } }