Hi,
yes - my application with Telegram works fine.
It is simple to send messages to a single person or not more than one
person at a time. But if you want to offer a dialog, concurrent for several
persons, the things become complicated.
My solution:
I have two tables:
This table translates between Web2py user-ids and Telegram user-ids
("chat-id")
db.define_table("tg_user",
Field("user_id", "reference auth_user"),
Field("chat_id", "integer"),
)
The second one stores every incoming message and every outgoing message.
tg_data and extra are "pickled" dictionaries. extra contains a field
"step": step is like a state number in a state diagram. Using step and the
content of an answer the program decides which step should be the next.
db.define_table("tg_cache",
Field("chat_id", "integer"),
Field("now", "datetime", default=request.now),
Field("tg_data", "text"),
Field("extra", "text"),
)
Hope it helps.
It would be a nice project to write a web2py component how to use Telegram.
Maybe I will start it.
Regards, Martin
2016-06-28 17:17 GMT+02:00 Gael Princivalle <[email protected]>:
> Hello.
>
> Do you have got success with the Telegram integration ?
> Can you post the URL where is it ?
>
> Il giorno sabato 12 settembre 2015 17:54:39 UTC+2, mweissen ha scritto:
>>
>> Thx! I put a variable in db.py, use it as a global variable and save the
>> content as json field for the next round.
>>
>> 2015-09-11 16:30 GMT+02:00 Anthony <[email protected]>:
>>
>>> The problem with relying on old session files is that it then becomes
>>> complicated to clean them up, because you don't know how long you need to
>>> keep them. Another option might be to store the data in the database in
>>> between sessions (much like the way the Auth user record is persisted in
>>> the database but then copied to the session upon login). Depending on the
>>> structure of the data, you could store it in a JSON field or in a custom
>>> field using pickle.
>>>
>>> Anthony
>>>
>>>
>>> On Friday, September 11, 2015 at 10:04:40 AM UTC-4, mweissen wrote:
>>>>
>>>> I need to restore a session without using cookies: the messenger from
>>>> telegram.org offers an interesting API to create a message bot. It's
>>>> very simple to send and to receive a single message. But if I want to
>>>> create a dialog with severals questions and answers I have I problem: I
>>>> need to save my actual session during the first conversion and during the
>>>> next round I want to reuse this session.
>>>>
>>>> One idea: I store the session_filename with something like
>>>>
>>>> cache.disk(telegram_user_id, lambda: response.session_filename)
>>>>
>>>> and during the next round I can restore the session with
>>>>
>>>> filename=cache.disk(telegram_user_id, lambda: response.session_filename)
>>>> session=pickle.load(open(filename,'rb'))
>>>>
>>>>
>>>> *My questions:*
>>>>
>>>> 1. Is it sufficient to restore the session variable in this way or are
>>>> there any side effects?
>>>> 2. There are two disk accesses (one for the cache.disk, one for the
>>>> open(filename)). It's not possible to use cache.ram because web2py is
>>>> running on a virtual server. Is there any better solution?
>>>> 3. The real filename is longer, like
>>>> ...app/sessions/*012/abc*/127.0.0.1-...,
>>>> but response.file_name shows only the main part
>>>> ...app/sessions/127.0.0.1-... How to get the whole filename?
>>>> 4. Is it possible and is it a better solution to store the whole
>>>> session-variable in cache.disk?
>>>>
>>>> Regards, Martin
>>>>
>>> --
>>> Resources:
>>> - http://web2py.com
>>> - http://web2py.com/book (Documentation)
>>> - http://github.com/web2py/web2py (Source code)
>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "web2py-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.