Skip to content

Commit ac091e0

Browse files
committed
feat: Added null checks for update and replyMessage objects to prevent potential null pointer exceptions
1 parent b3baa99 commit ac091e0

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/bot/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export class CopBot {
4848
}
4949

5050
console.log('Received webhook body:', update);
51+
if (!update || !update.id) {
52+
throw new Error('Missing required field: id');
53+
}
5154
await this._bot.handleUpdate(update);
5255
res.statusCode = 200;
5356
res.end();

src/decorators/Bot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function ReplyToBot() {
1919
return createDecorator(async (ctx, next, close) => {
2020
const reply = new BotReply(ctx);
2121
const replyMessage = ctx.message?.reply_to_message?.from!;
22-
if (replyMessage.id! === ctx.me.id) {
22+
if (replyMessage && replyMessage.id! === ctx.me.id) {
2323
const randomMessage = jokeMessage();
2424
await reply.textReply(randomMessage);
2525
close();

0 commit comments

Comments
 (0)