2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2017-02-15 02:35:22 +00:00
|
|
|
|
|
|
|
class Channel::Driver::Telegram
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
instance = Channel::Driver::Telegram.new
|
|
|
|
instance.send(
|
|
|
|
{
|
|
|
|
adapter: 'telegram',
|
|
|
|
auth: {
|
2019-07-30 13:47:53 +00:00
|
|
|
api_key: api_key
|
2017-02-15 02:35:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
telegram_attributes,
|
|
|
|
notification
|
|
|
|
)
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def send(options, article, _notification = false)
|
|
|
|
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
|
|
|
|
|
|
|
options = check_external_credential(options)
|
|
|
|
|
|
|
|
@client = Telegram.new(options[:auth][:api_key])
|
2020-07-07 06:30:20 +00:00
|
|
|
@client.from_article(article)
|
|
|
|
|
2017-02-15 02:35:22 +00:00
|
|
|
end
|
|
|
|
|
2017-10-02 11:23:14 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
Channel::Driver::Telegram.streamable?
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
true|false
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.streamable?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-02-15 02:35:22 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def check_external_credential(options)
|
|
|
|
if options[:auth] && options[:auth][:external_credential_id]
|
|
|
|
external_credential = ExternalCredential.find_by(id: options[:auth][:external_credential_id])
|
|
|
|
raise "No such ExternalCredential.find(#{options[:auth][:external_credential_id]})" if !external_credential
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-02-15 02:35:22 +00:00
|
|
|
options[:auth][:api_key] = external_credential.credentials['api_key']
|
|
|
|
end
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|