@fentaris/approval-telegram when a policy needs a human approve/deny step without building a custom UI. The adapter sends a Telegram message with Approve and Deny buttons, and the policy engine blocks the protected tool call until the store records a decision.
Policy Option, Not Middleware
telegramApproval(...) returns a Pick<ToolPermissionOptions, "approval">. It is a policy option that you pass to policy(...).mcp(server).allow(tool, ...) or policy(...).mcp(server).deny(tool, ...). It is not middleware, and there is no .middleware(...) method.
Telegram approval is evaluated by the policy engine before any middleware or tool route runs. If you want a runtime hook, use
proxy.use(...) or a tool route. The policy option is for the “should this call proceed at all” decision; the middleware is for what happens next.Quick Start
Local Approval Without A Bot
For local development and tests, use an in-memory store and a mockedfetch implementation. This exercises the same policy approval path without creating a Telegram bot or webhook.
Sensitive-Tool Test Path
You can drive the full approval flow in a test without a real Telegram bot. Inject afetch mock to capture the message request, and use createInMemoryTelegramApprovalStore to record a decision between calls. The example below uses policy.evaluate(...) so the test path matches the real policy pipeline.
Handle Callbacks
Wire Telegram webhook updates tohandleTelegramApprovalCallback. The in-memory store is useful for local demos; production deployments should provide a durable store.
telegramApproval(...) returns pending until the store has an approval decision for the request id. Fentaris denies the current tool call while the approval is pending and includes safe approval metadata in the policy error.
Callback buttons use signed compact payloads that bind the approve or deny action to the request id. handleTelegramApprovalCallback(...) rejects callbacks from any chat other than the configured chatId, callbacks without message chat metadata, and callback data with invalid signatures.
Secure Webhooks
When using Telegram webhooks, set a Telegram secret token and pass the request headers to the callback handler. The handler validatesX-Telegram-Bot-Api-Secret-Token before processing callback data.
Fail Closed By Default
The default failure mode is fail closed: if Telegram message delivery fails, the protected call is denied.failOpen: true is still available as an explicit development or emergency override, and the adapter emits a warning when it is enabled because approval delivery failures will allow protected calls.