https://github.com/zamberjo/odoo_telegram
Telegram bot integration on odoo
https://github.com/zamberjo/odoo_telegram
Last synced: 9 months ago
JSON representation
Telegram bot integration on odoo
- Host: GitHub
- URL: https://github.com/zamberjo/odoo_telegram
- Owner: zamberjo
- License: agpl-3.0
- Created: 2015-11-19T18:36:57.000Z (over 10 years ago)
- Default Branch: 8.0
- Last Pushed: 2015-11-29T12:36:08.000Z (over 10 years ago)
- Last Synced: 2025-02-01T04:04:12.032Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 72.3 KB
- Stars: 8
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#
Odoo_Telegram
##
Telegram bot integration on odoo
### Requeriments
* Install python requeriments
`pip install -r requeriments.txt`
This project uses the project [PyTelegramBotApi](https://github.com/eternnoir/pyTelegramBotAPI)
### Installation
* Edit openerp/service/__init__.py and add this code on line 10:
`import telegram`
* Copy installation/telegram folder inside openerp/service/
`openerp/service/telegram/__ini__.py`
### Usage
* Send message
```
from openerp.service.telegram import BOT
BOT.send_message(telegramUserId, 'Hello World!')
```
* For handle methods:
* Adds "telegram" package on your addon, and "handlers" module python in it.
* Example on `addons/telegram_mail
* On handlers.py file, adds this code:
```
from openerp import SUPERUSER_ID, api, sql_db
from contextlib import closing
...
class TelegramBotHandlers(object):
def __init__(self, bot):
self.bot = bot
self.uid = SUPERUSER_ID
self.context = {}
def get_cursor(self):
return sql_db.db_connect(config['db_name']).cursor()
def handle(self):
_logger.info('TelegramBotHandlers:handle -> %r' % (self.bot))
BOT = self.bot
... adds BOT handlers here ...
... for example ...
@BOT.message_handler(commands=['ping'])
def handle_ping(message):
BOT.reply_to(message, 'pong!')
... for odoo Environment ...
@BOT.message_handler(commands=['ping'])
def handle_ping(message):
with api.Environment.manage():
env = api.Environment(
self.get_cursor(), self.uid, self.context)
with closing(env.cr):
try:
ResUsers = env['res.users']
...
ResUSers.create({...})
except Exception, e:
...
else:
env.cr.commit()
```
### Configuration
* Add this lines
```
[config]
...
# TELEGRAM_BOT_APIKEY -> View BotFather
telegram_apikey = ...
# True/False (default False) - Do not stop polling when an ApiException occurs.
telegram_none_stop = ...
# True/False (default False) - The interval between polling requests
# Note: Editing this parameter harms the bot's response time
telegram_interval = ...
# True/False (default True) - Timeout in seconds for long polling.
telegram_timeout = ...
...
```
### TODO
* Security layer on telegram bot
* Module telegram
* Integration module telegram with mail.messages
* Notification state odoo server (down, up)
* Rethink everything again... hahaha :D