{
"apiVersion": "zebflow.com/v1",
"kind": "Pipeline",
"metadata": {
"name": "tg-register-webhook"
},
"spec": {
"id": "tg-register-webhook",
"nodes": [
{
"id": "trigger",
"kind": "trigger.function",
"config": {
"description": "Points the bot's Telegram webhook at this project."
},
"input_pins": [],
"output_pins": [
"out"
]
},
{
"id": "prepare",
"kind": "javascript.script.run",
"config": {
"source": "var hook = input.function; var body = { url: hook.platform.public_url + '/wh/' + hook.owner + '/' + hook.project + '/tg/' + hook.config.credential_id }; var events = hook.config.event; if (events !== undefined && events !== null && events !== '') body.allowed_updates = [].concat(events).map(String); if (ctx.placeholder && ctx.placeholder.WEBHOOK_SECRET) body.secret_token = ctx.placeholder.WEBHOOK_SECRET; return body;"
},
"input_pins": [
"in"
],
"output_pins": [
"out"
]
},
{
"id": "register",
"kind": "http.response.fetch",
"config": {
"method": "POST",
"url": "https://api.telegram.org/bot{{ $placeholder.BOT_TOKEN }}/setWebhook",
"headers": {
"Content-Type": "application/json"
},
"body": "{{ input.script }}"
},
"input_pins": [
"in"
],
"output_pins": [
"out"
]
},
{
"id": "store",
"kind": "kv.entry.put",
"config": {
"key": "telegram:webhook:{{ input.function.config.credential_id }}",
"value": "{{ input.response.body }}"
},
"input_pins": [
"in"
],
"output_pins": [
"out"
]
}
],
"edges": [
{
"from_node": "trigger",
"from_pin": "out",
"to_node": "prepare",
"to_pin": "in"
},
{
"from_node": "prepare",
"from_pin": "out",
"to_node": "register",
"to_pin": "in"
},
{
"from_node": "register",
"from_pin": "out",
"to_node": "store",
"to_pin": "in"
}
]
}
}