diff --git a/README.md b/README.md index 8b67907..d2422e1 100644 --- a/README.md +++ b/README.md @@ -140,16 +140,19 @@ plugins: ##### Supabase Commands - To start the Supabase database locally, run the following command: + ```bash yarn supabase start ``` - To reset the Supabase database, run the following command: + ```bash yarn supabase db reset ``` - To stop the Supabase database, run the following command: + ```bash yarn supabase stop ``` diff --git a/manifest.json b/manifest.json index 20b8a56..8d6dfd5 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { "name": "ubiquity-os/kernel-telegram", "description": "Part kernel plugin, part Telegram kernel. This bot is designed to be a bridge between UbiquityOS and Telegram.", - "ubiquity:listeners": ["issues.labeled", "issues.closed", "issues.reopened"] + "ubiquity:listeners": ["issues.closed", "issues.reopened", "issues.assigned"] } diff --git a/package.json b/package.json index 35d61bd..85afa5a 100644 --- a/package.json +++ b/package.json @@ -103,4 +103,4 @@ "@commitlint/config-conventional" ] } -} \ No newline at end of file +} diff --git a/src/bot/mtproto-api/workrooms/create-chat.ts b/src/bot/mtproto-api/workrooms/create-chat.ts index 942c01f..532ebf9 100644 --- a/src/bot/mtproto-api/workrooms/create-chat.ts +++ b/src/bot/mtproto-api/workrooms/create-chat.ts @@ -4,7 +4,7 @@ import { addCommentToIssue } from "../../../utils/add-comment-to-issues"; import { MtProto } from "../bot/mtproto"; import bigInt from "big-integer"; -export async function createChat(context: Context<"issues.labeled", SupportedEvents["issues.labeled"]>): Promise { +export async function createChat(context: Context<"issues.assigned", SupportedEvents["issues.assigned"]>): Promise { const { payload, config, logger } = context; const chatName = "@" + payload.repository.full_name + "#" + payload.issue.number; @@ -13,14 +13,14 @@ export async function createChat(context: Context<"issues.labeled", SupportedEve return { status: 200, reason: "skipped" }; } - const labelName = payload.label?.name.toLowerCase(); + const chatExists = await context.adapters.supabase.chats.getChatByTaskNodeId(payload.issue.node_id); - if (!labelName?.toLowerCase().includes("price")) { - logger.info("Skipping chat creation (reason: no price label has been set)."); - return { status: 200, reason: "skipped" }; + if (chatExists) { + logger.info("Chat already exists for this issue."); + return { status: 200, reason: "chat_exists" }; } - logger.info(`Will attempt to create a new chat room '${chatName}'...`, { labelName }); + logger.info(`Will attempt to create a new chat room '${chatName}'...`); const mtProto = new MtProto(context); await mtProto.initialize(); let chatId: number; diff --git a/src/handlers/workflow-proxy.ts b/src/handlers/workflow-proxy.ts index 389993e..0339011 100644 --- a/src/handlers/workflow-proxy.ts +++ b/src/handlers/workflow-proxy.ts @@ -11,9 +11,9 @@ import { handleCallback } from "./worker-proxy"; * see the README for more information on how to set this up. */ export const workflowCallbacks = { - "issues.labeled": [createChat], "issues.closed": [closeChat], "issues.reopened": [reopenChat], + "issues.assigned": [createChat], } as ProxyCallbacks; export function proxyWorkflowCallbacks(context: Context): ProxyCallbacks {