To connect to Tweet Catcher servers you must submit a valid user token, you can get your token on the dashboard , by creating a task and selecting "WebSocket" as option
Copy [Client]
Establish connection to ws://monitor-api.tweet-catcher.com:42069
[Tweet Catcher] Hello event
{ op: 10, heartbeat_interval: 45000 }
[Client] Heartbeat event
{ op: 1 }
[Tweet Catcher] Heartbeat ACK event
{ op: 11 }
[Client] Login
{ op: 2, token: "YOUR_TOKEN" }
[Tweet Catcher] Disconnection event(s)
{ op: 3, text: "REASON_OF_DISCONNECTION" }
[Tweet Catcher] Ready event
{ op: 4 }
[Tweet Catcher] Monitor event(s)
{
op: 0,
d: {
task: {
user: "",
userInfo: ""
reason: "new_tweet", // "new_tweet", "new_following", "user_update"
},
data: {
[tweet data]
}
}
}
Simple JavaScript implementation example
Copy const WebSocket = require("ws")
const loginToken = "YOUR_TOKEN"
let heartbeatInt = null
const ws = new WebSocket("ws://monitor-api.tweet-catcher.com:42069")
ws.on('error', console.error)
ws.on('close', async (code) => {
console.warn("Websocket connection closed with code:", code)
clearInterval(heartbeatInt)
/* Your reconnection logic */
})
ws.on('message', (data) => {
try
{
const objData = JSON.parse(data)
// console.log(objData)
switch (objData.op)
{
case 0: // New Notification
console.log("New notification", objData.d)
break
case 3: // Connection status updates
console.warn("Server connection closed with message:", objData.text)
break
case 4: // Ready event
console.log("Logged in!")
break
case 10: // Init heartbeat
ws.send(JSON.stringify({ op: 2, token: loginToken })) // Login
heartbeatInt = setInterval(() => {
try
{ ws.send('{"op":1}') }
catch (e)
{ console.error("Failed to send hearthbeat", e) }
}, objData.heartbeat_interval)
break
}
}
catch (e)
{
console.error("Error on ws on message:", e)
}
})