-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add onResponse and onResponseError
- Loading branch information
1 parent
d4f2312
commit 473b415
Showing
2 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
``` |