Metamigo -> Bridge

This commit is contained in:
Darren Clarke 2024-04-21 09:44:30 +02:00
parent 242f3cf6b8
commit a445762a37
145 changed files with 396 additions and 16668 deletions

View file

@ -0,0 +1,55 @@
# frozen_string_literal: true
class Channel
class Driver
class CdrSignal
def fetchable?(_channel)
false
end
def disconnect; end
#
# instance = Channel::Driver::CdrSignal.new
# instance.send(
# {
# adapter: 'cdrsignal',
# auth: {
# api_key: api_key
# },
# },
# signal_attributes,
# notification
# )
#
def send(options, article, _notification = false)
# return if we run import mode
return if Setting.get('import_mode')
options = check_external_credential(options)
Rails.logger.debug { 'signal send started' }
Rails.logger.debug { options.inspect }
@signal = ::CdrSignal.new(options[:bot_endpoint], options[:bot_token])
@signal.from_article(article)
end
def self.streamable?
false
end
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]})" unless external_credential
options[:auth][:api_key] = external_credential.credentials['api_key']
end
options
end
end
end
end