Skip to content

Implement chat events handling #31

Description

@lsdrfrx

Motivations

Now events like message reaction or new chat member are ignored, because TelegramEx.Server.process_update/2 processes only message field. Need to add Update type and extend processing, so different event handling will be possible via new handle_event/2 and defevent (maybe, I'm not sure that macro is useful yet)

Solution

Example:

  %TelegramEx.Event{
    type: :message_reaction,
    payload: payload,
    update: raw_update,
    message: message_or_nil,
    chat_id: chat_id_or_nil,
    message_thread_id: thread_id_or_nil
  }

  def handle_event(%Event{type: :new_chat_members, payload: members, message: message}, ctx) do
    names = Enum.map_join(members, ", ", & &1["first_name"])

    ctx
    |> Message.text("Welcome, #{names}")
    |> Message.send(message.chat.id)
  end

  defevent :new_chat_members, bind: [:members, :message, :ctx] do
    names = Enum.map_join(members, ", ", & &1["first_name"])

    ctx
    |> Message.text("Welcome, #{names}")
    |> Message.send(message.chat.id)
  end

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions