JILL24

JILL24

I’ve been working on a project where I’m trying to understand how Discord or Slack bots function on the backend. I know bots typically use WebSocket connections to receive real-time updates, and REST APIs to send responses or updates.

My question is: how do bots manage to update messages in real-time? For instance, when a bot edits or updates a message in a channel, it happens almost instantly like WebSockets, but traditionally, this should be happening over a REST API. Similarly, webhooks also seem to perform instant updates, but I understand they also use REST APIs.

Does anyone have insights into how these bots are architected to provide real-time functionality while still using REST APIs for responses? Is there a mechanism behind the scenes that ensures this instant update behavior? Any explanation would be appreciated!

Showing Posts 1 to 8

namxam

namxam

I never built a chat bot and I am not sure what you really ask for. REST APIs can be really fast. You have a little bit of overhead compared to a we socket connection, but they are still fast.
If you are interested in the inner workings of a chat bot, I would suggest to read the code of one of the various elixir discord / slack / … libraries.

Awlexus

Awlexus

Pretty much what has been said above. The cycle really is just “the bot receives an event through the websocket connection, and then the bot creates a new event with the REST API”.

The bot libraries can perform some tricks to reduce the overhead of the process, like keeping a persistent connection to the REST API to avoid having to establish a new connection on every request. But other than that, most of the instantaneousness comes from how their backend is able to distribute the events to the listeners

D4no0

D4no0

I am not entirely sure what the question is about, but if you are asking about websocket alternatives that are used to handle events in realtime you basically have the following options:

  1. Using HTTP long polling. The idea behind this is simple, you basically start a HTTP request to a server, leave it running and it will send a response only when new events are happening;
  2. Setting webhooks. Webhooks is the mechanism where you host your own HTTP server. The service you are using can then call your endpoints when an event happens.

PS: These are the mechanisms that are currently in-use by telegram, for the ones you mentioned it might be different.

JILL24

JILL24 OP

i am just saying, yesterday i observed a situation where i followed my other discord server announcement channel and i just post a message in announcement channel and publish it and in second server channel, i observer it reaches in real time like websocket is working but we know webhook use rest api. here i want to ask, are they using long pooling in backend or something else? and if long pooling, will it not increase the overhead?

sodapopcan

sodapopcan

As @namxam said, HTTP is quite fast. I’m also not 100% what you are asking but traditionally REST can be thought to be slower if it does things like validation and persistence before sending a response. However, there is nothing stopping it from sending a immediate response before doing that stuff. I’ve experienced this in these services where it looks like a message was sent only to be notified moments later that it failed.

JILL24

JILL24 OP

ok here is the simplfied question,
we know discord use elixir for its chat server and we know bot or webhook use rest api to send response.
now i want to ask, how bot is able to post message to channel in real time by using rest api?

LostKobrakai

LostKobrakai

The response is only one part of the question though. Using a webhook commonly means that in this case discord does a http request to an external system on certain conditions. That http request can then make that external system trigger an rest api request back to discord. The external system doesn’t need to be continously connected to discord if discord does drives the inital chain of events happening.

JILL24

JILL24 OP

do you not think when external system trigger http request in elixir, it will increase over head?

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews