Method: Telegrammer::Bot#send_audio

Defined in:
lib/telegrammer/bot.rb

#send_audio(params) ⇒ Telegrammer::DataTypes::Message

Sends audio file to a user or group chat.

At this moment, Telegram only allows Ogg files encoded with the OPUS codec. If you need to send another file format, you must use #send_document.

Examples:

bot = Telegrammer::Bot.new('[YOUR TELEGRAM TOKEN]')
audio_file = File.open("foo.ogg")
bot.send_audio(chat_id: 123456789, audio: audio_file)

Parameters:

  • params (Hash)

    hash of paramers to send to the sendAudio API operation.

Options Hash (params):

  • :chat_id (Integer, String)

    Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • audio (File, String)

    Required. Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data

  • duration (Integer)

    Optional. Duration of the audio in seconds.

  • performer (String)

    Optional. Performer.

  • title (String)

    Optional. Track name.

  • :reply_to_message_id (Integer)

    Optional. If the message is a reply, ID of the original message

  • :reply_markup (Telegrammer::DataTypes::ReplyKeyboardMarkup, Telegrammer::DataTypes::ReplyKeyboardHide, Telegrammer::DataTypes::ForceReply)

    Optional. Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.

Returns:

Raises:

See Also:



229
230
231
232
233
234
235
236
237
238
# File 'lib/telegrammer/bot.rb', line 229

def send_audio(params)
  extra_params_validation = {
    audio: { required: true, class: [File, String] },
    duration: { required: false, class: [Integer] },
    performer: { required: false, class: [String] },
    title: { required: false, class: [String] }
  }

  send_something(:audio, params, extra_params_validation)
end