Translated Twitter Mentions -> Slack
@pravin
code:
data:privatelast updated:1 year ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 250,000+ developers using the Pipedream platform
steps.
trigger
twitter-search
last updated:2 years ago
steps.
translate
auth
to use OAuth tokens and API keys in code via theauths object
(auths.google_cloud_translate)
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across invocations with$checkpoint.
async (event, steps, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
}
31
const fetch = require('node-fetch')

if (event.lang !== 'en' && event.lang !== '') {
  try {
    console.log(`Language is ${event.lang}. Translating`)
    url = `https://translation.googleapis.com/language/translate/v2?key=${auths.google_cloud_translate.api_key}`
    method = "POST"
    headers = {
      'Content-Type': 'application/json',
      'charset': 'utf-8',
    }
    const body = JSON.stringify({ q: event.full_text, target: 'en' })
    const data = await fetch(url, { 
      method, 
      body, 
      headers,
    })
    const response = await data.json()
    this.languageCode = response.data.translations[0].detectedSourceLanguage
    this.text = response.data.translations[0].translatedText
  } catch (err) {
    this.error = err
    this.languageCode = event.lang
    this.text = event.full_text
  }
} else {
  this.languageCode = event.lang
  this.text = event.full_text
} 
const fetch = require('node-fetch')

if (event.lang !== 'en' && event.lang !== '') {
  try {
    console.log(`Language is ${event.lang}. Translating`)
    url = `https://translation.googleapis.com/language/translate/v2?key=${auths.google_cloud_translate.api_key}`
    method = "POST"
    headers = {
      'Content-Type': 'application/json',
      'charset': 'utf-8',
    }
    const body = JSON.stringify({ q: event.full_text, target: 'en' })
    const data = await fetch(url, { 
      method, 
      body, 
      headers,
    })
    const response = await data.json()
    this.languageCode = response.data.translations[0].detectedSourceLanguage
    this.text = response.data.translations[0].translatedText
  } catch (err) {
    this.error = err
    this.languageCode = event.lang
    this.text = event.full_text
  }
} else {
  this.languageCode = event.lang
  this.text = event.full_text
} 
steps.
generate_messages
auth
to use OAuth tokens and AP