Closed tatakishiev closed 6 months ago
Hey!
The : extras field does not save values between messages, at least now, I've been looking at the dispatcher and we could keep some information between messages.
Right now, the :extras
field is used from the middlewares, to add information to your context from them, for example, you could have your own User entity, load it in a middleware and save it on the extras field, so the Bot logic doesn't have to handle that logic.
Example of Middleware:
defmodule UserMiddleware do
use ExGram.Middleware
alias ExGram.Cnt
def call(%Cnt{update: update} = cnt, _opts) do
user = update |> ExGram.Dsl.extract_user() |> MyUser.find()
add_extra(cnt, %{user: user})
end
end
Okay, thank you for your explanation
Hello team, as per the description says: The second argument is a map called Context (%ExGram.Cnt{}) with information about the update that just arrived, with information like the message object and internal data that ExGram will use to answer the message. You can also save your own information from your own middlewares in the :extra key using the add_extra method.
I put some information in the "extra" field based on the use case and I assume that in the next iteration, I will have access to "extra", but it is blank, always blank. The data that I put there has disappeared.