Add a method to send a photo.
This commit is contained in:
parent
81eee54695
commit
cebc91d13a
|
@ -58,6 +58,41 @@ module Telepathy
|
||||||
body: message_data.to_json)
|
body: message_data.to_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def send_photo(chat_id : String | Int64, photo : String | File, caption : String? = nil,
|
||||||
|
disable_notification : Bool = false,
|
||||||
|
reply_to_message_id : Int64? = nil)
|
||||||
|
IO.pipe do |reader, writer|
|
||||||
|
channel = Channel(String).new(1)
|
||||||
|
spawn do
|
||||||
|
HTTP::FormData.build(writer) do |formdata|
|
||||||
|
channel.send(formdata.content_type)
|
||||||
|
case chat_id
|
||||||
|
when String
|
||||||
|
formdata.field("chat_id", chat_id.as(String))
|
||||||
|
when Int64
|
||||||
|
formdata.field("chat_id", chat_id.as(Int64).to_s)
|
||||||
|
end
|
||||||
|
formdata.field("disable_notification", disable_notification.to_s)
|
||||||
|
caption.try { |caption| formdata.field("caption", caption) }
|
||||||
|
reply_to_message_id.try { |id| formdata.field("reply_to_message_id", id) }
|
||||||
|
case photo
|
||||||
|
when String
|
||||||
|
formdata.field("photo", photo.as(String))
|
||||||
|
when File
|
||||||
|
formdata.file("photo", photo.as(IO),
|
||||||
|
HTTP::FormData::FileMetadata.new(filename: File.basename(photo.path)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
writer.close
|
||||||
|
end
|
||||||
|
|
||||||
|
response = HTTP::Client.get(@request_base + "/sendPhoto",
|
||||||
|
headers: HTTP::Headers{"User-agent" => "Telepathy", "Content-type" => channel.receive },
|
||||||
|
body: reader)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def command(command_name, &block: Update, Array(String) -> Void)
|
def command(command_name, &block: Update, Array(String) -> Void)
|
||||||
@command_hooks[command_name] = block
|
@command_hooks[command_name] = block
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user