Skip to main content
Module

x/grammy_conversations/mod.ts>ConversationHandle#external

Conversational interfaces for grammY
Go to Latest
method ConversationHandle.prototype.external
import { ConversationHandle } from "https://deno.land/x/grammy_conversations@v1.1.1/mod.ts";

Safely performs an operation with side-effects. You must use this to wrap all communication with external systems that does not go through grammY, such as database communication or calls to external APIs.

This function will then make sure the operation is only performed once, and not every time a message is handled by the conversation.

It will need to be able to store the result value of this operation in the session. Hence, it must store and load the result of the operation according to your storage adapter. It is therefore best to only return primitive values or POJOs. If you need to transform your data before it can be stored, you can specify the beforeStore function. If you need to transform your data after it was loaded, you can specify the afterLoad function.

Type Parameters

F extends (...args: any[]) => any
optional
I = any

Parameters

op: F | { task: F; args?: Parameters<F>; beforeStore?: (value: Awaited<ReturnType<F>>) => I | Promise<I>; afterLoad?: (value: I) => ReturnType<F> | Promise<ReturnType<F>>; beforeStoreError?: (value: unknown) => unknown | Promise<unknown>; afterLoadError?: (value: unknown) => unknown; }

An external operation to perform

Returns

Promise<Awaited<ReturnType<F>>>

The result of the operation