feat: Add Google Translate API Integration (#6454)

This commit is contained in:
Pranav Raj S
2023-02-15 20:50:45 -08:00
committed by GitHub
parent c12bdc8350
commit 80784e3cab
17 changed files with 229 additions and 6 deletions

View File

@@ -0,0 +1,30 @@
class Integrations::GoogleTranslate::ProcessorService
pattr_initialize [:message!, :target_language!]
def perform
return if message.content.blank?
return if hook.blank?
response = client.translate_text(
contents: [message.content],
target_language_code: target_language,
parent: "projects/#{hook.settings['project_id']}"
)
return if response.translations.first.blank?
response.translations.first.translated_text
end
private
def hook
@hook ||= message.account.hooks.find_by(app_id: 'google_translate')
end
def client
@client ||= Google::Cloud::Translate.translation_service do |config|
config.credentials = hook.settings['credentials']
end
end
end