Skip to content

Commit b20e60f

Browse files
author
remote-swe-app[bot]
committed
Fix: Add validation for mention position in messages
1 parent 50cf7e3 commit b20e60f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

slack-bolt-app/src/app.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,29 @@ const app = new App({
3232
app.event('app_mention', async ({ event, client, logger }) => {
3333
console.log('app_mention event received');
3434
console.log(JSON.stringify(event));
35-
const message = event.text.slice(event.text.indexOf('>') + 1).trim();
35+
36+
// Check if the mention is at the beginning of the message
37+
const mentionEndIndex = event.text.indexOf('>');
38+
if (mentionEndIndex <= 0 || !event.text.startsWith('<@')) {
39+
await client.chat.postMessage({
40+
channel: event.channel,
41+
text: `<@${event.user}> メンションは文頭に配置してください(例:@remote-swe-agents こんにちは)`,
42+
thread_ts: event.thread_ts ?? event.ts,
43+
});
44+
return;
45+
}
46+
47+
const message = event.text.slice(mentionEndIndex + 1).trim();
48+
// 空のメッセージの場合もエラーを返す
49+
if (!message) {
50+
await client.chat.postMessage({
51+
channel: event.channel,
52+
text: `<@${event.user}> メッセージ内容が空です。メンションの後にメッセージを入力してください。`,
53+
thread_ts: event.thread_ts ?? event.ts,
54+
});
55+
return;
56+
}
57+
3658
const userId = event.user ?? '';
3759
const channel = event.channel;
3860
try {

0 commit comments

Comments
 (0)