73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import { proxyActivities, continueAsNew, log, sleep } from "@temporalio/workflow"
|
|
import type * as activities from "./activities.js"
|
|
import { FetchMessageObject } from 'imapflow'
|
|
|
|
// { isMatch, url, platform, channel, displayName, date, userId, avatar }
|
|
export type NotificationData = {
|
|
isMatch?: boolean;
|
|
url: string;
|
|
platform: string;
|
|
channel: string;
|
|
displayName: string;
|
|
date: string;
|
|
userId: string | null;
|
|
avatar: string;
|
|
};
|
|
|
|
const {
|
|
chargeUser,
|
|
checkAndDecrementInventory,
|
|
incrementInventory,
|
|
upsertPlatformNotification,
|
|
upsertStream,
|
|
upsertVtuber,
|
|
} = proxyActivities<typeof activities>({
|
|
startToCloseTimeout: "1 minute",
|
|
});
|
|
|
|
|
|
|
|
|
|
export async function processEmail({
|
|
url, platform, channel, displayName, date, userId, avatar
|
|
}: NotificationData): Promise<{ vtuberId: number, pNotifId: number, streamId: number }> {
|
|
console.log(`processEmail begin. platform=${platform}, date=${date}, url=${url}`)
|
|
// * In Strapi, we are finding or updating or creating the following content-types.
|
|
// * * vtuber
|
|
// * * platform-notification
|
|
// * * stream
|
|
// Step 1
|
|
|
|
const vtuberId = await upsertVtuber({ url, platform, channel, displayName, date, userId, avatar })
|
|
console.log('we have finished upsertVtuber and the vtuberId is '+vtuberId)
|
|
throw new Error('Error: Error: error: erorreorororr; @todo');
|
|
const pNotifId = await upsertPlatformNotification()
|
|
const streamId = await upsertStream()
|
|
return { vtuberId, pNotifId, streamId }
|
|
}
|
|
|
|
// export async function order(
|
|
// userId: string,
|
|
// itemId: string,
|
|
// quantity: number,
|
|
// ): Promise<string> {
|
|
// const haveEnoughInventory: boolean = await checkAndDecrementInventory(
|
|
// itemId,
|
|
// quantity,
|
|
// );
|
|
// if (haveEnoughInventory) {
|
|
// const result: activities.ChargeResult = await chargeUser(
|
|
// userId,
|
|
// itemId,
|
|
// quantity,
|
|
// );
|
|
// if (result.status === "success") {
|
|
// return `Order successful!`;
|
|
// } else {
|
|
// await incrementInventory(itemId, quantity);
|
|
// return `Unable to complete payment. Error: ${result.errorMessage}`;
|
|
// }
|
|
// } else {
|
|
// return `Sorry, we don't have enough items in stock to fulfill your order.`;
|
|
// }
|
|
// }
|