Comments (7)
Sounds really awesome! I'll do it (someday)
from tgflow.
Hi, it seems that there's no need for this, you can now use ordinary time.sleep()
function and tgf.send_state()
to send a delayed notification. Check out an example: https://github.com/DaniloZZZ/tgflow/blob/master/examples/delayed.py
from tgflow.
It's not what I meant
My example implies that you can change states before the task started
It is a notification feature, so it may be more correct not to allow to change the current state
My fixed example:
def func(i, s, **d):
@tgflow.task(change_state=False) # if True then function must contain a return statement
def celery_task(i, s, **d): # some arguments
# doing something
return # "return States.SUCCESS, d" if "change_state" is True
task = celery_task()
tgflow.schedule(task, 30*60) # 30 minutes
return States.NEXT_STATE, d
from tgflow.
If you don't want to change state on notification, you can send a raw message:
A modified code from example will be:
def handle_delay(i, s, **d):
delay = int(i.text)
tgf.send_state(States.SET, i.from_user.id, data = {'delay':delay})
print("sleeping for",delay)
time.sleep(delay)
tgf.send_raw("Notification!", i.user.id)
print("done",delay)
return States.MENU, {'notification_sent':true}
from tgflow.
If you don't want to change state on notification, you can send a raw message:
A modified code from example will be:
def handle_delay(i, s, **d): delay = int(i.text) tgf.send_state(States.SET, i.from_user.id, data = {'delay':delay}) print("sleeping for",delay) time.sleep(delay) tgf.send_raw("Notification!", i.user.id) print("done",delay) return States.MENU, {'notification_sent':true}
But it will be block the thread, isn't it? and so you will not receive updates from server at that moment
from tgflow.
No, it seems that telebot is handling a connection in a separate thread. I haven't tested for other platforms, though, but telegram works ok.
from tgflow.
okey. then I close the issue.
from tgflow.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tgflow.