class Xasin::Telegram::SingleUser

Attributes

httpCore[R]

Public Class Methods

new(userChat, httpCore) click to toggle source
# File lib/xasin/telegram/SingleUser.rb, line 9
def initialize(userChat, httpCore)
        # Check if we already have a HTTPCore, else create one
        @httpCore = if(httpCore.is_a? Telegram::HTTPCore)
                        httpCore;
                else
                        Telegram::HTTPCore.new(httpCore);
                end
        @httpCore.attach_receptor(self);
        @httpCore.attach_receptor(self);

        @userID = userChat;

        @message_procs               = Array.new();
        @inlinebutton_procs  = Array.new();
end

Public Instance Methods

delete_message(mID) click to toggle source
# File lib/xasin/telegram/SingleUser.rb, line 66
def delete_message(mID)
        @httpCore.perform_post("deleteMessage", {chat_id: @userID, message_id: mID});
end
edit_message(mID, text=nil, **args) click to toggle source
# File lib/xasin/telegram/SingleUser.rb, line 52
def edit_message(mID, text=nil, **args)
        args[:chat_id]               = @userID;
        args[:message_id]    = mID;

        args[:parse_mode]            ||= "Markdown";

        if(text) then
                args[:text] = text;
                @httpCore.perform_post("editMessageText", args);
        else
                @httpCore.perform_post("editMessageReplyMarkup", args);
        end
end
handle_packet(packet) click to toggle source
# File lib/xasin/telegram/SingleUser.rb, line 25
def handle_packet(packet)
        if(packet[:message])
                return unless packet[:message][:chat][:id] == @userID;

                @message_procs.each do |cb| cb.call(packet[:message]); end
                packet[:has_been_handled] = true;
        end

        return unless packet[:callback_query]
        return unless packet[:callback_query][:message][:chat][:id] == @userID;

        @inlinebutton_procs.each { |cb| cb.call(packet[:callback_query]); }
        packet[:has_been_handled] = true;
end
on_inlinebutton_press(&block) click to toggle source
# File lib/xasin/telegram/SingleUser.rb, line 73
def on_inlinebutton_press(&block)
        @inlinebutton_procs << block;
end
on_message(&block) click to toggle source
# File lib/xasin/telegram/SingleUser.rb, line 70
def on_message(&block)
        @message_procs << block;
end
send_message(text, **args) click to toggle source
# File lib/xasin/telegram/SingleUser.rb, line 40
def send_message(text, **args)
        args ||= Hash.new();
        args[:text] = text;

        args[:chat_id]       =   @userID;
        args[:parse_mode]    ||= "Markdown";

        sent_message = @httpCore.perform_post("sendMessage", args);

        return sent_message[:result][:message_id];
end