Skip to content

Commit

Permalink
Merge pull request #8 from ubq-testing/create-on-assignment
Browse files Browse the repository at this point in the history
Create on assignment
  • Loading branch information
Keyrxng authored Oct 21, 2024
2 parents d021a76 + be1302c commit 1710ede
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@
"@commitlint/config-conventional"
]
}
}
}
12 changes: 6 additions & 6 deletions src/bot/mtproto-api/workrooms/create-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CallbackResult> {
export async function createChat(context: Context<"issues.assigned", SupportedEvents["issues.assigned"]>): Promise<CallbackResult> {
const { payload, config, logger } = context;
const chatName = "@" + payload.repository.full_name + "#" + payload.issue.number;

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/workflow-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1710ede

Please sign in to comment.