Skip to content
This repository has been archived by the owner. It is now read-only.

[IMP] #100

Closed
wants to merge 2 commits into from
Closed

[IMP] #100

Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -16,7 +16,7 @@
"depends": [
"base",
"web",
"base_action_rule",
"base_automation",
],
"external_dependencies": {"python": [
'telebot',
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="users_command_call_server_action" model="base.action.rule">
<record id="users_command_call_server_action" model="base.automation">
<field name="name">Telegram: Update cache for /users command</field>
<field name="model_id" ref="base.model_res_users"/>
<field name="sequence">59</field>
<field name="kind">on_create_or_write</field>
<field name="trigger">on_create_or_write</field>
<field name="server_action_ids" eval="[(6, 0, [ref('telegram.action_update_cache')])]"/>
</record>
<record id="manage_threads_on_config_update" model="base.action.rule">
<record id="manage_threads_on_config_update" model="base.automation">
<field name="name">Call server_action when ir config parameter updated</field>
<field name="model_id" ref="base.model_ir_config_parameter"/>
<field name="sequence">63</field>
<field name="kind">on_create_or_write</field>
<field name="trigger">on_create_or_write</field>
<field name="server_action_ids" eval="[(6, 0, [ref('telegram.action_manage_threads')])]"/>
</record>
</data>
@@ -101,6 +101,7 @@ def telegram_listener_message(self, messages, bot):
cr = self.env.cr
search_command = tmessage.text
m = re.match('(/[^ @]*)([^ ]*)(.*)', search_command)

if m:
# remove bot name, e.g.
# "/command@bot_name text" -> /command text
@@ -287,6 +288,7 @@ def eval_post_response(self, tsession):
def eval_notification(self, event, tsession):
self.ensure_one()
# TODO: tsession can be multi recordset
#import pdb; pdb.set_trace()

This comment has been minimized.

Copy link
@hound

hound bot Jul 6, 2019

block comment should start with '# '

return self._eval(self.notification_code,
locals_dict={'telegram': {'event': event}},
tsession=tsession)
@@ -318,7 +320,7 @@ def _update_locals_dict(self, locals_dict, tsession):
context = {}
if tsession and tsession.context:
context = simplejson.loads(tsession.context)
base_url = self.env['ir.config_parameter'].get_param('web.base.url', '')
base_url = self.sudo().env['ir.config_parameter'].get_param('web.base.url', '')
locals_dict.update({
'data': {},
'options': {
@@ -338,6 +340,7 @@ def _update_locals_dict(self, locals_dict, tsession):
@api.multi
def _eval(self, code, locals_dict=None, tsession=None):
"""Prepare data for rendering"""
#import pdb; pdb.set_trace()

This comment has been minimized.

Copy link
@hound

hound bot Jul 6, 2019

block comment should start with '# '

_logger.debug("_eval locals_dict: %s" % locals_dict)
t0 = time.time()
locals_dict = self._update_locals_dict(locals_dict, tsession)
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data>

<record id="view_telegram_command_tree" model="ir.ui.view">
@@ -82,8 +82,8 @@ Vars that can be updated:
* data - empty dictonary to be filled with any data for rendering
* options - dictonary to control processing
* options['notify_user_ids'] - list interger user ids to be notified in subscription commands (will affect only if user is subscribed). With empty list nobody receives notification. With unspecified value all subscribers receive notification.
* options['reply_markup']
* Values: types.InlineKeyboardMarkup | types.ReplyKeyboardMarkup | types.ReplyKeyboardRemove.
* options['reply_markup']
* Values: types.InlineKeyboardMarkup | types.ReplyKeyboardMarkup | types.ReplyKeyboardRemove.
* See reply_markup in https://core.telegram.org/bots/api#sendmessage
* Provides low-level access to reply_markup. It's used implicitly in:
* command.inline_keyboard_buttons, command.keyboard_buttons
@@ -96,28 +96,28 @@ Vars that can be updated:
* data
* type = "file"|"base64". Default is "base64".
* filename
* options['editMessageText'] - dictonary with identifier (message_id or inline_message_id). Allows to update existed message instead of sending new one. See https://core.telegram.org/bots/api#editmessagetext.
* options['editMessageText'] - dictonary with identifier (message_id or inline_message_id). Allows to update existed message instead of sending new one. See https://core.telegram.org/bots/api#editmessagetext.
* options['handle_reply']
* dictonary {'replies': {REPLY: DATA}, 'custom_reply': DATA}.
* If user send some value from REPLY, then this command will be called again with telegram['callback_data'] equal to corresponded DATA and and telegram['callback_data'] equal to 'reply'.
* dictonary {'replies': {REPLY: DATA}, 'custom_reply': DATA}.
* If user send some value from REPLY, then this command will be called again with telegram['callback_data'] equal to corresponded DATA and and telegram['callback_data'] equal to 'reply'.
* If custom_reply is present and user send response not from 'replies', then this command is called with telegram['callback_data'] and telegram['callback_data'] equal to 'custom_reply'
* context - dictonary to save json serializable data between user requests.

Vars that can be used:
* command - telegram.command record
* command.inline_keyboard_buttons(options, buttons, row_width=None)
* adds set of inline buttons to response. See https://core.telegram.org/bots/api#inlinekeyboardbutton.
* adds set of inline buttons to response. See https://core.telegram.org/bots/api#inlinekeyboardbutton.
* Argument buttons is a list of dictonary
* text=TEXT
* callback_data=ANY_DATA
* command.keyboard_buttons(options, buttons, row_width=None, one_time_keyboard=None, resize_keyboard=None)
* command.keyboard_buttons(options, buttons, row_width=None, one_time_keyboard=None, resize_keyboard=None)
* adds set of reply buttons to response. See https://core.telegram.org/bots/api#keyboardbutton
* one_time_keyboard and resize_keyboard make sense only for first call of the function. Also, they can be updated later via options['reply_markup'].
* Argument buttons is a list of dictonary
* text=TEXT
* callback_data=ANY_DATA
* telegram - dictonary with some input data
* telegram['tsession'] - telegram.session record.
* telegram['tsession'] - telegram.session record.
* telegram['tsession'].get_odoo_session() - the same as request.session in odoo
* telegram['tmessage'] - message from telegram. See https://core.telegram.org/bots/api#message
* telegram['tmessage'].text - actual UTF-8 text of the message
@@ -170,4 +170,4 @@ Libs that can be used:
<menuitem id="menu_telegram_command" parent="telegram.menu_telegram" name="Telegram Commands" sequence="10" action="action_telegram_command" />

</data>
</openerp>
</odoo>
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data>

<menuitem id="menu_telegram" parent="base.menu_administration" name="Telegram" sequence="100"/>

</data>
</openerp>
</odoo>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.