Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create on assignment #8

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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