class Telecr::Core::Context

Overview

Context holds everything related to a single Telegram update It's passed through middleware chain and finally to the user's handler

Defined in:

core/context.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(update : Types::Update, bot : Bot) #

Initialize with update and bot


[View source]

Instance Method Detail

def answer_callback_query(text : String | Nil = nil, show_alert : Bool = false, **options) #

Answer a callback query


[View source]
def answer_inline_query(results : Array, **options) #

Answer an inline query with results


[View source]
def api #

Get API client


[View source]
def audio(audio, caption : String | Nil = nil, **options) #

Send an audio file


[View source]
def ban_chat_member(user_id : Int64, **options) #

Ban a member from the chat


[View source]
def bot : Bot #

[View source]
def bot=(bot : Bot) #

[View source]
def callback_query : Types::CallbackQuery | Nil #

Get the callback query if this update is a callback


[View source]
def callback_query? : Bool #

Check if this is a callback query


[View source]
def caption : String | Nil #

Get message caption


[View source]
def caption_entities : Array(Types::MessageEntity) #

Get caption entities


[View source]
def channel_post? : Bool #

Check if this is a channel post


[View source]
def chat : Types::Chat | Nil #

Get the chat where this update occurred


[View source]
def command? : Bool #

Check if this is a command message


[View source]
def command_args : String | Nil #

Get command arguments if this is a command


[View source]
def command_name : String | Nil #

Get command name if this is a command


[View source]
def copy_message(from_chat_id : Int64, message_id : Int64, **options) #

Copy a message from another chat


[View source]
def data : String | Nil #

Get callback data (for callback queries)


[View source]
def delete_message(message_id : Int64 | Nil = nil) #

Delete a message


[View source]
def document(document, caption : String | Nil = nil, **options) #

Send a document


[View source]
def download_file(file_id : String, destination_path : String | Nil = nil) #

Download a file from Telegram


[View source]
def edit_date : Time | Nil #

Get edit date if message was edited


[View source]
def edit_message_reply_markup(reply_markup, **options) #

Edit message reply markup


[View source]
def edit_message_text(text : String, **options) #

Edit the current message text


[View source]
def edited? : Bool #

Check if this is an edited message


[View source]
def entities : Array(Types::MessageEntity) #

Get message entities


[View source]
def forward_message(from_chat_id : Int64, message_id : Int64, **options) #

Forward a message from another chat


[View source]
def from : Types::User | Nil #

Get the user who sent this update


[View source]
def get_chat(**options) #

Get chat info


[View source]
def get_chat_administrators(**options) #

Get chat administrators


[View source]
def get_chat_members_count(**options) #

Get members count


[View source]
def has_media? : Bool #

Check if message has media


[View source]
def inline_keyboard(&) #

Create an inline keyboard


[View source]
def inline_query : Types::InlineQuery | Nil #

Get the inline query if this update is an inline query


[View source]
def inline_query? : Bool #

Check if this is an inline query


[View source]
def keyboard(&) #

===== Keyboard Helpers ===== Create a reply keyboard


[View source]
def kick_chat_member(user_id : Int64, **options) #

Kick a member from the chat


[View source]
def location(latitude : Float64, longitude : Float64, **options) #

Send a location


[View source]
def logger #

===== Utility Methods ===== Get logger from bot


[View source]
def match : Regex::MatchData | Nil #

[View source]
def match=(match : Regex::MatchData | Nil) #

[View source]
def media_type : Symbol | Nil #

Get media type if present


[View source]
def message : Types::Message | Nil #

===== Update Type Accessors ===== Get the message if this update is a message


[View source]
def message_date : Time | Nil #

Get message date


[View source]
def message_id : Int64 | Nil #

===== Message Properties ===== Get message ID


[View source]
def photo(photo, caption : String | Nil = nil, **options) #

===== Media Sending Methods ===== Send a photo


[View source]
def pin_message(message_id : Int64, **options) #

===== Chat Management ===== Pin a message in the chat


[View source]
def query : String | Nil #

Get inline query text


[View source]
def raw_update #

Get raw update data (for debugging)


[View source]
def remove_keyboard(text : String | Nil = nil, **options) #

Remove keyboard


[View source]
def replied_chat : Types::Chat | Nil #

Get chat of replied message


[View source]
def replied_from : Types::User | Nil #

Get sender of replied message


[View source]
def replied_message : Types::Message | Nil #

Get the message being replied to


[View source]
def replied_text : String | Nil #

Get text of replied message


[View source]
def reply(text : String, options : Hash(String, JSON::Any) = {} of String => JSON::Any) #

===== Response Methods ===== Send a text message to the chat (with hash options)


[View source]
def reply(text : String, **options) #

Send a text message to the chat (with named arguments)


[View source]
def reply? : Bool #

Check if this is a reply to another message


[View source]
def reply_draft(text : String, **options) #

NEW in API 9.5: Send a message draft (streaming)


[View source]
def reply_with_inline_keyboard(text : String, inline_markup, **options) #

Reply with inline keyboard (using the hash version of reply)


[View source]
def reply_with_keyboard(text : String, keyboard_markup, **options) #

Reply with a keyboard (using the hash version of reply)


[View source]
def send_chat_action(action : String, **options) #

Send a chat action (typing, uploading, etc.)


[View source]
def sender_tag : String | Nil #

NEW in API 9.5: Get sender tag (for group members)


[View source]
def session : Hash(String, JSON::Any) #

[View source]
def session=(session : Hash(String, JSON::Any)) #

[View source]
def state : Hash(Symbol, JSON::Any) #

[View source]
def state=(state : Hash(Symbol, JSON::Any)) #

[View source]
def sticker(sticker, **options) #

Send a sticker


[View source]
def typing(**options) #

===== Chat Actions ===== Send typing action


[View source]
def typing_active : Bool #

[View source]
def typing_active=(typing_active : Bool) #

[View source]
def unban_chat_member(user_id : Int64, **options) #

Unban a member


[View source]
def unpin_message(**options) #

Unpin a message


[View source]
def update : Types::Update #

Core properties


[View source]
def update=(update : Types::Update) #

Core properties


[View source]
def update_type : Symbol #

===== Update Type Detection ===== Get the type of this update as a symbol


[View source]
def uploading_audio(**options) #

Send uploading audio action


[View source]
def uploading_document(**options) #

Send uploading document action


[View source]
def uploading_photo(**options) #

Send uploading photo action


[View source]
def uploading_video(**options) #

Send uploading video action


[View source]
def user_id : Int64 | Nil #

Get user ID


[View source]
def video(video, caption : String | Nil = nil, **options) #

Send a video


[View source]
def voice(voice, caption : String | Nil = nil, **options) #

Send a voice message


[View source]
def with_typing(&block) #

Keep typing active during a long operation


[View source]