kannix
I am currently stuck with an implementation of a function that has to poll the Telegram API periodically and wait for a response from this. I guess there is some async / await magic that will help me to solve this problem in an elegant way. Maybe someone can jump in an give me a hint ![]()
Other suggestions for improvement are also very welcome ![]()
defmodule TelegramHelper do
@moduledoc """
Documentation for TelegramHelper.
"""
import Nadia
@chat_id 123456
@spec get_sms_verification_code() :: any()
def get_sms_verification_code do
# telegram api will return some old messages from time to time
# so we have to check if there are old message and get the update_id to poll later only for newer messages
update_id = 0
{:ok, result} = get_updates
if length(result) > 0 do
update_id = List.last(result).update_id + 1
end
send_message(@chat_id, "Please send the Auth Code")
get_reply(update_id)
end
defp get_reply(update_id) do
Process.sleep(1000)
{:ok, result} = get_updates(%{:update_id => update_id})
if length(result) == 0 do
# this should stop after a timeout of e.g. 5 Minutes
# and is obviously the wrong way of doing it
get_reply(update_id)
end
# this is only for reference on what i want to return if i get back a new message from telegram
List.first(result).message.text
end
end
Trending in Questions
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
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
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
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










First Post!- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
Have you considered using webhooks?
Most Liked
david_ex
I believe you should be returning a tuple from
handle_info/2:Last Post!
idi527
I don’t think you need a looping async functions … I’d do something like
Then in your browser automation program you can do
state.auth_codesshould probably be renamed tostate.awaiting_auth_codesorawaiting_chats_auth_codesomething like that. It was named incorrectly the first time since I misunderstood your problem again, it seems.