Skip to content
This repository was archived by the owner on Mar 21, 2021. It is now read-only.
Open

[IMP] #101

Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: python

python:
- "2.7"
- "3.7"

sudo: false
cache: pip

Expand All @@ -13,16 +13,16 @@ addons:
- python-lxml # because pip installation is slow

env:
- VERSION="10.0" LINT_CHECK="1"
- VERSION="10.0" ODOO_REPO="odoo/odoo" LINT_CHECK="0"
- VERSION="10.0" ODOO_REPO="OCA/OCB" LINT_CHECK="0"
- VERSION="10.0" UNIT_TEST="1" LINT_CHECK="0"
- VERSION="11.0" LINT_CHECK="1"
- VERSION="11.0" ODOO_REPO="odoo/odoo" LINT_CHECK="0"
- VERSION="11.0" ODOO_REPO="OCA/OCB" LINT_CHECK="0"
- VERSION="11.0" UNIT_TEST="1" LINT_CHECK="0"

virtualenv:
system_site_packages: true

install:
- pip install anybox.testing.openerp
- pip3 install anybox.testing.openerp
- git clone https://github.com/it-projects-llc/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly
Expand Down
2 changes: 1 addition & 1 deletion telegram/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"depends": [
"base",
"web",
"base_action_rule",
"base_automation",
],
"external_dependencies": {"python": [
'telebot',
Expand Down
Binary file added telegram/__pycache__/telegram.cpython-37.pyc
Binary file not shown.
Binary file added telegram/__pycache__/telegram_bus.cpython-37.pyc
Binary file not shown.
Binary file added telegram/__pycache__/tools.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions telegram/data/base_action_rules.xml
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
5 changes: 4 additions & 1 deletion telegram/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block comment should start with '# '

return self._eval(self.notification_code,
locals_dict={'telegram': {'event': event}},
tsession=tsession)
Expand Down Expand Up @@ -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': {
Expand All @@ -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()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Expand Down
20 changes: 10 additions & 10 deletions telegram/views/telegram_command_views.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data>

<record id="view_telegram_command_tree" model="ir.ui.view">
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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>
4 changes: 2 additions & 2 deletions telegram/views/telegram_views.xml
Original file line number Diff line number Diff line change
@@ -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>