({
accountId,
channelId,
domain,
fullSync,
logger,
}: {
accountId: string;
channelId?: string;
domain?: string;
fullSync?: boolean | undefined;
logger: Logger;
})
| 13 | import { Logger } from '@linen/types'; |
| 14 | |
| 15 | export async function slackSync({ |
| 16 | accountId, |
| 17 | channelId, |
| 18 | domain, |
| 19 | fullSync, |
| 20 | logger, |
| 21 | }: { |
| 22 | accountId: string; |
| 23 | channelId?: string; |
| 24 | domain?: string; |
| 25 | fullSync?: boolean | undefined; |
| 26 | logger: Logger; |
| 27 | }) { |
| 28 | logger.log({ startAt: new Date(), fullSync }); |
| 29 | |
| 30 | const account = await findAccountById(accountId); |
| 31 | |
| 32 | if (!account) { |
| 33 | throw new Error('Account not found'); |
| 34 | } |
| 35 | if (!account.slackTeamId) { |
| 36 | throw new Error('slackTeamId not found'); |
| 37 | } |
| 38 | |
| 39 | logger.setPrefix(account.slackDomain || account.name || account.id); |
| 40 | |
| 41 | await updateAndNotifySyncStatus({ |
| 42 | accountId, |
| 43 | status: SyncStatus.IN_PROGRESS, |
| 44 | accountName: account.name, |
| 45 | homeUrl: account.homeUrl, |
| 46 | communityUrl: account.communityUrl, |
| 47 | pathDomain: account.slackDomain, |
| 48 | }); |
| 49 | |
| 50 | try { |
| 51 | await syncWrapper({ |
| 52 | account, |
| 53 | domain, |
| 54 | accountId, |
| 55 | channelId, |
| 56 | fullSync, |
| 57 | fetchConversationsTyped, |
| 58 | fetchReplies, |
| 59 | fetchTeamInfo, |
| 60 | getSlackChannels, |
| 61 | joinChannel, |
| 62 | listUsers, |
| 63 | getMemberships, |
| 64 | logger, |
| 65 | }); |
| 66 | |
| 67 | await updateAndNotifySyncStatus({ |
| 68 | accountId, |
| 69 | status: SyncStatus.DONE, |
| 70 | accountName: account.name, |
| 71 | homeUrl: account.homeUrl, |
| 72 | communityUrl: account.communityUrl, |
no test coverage detected