rockneurotiko/ex_gram

Stop process if get my_chat_member

Closed this issue · 4 comments

How I can halt process and next handles in middleware if I get from user my_chat_member with kicked status?

If you want to keep track if a member has been kicked you will need to store somewhere which user has been kicked when receiving an user update and then in the middleware ask about the user status.

Look what I mean ))
I have middleware to save user:

  def call(cnt, _opts) do
    {:ok, from} = extract_user(cnt.update)

    user =
      User.changeset(%User{}, from)
      |> Repo.insert!(
        on_conflict: {:replace_all_except, [:id, :is_bot, :answers, :inserted_at]},
        conflict_target: :id
      )

    add_extra(cnt, :from, user)
  end

And I want to add to this middleware new function or add another middleware to save kicked/member user status and halt further process if I get kicked status. So that the application does not call handle functions in bot handler.

You can create a new middleware that reads the update and checks for the kicked messages to update the user with the kicked status.

Then, you can halt in another middleware reading the :from extra information, or you can have the first handle/2 message match for that :from too.

Ok, Thanks.