export async function sendDigest()

in packages/cloudbuster/src/digests.ts [132:174]


export async function sendDigest(
	anghammaradClient: Anghammarad,
	config: Config,
	digest: Digest,
): Promise<void> {
	const notifyParams: NotifyParams = {
		subject: digest.subject,
		message: digest.message,
		actions: digest.actions,
		target: { AwsAccount: digest.accountId },
		threadKey: digest.accountId,
		channel: RequestedChannel.PreferHangouts,
		sourceSystem: `cloudbuster ${config.stage}`,
		topicArn: config.anghammaradSnsTopic,
	};

	const { enableMessaging, stage } = config;

	if (enableMessaging) {
		const notificationParameters =
			stage === 'PROD'
				? notifyParams
				: {
						...notifyParams,
						target: { Stack: 'testing-alerts' },
					};
		logger.log({
			message: `Sending ${digest.accountId} (${digest.accountName}) digest...`,
			accountName: digest.accountName,
			target: notificationParameters.target,
			enableMessaging,
		});

		await anghammaradClient.notify(notificationParameters);
	} else {
		logger.log({
			message: `Messaging disabled. Anghammarad would have sent: ${JSON.stringify(notifyParams, null, 4)}`,
			accountName: digest.accountName,
			target: notifyParams.target,
			enableMessaging,
		});
	}
}