Skip to content

Commit

Permalink
chore: add onResponse and onResponseError
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed Nov 24, 2024
1 parent d4f2312 commit 473b415
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
34 changes: 33 additions & 1 deletion docs/hooks/on-response-error.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# TODO
# onResponseError

This hook called `after receiving a error response` from Telegram Bot API.

## Parameters

[TelegramError](https://jsr.io/@gramio/core@latest/doc/~/TelegramError)

<!-- > [!IMPORTANT] -->

## Example

```ts twoslash
import { Bot } from "gramio";

const bot = new Bot(process.env.BOT_TOKEN as string).onResponseError(
(context) => {
console.log("Error for", context.method, context.message);
}
);
```

### Add hook only to specified API methods

```ts
bot.onResponseError("sendMessage", (context) => {
console.log("Error for sendMessage", context.message);
});
// or array
bot.onResponseError(["sendMessage", "sendPhoto"], (context) => {
console.log("Error for", context.method, context.message);
});
```
36 changes: 35 additions & 1 deletion docs/hooks/on-response.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# TODO
# onResponse

This hook called `after receiving a successful response` from Telegram Bot API.

## Parameters

Object with:

- method - API method name
- params - API method params
- response - response

<!-- > [!IMPORTANT] -->

## Example

```ts twoslash
import { Bot } from "gramio";

const bot = new Bot(process.env.BOT_TOKEN as string).onResponse((context) => {
console.log("response for", context.method, context.response);
});
```

### Add hook only to specified API methods

```ts
bot.onResponse("sendMessage", (context) => {
console.log("response for sendMessage", context.response);
});
// or array
bot.preRequest(["sendMessage", "sendPhoto"], (context) => {
console.log("response for", context.method, context.response);
});
```

0 comments on commit 473b415

Please sign in to comment.