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!
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 8- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
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
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
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:
PS: These are the mechanisms that are currently in-use by telegram, for the ones you mentioned it might be different.
JILL24
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
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
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
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
do you not think when external system trigger http request in elixir, it will increase over head?