Skip to content

Commit

Permalink
Replace use of null with undefined to stop sending chat actions
Browse files Browse the repository at this point in the history
  • Loading branch information
deptyped committed May 6, 2024
1 parent f9f9457 commit ac7d37c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ actions for the current update.
// Set the action to be sent until the update is processed
ctx.chatAction = "typing";

// To stop sending the chat action, simply set it to null
ctx.chatAction = null;
// To stop sending the chat action, simply set it to undefined
ctx.chatAction = undefined;

// You can change the chat action during update processing
ctx.chatAction = "choose_sticker";
Expand All @@ -135,7 +135,7 @@ await ctx.replyWithPhoto(
);

// There is no ongoing chat action now
// ctx.chatAction is null
// ctx.chatAction is undefined
```

#### Sending Chat Action with Middleware
Expand Down
6 changes: 3 additions & 3 deletions src/auto-chat-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createChatActionsController } from "./chat-actions-controller.ts";
import { getChatActionsForRequest } from "./extract-chat-actions.ts";

export type AutoChatActionFlavor = {
chatAction: Action | null;
chatAction: Action | undefined;
};

export function autoChatAction<C extends Context>(
Expand Down Expand Up @@ -56,12 +56,12 @@ export function autoChatAction<C extends Context>(
payload.chat_id,
messageThreadId,
);
currentAction = null;
currentAction = undefined;
}
},
);

let currentAction: Action | null = null;
let currentAction: Action | undefined = undefined;
Object.defineProperty(ctx, "chatAction", {
get() {
return currentAction;
Expand Down
4 changes: 2 additions & 2 deletions test/auto-chat-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ describe("autoChatAction middleware", () => {

await ctx.api.sendPhoto(chat_id, photo, {}, signal);

assertEquals(ctx.chatAction, null);
assertEquals(ctx.chatAction, undefined);
});

await bot.handleUpdate({
Expand Down Expand Up @@ -1386,7 +1386,7 @@ describe("autoChatAction middleware", () => {
ctx.chatAction = "typing";
ctx.chatAction = "choose_sticker";
await time.tickAsync(actionSendingInterval);
ctx.chatAction = null;
ctx.chatAction = undefined;
await time.tickAsync(actionSendingInterval * 2);
ctx.chatAction = "find_location";

Expand Down

0 comments on commit ac7d37c

Please sign in to comment.