({
channel,
threadId,
messageId,
isThread,
isReply,
logger,
}: {
channel:
| channels & {
channelsIntegration: channelsIntegration[];
account:
| (accounts & {
slackAuthorizations: slackAuthorizations[];
discordAuthorizations: discordAuthorizations[];
})
| null;
};
threadId?: string;
messageId: string;
isThread?: boolean;
isReply?: boolean;
logger: Logger;
})
| 84 | } |
| 85 | |
| 86 | export async function slackChatSync({ |
| 87 | channel, |
| 88 | threadId, |
| 89 | messageId, |
| 90 | isThread, |
| 91 | isReply, |
| 92 | logger, |
| 93 | }: { |
| 94 | channel: |
| 95 | | channels & { |
| 96 | channelsIntegration: channelsIntegration[]; |
| 97 | account: |
| 98 | | (accounts & { |
| 99 | slackAuthorizations: slackAuthorizations[]; |
| 100 | discordAuthorizations: discordAuthorizations[]; |
| 101 | }) |
| 102 | | null; |
| 103 | }; |
| 104 | threadId?: string; |
| 105 | messageId: string; |
| 106 | isThread?: boolean; |
| 107 | isReply?: boolean; |
| 108 | logger: Logger; |
| 109 | }) { |
| 110 | logger.log({ threadId, messageId }); |
| 111 | // check if has enough permissions |
| 112 | const slackToken = channel.account?.slackAuthorizations.find((s) => |
| 113 | isAllowToSendMessages(s) |
| 114 | ); |
| 115 | if (!slackToken?.accessToken) { |
| 116 | return 'missing scope on slack token'; |
| 117 | } |
| 118 | |
| 119 | const message = await prisma.messages.findUnique({ |
| 120 | where: { id: messageId }, |
| 121 | include: { |
| 122 | author: true, |
| 123 | threads: true, |
| 124 | attachments: true, |
| 125 | mentions: { |
| 126 | include: { |
| 127 | users: true, |
| 128 | }, |
| 129 | }, |
| 130 | }, |
| 131 | }); |
| 132 | if (!message) { |
| 133 | return 'message not found'; |
| 134 | } |
| 135 | if (!message.threads) { |
| 136 | return 'thread is missing from message'; |
| 137 | } |
| 138 | if (!!message.externalMessageId) { |
| 139 | return 'message has externalId already'; |
| 140 | } |
| 141 | |
| 142 | const token = slackToken.accessToken; |
| 143 | const externalChannelId = channel.externalChannelId!; |
no test coverage detected