hi heros
i am trying to use telegram bot with erpnext
i crated documnt and in in documnet controller i called the bot
its working ok
but issue there wen truing to using frappe object like (frappe.db) or (frappe.session)
i get below errors
11:06:23 web.1 | Traceback (most recent call last):
11:06:23 web.1 | File “/home/hbx/frappe-bench/env/lib/python3.6/site-packages/telegram/ext/dispatcher.py”, line 555, in process_update
11:06:23 web.1 | handler.handle_update(update, self, check, context)
11:06:23 web.1 | File “/home/hbx/frappe-bench/env/lib/python3.6/site-packages/telegram/ext/handler.py”, line 198, in handle_update
11:06:23 web.1 | return self.callback(update, context)
11:06:23 web.1 | File “/home/hbx/frappe-bench/apps/hbx/hbx/hbx_edu/doctype/hbx_edu_test/hbx_edu_test.py”, line 117, in got_contact
11:06:23 web.1 | subject = frappe.db.get_value(‘hbx_edu_telegram_user’, ‘TESTT’, ‘phone_number’)
11:06:23 web.1 | File “/home/hbx/frappe-bench/env/lib/python3.6/site-packages/werkzeug/local.py”, line 348, in getattr
11:06:23 web.1 | return getattr(self._get_current_object(), name)
11:06:23 web.1 | File “/home/hbx/frappe-bench/env/lib/python3.6/site-packages/werkzeug/local.py”, line 311, in _get_current_object
11:06:23 web.1 | raise RuntimeError(“no object bound to %s” % self.name)
11:06:23 web.1 | RuntimeError: no object bound to db
my code a below
import frappe
from frappe.model.document import Document
import telegram
from telegram import Update, ForceReply,KeyboardButton ,ReplyKeyboardMarkup ,InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
class hbx_edu_test(Document):
pass
@ frappe.whitelist()
def startbot():
# bot = telegram.Bot(token='1965958233:xxxxxxxxxxxxxxxx')
updater = Updater(token='XXX', use_context=True)
dispatcher = updater.dispatcher
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
updater.start_polling()
# print(bot.get_me())
def start(update: Update, context: CallbackContext) -> None:
"""Send a message when the command /start is issued."""
subject = frappe.db.get_value('hbx_edu_telegram_user', 'TESTT', 'phone_number')
print(subject)
user = update.effective_user
update.message.reply_markdown_v2(
fr'Hi {user.mention_markdown_v2()}\!',
reply_markup=reply_markup,
)
i think the issue that the start mathod called by bot and the session not initialized for this method
any one have idea how to let the bot methods to acess the frappe methods like frappe.db