Gato curioso
@lucasew
code:
data:privatelast updated:4 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,000+ developers using the Pipedream platform
steps.
trigger
Email
Deploy to generate unique email address
This workflow runs on Pipedream's servers and is triggered when an email is received.
steps.
nodejs
auth
to use OAuth tokens and API keys in code via theauths object
(auths.telegram_bot_api)
params
chat_id to send messages
 
string ·params.telegram_bot_chat
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 executions with$checkpoint.
async (event, steps, params, 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
32
33
34
35
36
37
}
38
const Telegram = require('node-telegram-bot-api') 
const bot = new Telegram(auths.telegram_bot_api.token)
bot.on('update', console.log)
const title = steps.trigger.event.subject
const source = steps.trigger.event.from
const text = steps.trigger.event.text
let textToSend = `
*${title}*

${source.map((addr) => `from: ${addr.name} <${addr.address}>`).concat("\n\r")}

${text}
`
textToSend = textToSend.replace(/\./g, "\\.").replace("<", "\\<").replace(">", "\\>")
try {
  await bot.sendMessage(
    params.telegram_bot_chat,
    textToSend,
    {
      parse_mode: "MarkdownV2"
    }
  )
  await Promise.all(event.attachments.map((file) =>
    bot.sendDocument(
      params.telegram_bot_chat,
      new Buffer(file.content_b64, 'base64'),
      {},
      {
        filename: file.fileName,
        contentType: file.contentType
      }
    )
  ))
} catch (e) {
  console.error(e)
}