Hi,
I’m trying to create a Klippy extra to interface with Moonraker’s websockets through a webhook. I’ve been able to create a webhook accessible through the below URL:
http://klippy.local:7125/printer/test/webhook
and receive a reply:
{"result":{"status":{"key":"value"}}}
However, when I try to access this through the Moonraker websocket API with the following request (from Python using single-quotes, but properly JSON serialized before sending):
{
'jsonrpc': '2.0',
'method': 'printer.test.webhook',
'id': 0,
}
it errors with:
{'jsonrpc': '2.0', 'error': {'code': -32601, 'message': 'Method not found'}, 'id': 0}
Also, when I try to read the config section:
{
'jsonrpc': '2.0',
'method': 'printer.objects.query',
'params': {
'objects': {
'test_config': None,
}
},
'id': 1,
}
it returns an empty dictionary.
{'jsonrpc': '2.0', 'result': {'eventtime': 285900.34715596, 'status': {'test_config': {}}}, 'id': 1}
Below is the minimal extras file test_config.py.
class TestConfig:
def __init__(self, config):
self.printer = config.get_printer()
self.webhooks = self.printer.lookup_object('webhooks')
self.webhooks.register_endpoint('test/webhook', self.webhook_handler)
def webhook_handler(self, request):
request.send({
'status': self.get_status(0)
})
def get_status(self, eventtime):
return {
'key': 'value',
}
def load_config(config):
return TestConfig(config)
Any help would be appreciated!