import { isMessage , isTypedArray , IMessage } from "@shlack/types" ; import { apiCall } from "@shlack/utils" ; const cachedMessageRecordArrays = { } ; export async function getChannelMessages ( teamId , channelId ) { let cached = cachedMessageRecordArrays [ channelId ] ; if ( typeof cached === "undefined" ) cached = cachedMessageRecordArrays [ channelId ] = apiCall ( `teams/${ teamId }/channels/${ channelId }/messages` ) . then ( ( rawData ) => { debugger ; if ( isTypedArray ( rawData , isMessage ) ) { return rawData ; } else throw new Error ( `Unexpected value for message array\n${ JSON . stringify ( rawData ) }` ) ; } ) ; return await cached ; }