telegram.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Channel::Driver::Telegram
  3. =begin
  4. instance = Channel::Driver::Telegram.new
  5. instance.send(
  6. {
  7. adapter: 'telegram',
  8. auth: {
  9. api_key: api_key
  10. },
  11. },
  12. telegram_attributes,
  13. notification
  14. )
  15. =end
  16. def deliver(options, article, _notification = false)
  17. # return if we run import mode
  18. return if Setting.get('import_mode')
  19. options = check_external_credential(options)
  20. @client = TelegramHelper.new(options[:auth][:api_key])
  21. @client.from_article(article)
  22. end
  23. =begin
  24. Channel::Driver::Telegram.streamable?
  25. returns
  26. true|false
  27. =end
  28. def self.streamable?
  29. false
  30. end
  31. private
  32. def check_external_credential(options)
  33. if options[:auth] && options[:auth][:external_credential_id]
  34. external_credential = ExternalCredential.find_by(id: options[:auth][:external_credential_id])
  35. raise "No such ExternalCredential.find(#{options[:auth][:external_credential_id]})" if !external_credential
  36. options[:auth][:api_key] = external_credential.credentials['api_key']
  37. end
  38. options
  39. end
  40. end