Getting started

Simple Example with CURL

First we'll generate a random key to subscribe on


Subscribe to topic


Post to the topic - In a different terminal window

curl -H 'Content-type: application/json' -d '{"hello": "world"}' \$RAMDOM_KEY
  1. Now the subscriber will get the message

Using JS event source

In javascript SSE are handled automatically with reconnects and parsing out of the box


import { v4 as uuidv4 } from 'uuid'
const RANDOM_KEY = uuidv4()
const eSource = new EventSource(`${RANDOM_KEY}`)
eSource.onmessage = (m) => {
  console.log('New Message: ', m)


We can post again from bash with curl or from js like this:

import axios from 'axios'`${RANDOM_KEY}`, { hello: 'world' })

Real world example with Telegram

Let's say we want to listen to a Telegram bot messages and respond on incoming messages

Set Telegram webhook

We call Telegram to set the webhook url to post to our topic on on any new update

curl -d {"url":"$TOPIC_ID"} \$YOUR_BOT_TOKEN/setWebhook \
    -H "Content-Type: application/json"

Handle Messages

Now we can build a simple bot that runs everywhere

const eSource = new EventSource(`${TOPIC_ID}`)
eSource.onmessage = (m) => {
  console.log('New Message: ', m)
// This will print any incoming message

Or adapt it to respond with echo message

const eSource = new EventSource(`${TOPIC_ID}`)
eSource.onmessage = (m) => {
  const msg = JSON.parse(`${telegramToken}/sendMessage`, {
    text: msg.event.message.text,
What is this