Send value using Frappe Call gives AttributeError

I’m trying to send a message from a custom text-field to Telegram and I’ve been able to get the message to telegram, but I keep getting an error and not sure what I’m doing wrong:

AttributeError: module 'erpnext_telegram.erpnext_telegram.doctype.sent_messages.sent_messages' has no attribute 'send_message'

Full Traceback

Traceback (most recent call last):
  File "/home/frappe/frappe-bench-t/apps/frappe/frappe/app.py", line 60, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench-t/apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench-t/apps/frappe/frappe/handler.py", line 22, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench-t/apps/frappe/frappe/handler.py", line 50, in execute_cmd
    raise e
  File "/home/frappe/frappe-bench-t/apps/frappe/frappe/handler.py", line 47, in execute_cmd
    method = get_attr(cmd)
  File "/home/frappe/frappe-bench-t/apps/frappe/frappe/handler.py", line 205, in get_attr
    method = frappe.get_attr(cmd)
  File "/home/frappe/frappe-bench-t/apps/frappe/frappe/__init__.py", line 1029, in get_attr
    return getattr(get_module(modulename), methodname)
AttributeError: module 'erpnext_telegram.erpnext_telegram.doctype.sent_messages.sent_messages' has no attribute 'send_message'

Here’s my python

# -*- coding: utf-8 -*-
# Copyright (c) 2019, Proenterprise Ventures and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
import telegram_send

class SentMessages(Document):

	@frappe.whitelist()
	def send_message(message):
		if message:
			telegram_send.send(messages=[message])
		else:
			msg.print("Nothing to be sent")

	@frappe.whitelist()
	def set_order_message(order):
		pass

	send_message("hello from python") # send to Telegram even with the error

Here’s my custom script

frappe.ui.form.on('Sales Order', {
	validate(frm) {
		frappe.call({
            'method': 'erpnext_telegram.erpnext_telegram.doctype.sent_messages.sent_messages.send_message',
            'args': {
                message: frm.doc.message
            },
            'callback': function(r){
                //r.message
            }
        })
	}
})

You have written method inside class write out of the class.

Kindly suggest how I fix that

class SentMessages(Document):
    pass
    
@frappe.whitelist()
def send_message(message):
    if message:
        telegram_send.send(messages=[message])
    else:
        msg.print("Nothing to be sent")

@frappe.whitelist()
def set_order_message(order):
    pass

send_message("hello from python") # send to Telegram even with the error

You should try https://www.learnpython.org/

I see. The indenting is wrong here:

@frappe.whitelist()
def send_message(message):
    if message:
        telegram_send.send(messages=[message])
    else:
        msg.print("Nothing to be sent")

@frappe.whitelist()
def set_order_message(order):
    pass

send_message("hello from python") # send to Telegram even with the error

This worked. thanks alot!