Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field "extra" in context(%ExGram.Cnt{}) is always empty #163

Closed
tatakishiev opened this issue May 9, 2024 · 2 comments
Closed

Field "extra" in context(%ExGram.Cnt{}) is always empty #163

tatakishiev opened this issue May 9, 2024 · 2 comments

Comments

@tatakishiev
Copy link

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.

@rockneurotiko
Copy link
Owner

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

@tatakishiev
Copy link
Author

Okay, thank you for your explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants