Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user_data #135

Closed
RobertMhf opened this issue Mar 2, 2019 · 2 comments
Closed

user_data #135

RobertMhf opened this issue Mar 2, 2019 · 2 comments

Comments

@RobertMhf
Copy link

RobertMhf commented Mar 2, 2019

سلام. معمولا برای ذخیره متغیرهای موقتی در بات یک user_data داریم. توی مثال‌ها هم یک اسمی ازش برده شده اما اصلا مشخص نیست چطور باید باهاش کار کرد. به طور خاص فقط این مثال https://github.com/balemessenger/bale-bot-samples/blob/master/examples/document_conversation.py گفته که یک تابع get داره.

۱. اینکه غیر از call back functionها چطوری میشه به user_data‌ دسترسی داشت مشخص نیست. آیا می‌شود؟
۲. اینکه چطوری میشه توش مقداری ذخیره کرد مشخص نیست.
۳. فرض کنید من از کاربر اسمش رو پرسیدم و در پیام بعدی میخوام اسمشو بیارم. مثلا بگم: «سلام آقای فلانی». این اسم رو الان کجا باید ذخیره کنم؟ یک راه خیلی خیلی بد اینه که من خودم یک دیکشنری global user_data بذارم و کلید هر کاربر access_hash باشه و باز user_data[access_hash] بشه یک دیکشنری دیگه که حالا توی فیلد name اسم کاربر رو ذخیره کنم. و بعدش احتمالا باید mutex هم بذارم چرا که تغییر دادن یک فیلد از یک دیکشنری توی یک دیکشنری atomic نیست. راه حل بهتر این مساله ابتدایی چیه؟

متشکرم

@kiana63
Copy link

kiana63 commented Mar 2, 2019

سلام
۱. این قابلیت اینجور طراحی شده که برای هر کاربر یک update در توابع وجود داره که با متودی که dispatcher داره به صورت زیر کار میکنه :
( "dispatcher.set_conversation_data(update=update, key="mobile", value="09130000000
حالا توی هر بخش از بات که هستی میتونی با متود زیر اون رو بدست بیاری :
( "dispatcher.get_conversation_data(update, key="mobile

@GhiaC
Copy link
Collaborator

GhiaC commented Aug 18, 2019

از api جدید استفاده کنید
https://dev.bale.ai

@GhiaC GhiaC closed this as completed Aug 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants