Telegram Integration Custom App

I am willing to develop and take this further if someone is able to support. My ideas are -

  1. Bot to create SO/PO/JOB Application/ other doctype
  2. Polling/survey integration app for erpnext
  3. Make payment using payment gateways and send payment request wth link to pay
  4. Project should have a checkbox, if selected system should create a telegram channel for every project and add the given users automatically
1 Like

Certainly there is a development plan, currently I am considering adding SMS support, where a friend suggested the idea to me and I liked it.
I am also interested in this idea, only I will need a clear vision of how it works.

Hi , I am trying to test this integration, but I get this error “ValueError: Document for field "field_order" attached to child table of "Telegram Notification" must be a dict or BaseDocument, not type 'unicode' (enabled)” when I run bench install-app erpnext_telegram_integration.

please advise. Thank you

Hi, can you provide me the version of Frappe and Erpnext you use and the full error log?

Thanks

Yeah sure. By the way, the administrative_communcations app also has the same error.

administrative_communications 0.0.1
erpnext 11.1.72
erpnext_telegram_integration 0.0.1
frappe 11.1.64

Full error trace for erpnext_telegram_integration -

HEY! USE SCREEN [frappe@ERP frappe-bench]$ bench --site main.promatics.ng install-app erpnext_telegram_integration

Installing erpnext_telegram_integration...
Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 168, in install_app
    _install_app(app, verbose=context.verbose)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 145, in install_app
    sync_for(name, force=True, sync_everything=True, verbose=verbose, reset_permissions=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py", line 56, in sync_for
    reset_permissions=reset_permissions, for_sync=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 65, in import_file_by_path
    ignore_version=ignore_version, reset_permissions=reset_permissions)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 100, in import_doc
    doc = frappe.get_doc(docdict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 734, in get_doc
    doc = frappe.model.document.get_doc(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 69, in get_doc
    return controller(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 113, in __init__
    super(Document, self).__init__(kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 54, in __init__
    self.update(d)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 77, in update
    self.set(key, value)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 124, in set
    self.extend(key, value)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 161, in extend
    self.append(key, v)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 155, in append
    self.name, str(type(value))[1:-1], value)
ValueError: Document for field "field_order" attached to child table of "Telegram Notification" must be a dict or BaseDocument, not type 'unicode' (enabled)
HEY! USE SCREEN [frappe@ERP frappe-bench]$

Full error trace for administrative_communications -

HEY! USE SCREEN -bash-4.2# su frappe
HEY! USE SCREEN [frappe@ERP root]$ cd ~/frappe-bench
HEY! USE SCREEN [frappe@ERP frappe-bench]$ bench --site main.promatics.ng install-app administrative_communications

Installing administrative_communications...
Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 168, in install_app
    _install_app(app, verbose=context.verbose)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 145, in install_app
    sync_for(name, force=True, sync_everything=True, verbose=verbose, reset_permissions=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py", line 56, in sync_for
    reset_permissions=reset_permissions, for_sync=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 65, in import_file_by_path
    ignore_version=ignore_version, reset_permissions=reset_permissions)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 100, in import_doc
    doc = frappe.get_doc(docdict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 734, in get_doc
    doc = frappe.model.document.get_doc(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 69, in get_doc
    return controller(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 113, in __init__
    super(Document, self).__init__(kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 54, in __init__
    self.update(d)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 77, in update
    self.set(key, value)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 124, in set
    self.extend(key, value)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 161, in extend
    self.append(key, v)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 155, in append
    self.name, str(type(value))[1:-1], value)
ValueError: Document for field "field_order" attached to child table of "AC Log" must be a dict or BaseDocument, not type 'unicode' (transaction_type)
HEY! USE SCREEN [frappe@ERP frappe-bench]$

Sorry, I did not test compatibility with version 11, it was tested and working with version 12 and Python 3.6 .

welp, Okay thanks

Hi, I tested with v12 and it’s been amazing. Thank you, and welldone!

1 Like

Hi, I tested this in one of my VM for v12, and it works great.
But when I wanted to install the app on my production machine which also runs version 12, I run into this error when doing bench install-app
Traceback (most recent call last):
File “/usr/lib/python3.6/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/usr/lib/python3.6/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/erpnext/bench/apps/frappe/frappe/utils/bench_helper.py”, line 97, in
main()
File “/home/erpnext/bench/apps/frappe/frappe/utils/bench_helper.py”, line 18, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/erpnext/bench/env/lib/python3.6/site-packages/click/core.py”, line 764, in call
return self.main(*args, **kwargs)
File “/home/erpnext/bench/env/lib/python3.6/site-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/home/erpnext/bench/env/lib/python3.6/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erpnext/bench/env/lib/python3.6/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erpnext/bench/env/lib/python3.6/site-packages/click/core.py”, line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/erpnext/bench/env/lib/python3.6/site-packages/click/core.py”, line 555, in invoke
return callback(*args, **kwargs)
File “/home/erpnext/bench/env/lib/python3.6/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/erpnext/bench/apps/frappe/frappe/commands/init.py”, line 25, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/erpnext/bench/apps/frappe/frappe/commands/site.py”, line 179, in install_app
_install_app(app, verbose=context.verbose)
File “/home/erpnext/bench/apps/frappe/frappe/installer.py”, line 51, in install_app
frappe.clear_cache()
File “/home/erpnext/bench/apps/frappe/frappe/init.py”, line 582, in clear_cache
frappe.cache_manager.clear_user_cache()
File “/home/erpnext/bench/apps/frappe/frappe/cache_manager.py”, line 42, in clear_user_cache
clear_global_cache()
File “/home/erpnext/bench/apps/frappe/frappe/cache_manager.py”, line 48, in clear_global_cache
clear_website_cache()
File “/home/erpnext/bench/apps/frappe/frappe/website/render.py”, line 301, in clear_cache
for method in frappe.get_hooks(“website_clear_cache”):
File “/home/erpnext/bench/apps/frappe/frappe/init.py”, line 958, in get_hooks
hooks = _dict(cache().get_value(“app_hooks”, load_app_hooks))
File “/home/erpnext/bench/apps/frappe/frappe/utils/redis_wrapper.py”, line 79, in get_value
val = generator()
File “/home/erpnext/bench/apps/frappe/frappe/init.py”, line 932, in load_app_hooks
for app in [app_name] if app_name else get_installed_apps(sort=True):
File “/home/erpnext/bench/apps/frappe/frappe/init.py”, line 896, in get_installed_apps
installed = json.loads(db.get_global(“installed_apps”) or “[]”)
File “/home/erpnext/bench/apps/frappe/frappe/database/database.py”, line 702, in get_global
return self.get_default(key, user)
File “/home/erpnext/bench/apps/frappe/frappe/database/database.py”, line 706, in get_default
d = self.get_defaults(key, parent)
File “/home/erpnext/bench/apps/frappe/frappe/database/database.py”, line 724, in get_defaults
defaults = frappe.defaults.get_defaults(parent)
File “/home/erpnext/bench/apps/frappe/frappe/defaults.py”, line 77, in get_defaults
globald = get_defaults_for()
File “/home/erpnext/bench/apps/frappe/frappe/defaults.py”, line 204, in get_defaults_for
where parent = %s order by creation"“”, (parent,), as_dict=1)
File “/home/erpnext/bench/apps/frappe/frappe/database/database.py”, line 122, in sql
self.connect()
File “/home/erpnext/bench/apps/frappe/frappe/database/database.py”, line 75, in connect
self._conn = self.get_connection()
File “/home/erpnext/bench/apps/frappe/frappe/database/mariadb/database.py”, line 90, in get_connection
local_infile = frappe.conf.local_infile)
File “/home/erpnext/bench/env/lib/python3.6/site-packages/pymysql/init.py”, line 94, in Connect
return Connection(*args, **kwargs)
File “/home/erpnext/bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 325, in init
self.connect()
File “/home/erpnext/bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 599, in connect
self._request_authentication()
File “/home/erpnext/bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 861, in _request_authentication
auth_packet = self._read_packet()
File “/home/erpnext/bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 684, in _read_packet
packet.check_error()
File “/home/erpnext/bench/env/lib/python3.6/site-packages/pymysql/protocol.py”, line 220, in check_error
err.raise_mysql_exception(self._data)
File “/home/erpnext/bench/env/lib/python3.6/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, “Access denied for user ‘erpnext’@‘localhost’ (using password: NO)”)

Any idea how I can resolve this?

I have found the solution to my problem and would like to post it here for the community.

If you’re running your instance with the DSN Multitenant On, you will have to specify the site when installing this app. Use this command:

bench --site mysite.com install-app erpnext_telegram_integration

Thanks for the awesome work.

1 Like

I’m loving this app so much. Thank you for putting the time and effort into making this possible.

There is one thing I notice so far: html tags do not work in the message. Is this the default behaviour?

Again, thanks for the awesome work.

Thank you for trying the app, and I am glad that you like it.
I have made the app to support the basic features of the Telegram, then I added SMS alerts and date alerts to it.

@youssef huv generated telegram token but while getting chart id not able to generate id shows " telegram.error.TimedOut: Timed out" .

@arokia have you create a Telegram bot from BotFather ?

@youssef yep created in android telegram and got access API also while clicking get chart id am getting timed out error.

And have you copied telegram token in your bot?

@youssef yep copied token and have followed all your above steps under In Erpnext Telegram Integration section stuck in 7th point.

Hi, it’s me again. :slight_smile:

I just noticed that only ONE condition is allowed in the Condition filed.
For example:
doc.status==“Overdue”
doc.total > 2000
would be thrown error.

Is there any solution to that?

I cannot find the problem without additional information

you can do it with “and”, " or" like this:

doc.status==“Overdue” and doc.total > 2000