Skip to content

Commit abc9cfb

Browse files
committed
send reminders on threads, support 10+ languages now on translation shortcuts
1 parent 7a73a46 commit abc9cfb

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

src/handlers/message.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function registerMessageHandler(app: App) {
1313
if (!("text" in event) || !event.text) return;
1414
if ("bot_id" in event && event.bot_id) return;
1515

16-
const { text, user: userId, channel, ts } = event as any;
16+
const { text, user: userId, channel, ts, thread_ts } = event as any;
1717
if (!userId || !text.trim()) return;
1818

1919
(async () => {
@@ -48,6 +48,7 @@ export function registerMessageHandler(app: App) {
4848
channel,
4949
user: userId,
5050
text: lang.greeting,
51+
thread_ts,
5152
blocks: [
5253
{
5354
type: "section",
@@ -102,6 +103,7 @@ export function registerMessageHandler(app: App) {
102103
channel,
103104
user: userId,
104105
text: lang.greeting,
106+
thread_ts,
105107
blocks: [
106108
{
107109
type: "section",

src/handlers/shortcuts.ts

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,36 @@ export function registerShortcuts(app: App) {
2929
multiline: true,
3030
placeholder: {
3131
type: "plain_text",
32-
text: "Enter text to translate to English...",
32+
text: "Enter text to translate...",
3333
},
3434
},
3535
label: { type: "plain_text", text: "Text" },
3636
},
37+
{
38+
type: "input",
39+
block_id: "language_selection_block",
40+
element: {
41+
type: "static_select",
42+
action_id: "language_selection",
43+
initial_option: {
44+
text: { type: "plain_text", text: "English" },
45+
value: "English",
46+
},
47+
options: [
48+
{ text: { type: "plain_text", text: "English" }, value: "English" },
49+
{ text: { type: "plain_text", text: "Spanish" }, value: "Spanish" },
50+
{ text: { type: "plain_text", text: "French" }, value: "French" },
51+
{ text: { type: "plain_text", text: "German" }, value: "German" },
52+
{ text: { type: "plain_text", text: "Chinese" }, value: "Chinese" },
53+
{ text: { type: "plain_text", text: "Japanese" }, value: "Japanese" },
54+
{ text: { type: "plain_text", text: "Korean" }, value: "Korean" },
55+
{ text: { type: "plain_text", text: "Portuguese" }, value: "Portuguese" },
56+
{ text: { type: "plain_text", text: "Italian" }, value: "Italian" },
57+
{ text: { type: "plain_text", text: "Russian" }, value: "Russian" },
58+
],
59+
},
60+
label: { type: "plain_text", text: "Target Language" },
61+
},
3762
],
3863
},
3964
});
@@ -69,11 +94,36 @@ export function registerShortcuts(app: App) {
6994
initial_value: messageText,
7095
placeholder: {
7196
type: "plain_text",
72-
text: "Enter text to translate to English...",
97+
text: "Enter text to translate...",
7398
},
7499
},
75100
label: { type: "plain_text", text: "Text" },
76101
},
102+
{
103+
type: "input",
104+
block_id: "language_selection_block",
105+
element: {
106+
type: "static_select",
107+
action_id: "language_selection",
108+
initial_option: {
109+
text: { type: "plain_text", text: "English" },
110+
value: "English",
111+
},
112+
options: [
113+
{ text: { type: "plain_text", text: "English" }, value: "English" },
114+
{ text: { type: "plain_text", text: "Spanish" }, value: "Spanish" },
115+
{ text: { type: "plain_text", text: "French" }, value: "French" },
116+
{ text: { type: "plain_text", text: "German" }, value: "German" },
117+
{ text: { type: "plain_text", text: "Chinese" }, value: "Chinese" },
118+
{ text: { type: "plain_text", text: "Japanese" }, value: "Japanese" },
119+
{ text: { type: "plain_text", text: "Korean" }, value: "Korean" },
120+
{ text: { type: "plain_text", text: "Portuguese" }, value: "Portuguese" },
121+
{ text: { type: "plain_text", text: "Italian" }, value: "Italian" },
122+
{ text: { type: "plain_text", text: "Russian" }, value: "Russian" },
123+
],
124+
},
125+
label: { type: "plain_text", text: "Target Language" },
126+
},
77127
],
78128
},
79129
});
@@ -82,6 +132,8 @@ export function registerShortcuts(app: App) {
82132
app.view("rosetta_translate_modal", async ({ ack, view, client, body }) => {
83133
const input =
84134
view.state.values?.["translate_input_block"]?.["translate_input"]?.value ?? "";
135+
const targetLanguage =
136+
view.state.values?.["language_selection_block"]?.["language_selection"]?.selected_option?.value ?? "English";
85137

86138
const { channelId, threadTs } = JSON.parse(view.private_metadata || "{}");
87139

@@ -97,7 +149,7 @@ export function registerShortcuts(app: App) {
97149

98150
await ack();
99151

100-
const translated = await translate(input);
152+
const translated = await translate(input, targetLanguage);
101153

102154
try {
103155
await client.chat.postMessage({

src/lib/hackai.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ Respond "no" only if the entire message is 100% English.`,
2424
}
2525
}
2626

27-
export async function translate(text: string): Promise<string> {
27+
export async function translate(text: string, targetLanguage: string = "English"): Promise<string> {
2828
try {
29+
const instructions = await Bun.file("./instructions.txt").text();
30+
const basePrompt = instructions.replace("into English", `into ${targetLanguage}`);
31+
2932
const result = await client.callModel({
3033
model: "google/gemini-2.5-flash",
31-
instructions: await Bun.file("./instructions.txt").text(),
34+
instructions: basePrompt,
3235
input: text,
3336
});
3437

3538
return await result.getText();
3639
} catch (error) {
37-
console.error("Error checking if text needs translation:", error);
40+
console.error("Error translating text:", error);
3841
return "";
3942
}
4043
}

0 commit comments

Comments
 (0)