Class: TelegramWorkflow::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_workflow/client.rb

Constant Summary collapse

API_VERSION =
"4.9"
WebhookConfigPath =
Pathname.new("tmp/telegram_workflow/webhook_config.txt")
AVAILABLE_ACTIONS =
%i(
  getUpdates
  getWebhookInfo

  getMe
  sendMessage
  forwardMessage
  sendPhoto
  sendAudio
  sendDocument
  sendVideo
  sendAnimation
  sendVoice
  sendVideoNote
  sendMediaGroup
  sendLocation
  editMessageLiveLocation
  stopMessageLiveLocation
  sendVenue
  sendContact
  sendPoll
  sendDice
  sendChatAction
  getUserProfilePhotos
  getFile
  kickChatMember
  unbanChatMember
  restrictChatMember
  promoteChatMember
  setChatAdministratorCustomTitle
  setChatPermissions
  exportChatInviteLink
  setChatPhoto
  deleteChatPhoto
  setChatTitle
  setChatDescription
  pinChatMessage
  unpinChatMessage
  leaveChat
  getChat
  getChatAdministrators
  getChatMembersCount
  getChatMember
  setChatStickerSet
  deleteChatStickerSet
  answerCallbackQuery
  setMyCommands
  getMyCommands

  editMessageText
  editMessageCaption
  editMessageMedia
  editMessageReplyMarkup
  stopPoll
  deleteMessage

  sendSticker
  getStickerSet
  uploadStickerFile
  createNewStickerSet
  addStickerToSet
  setStickerPositionInSet
  deleteStickerFromSet
  setStickerSetThumb

  answerInlineQuery

  sendInvoice
  answerShippingQuery
  answerPreCheckoutQuery

  setPassportDataErrors

  sendGame
  setGameScore
  getGameHighScores
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chat_id = nil) ⇒ Client

Returns a new instance of Client.



96
97
98
99
# File 'lib/telegram_workflow/client.rb', line 96

def initialize(chat_id = nil)
  @chat_id = chat_id
  @api_url = "https://api.telegram.org/bot#{TelegramWorkflow.config.api_token}"
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



94
95
96
# File 'lib/telegram_workflow/client.rb', line 94

def api_url
  @api_url
end

#inlineObject

Returns the value of attribute inline.



93
94
95
# File 'lib/telegram_workflow/client.rb', line 93

def inline
  @inline
end

#inline_requestObject

Returns the value of attribute inline_request.



93
94
95
# File 'lib/telegram_workflow/client.rb', line 93

def inline_request
  @inline_request
end

Instance Method Details

#__setup_webhook(webhook_url = TelegramWorkflow.config.webhook_url, params = {}) ⇒ Object



111
112
113
114
115
116
117
118
119
120
# File 'lib/telegram_workflow/client.rb', line 111

def __setup_webhook(webhook_url = TelegramWorkflow.config.webhook_url, params = {})
  TelegramWorkflow.config.logger.info "[TelegramWorkflow] Checking webhook setup..."

  webhook_params = { url: webhook_url, allowed_updates: [], **params }

  if cached_webhook_config != webhook_params
    TelegramWorkflow.config.logger.info "[TelegramWorkflow] Setting up a new webhook..."
    set_webhook(webhook_params)
  end
end

#delete_webhookObject



106
107
108
109
# File 'lib/telegram_workflow/client.rb', line 106

def delete_webhook
  make_request("deleteWebhook")
  cached_webhook_config({})
end

#set_webhook(params = {}) ⇒ Object



101
102
103
104
# File 'lib/telegram_workflow/client.rb', line 101

def set_webhook(params = {})
  make_request("setWebhook", params)
  cached_webhook_config(params)
end