assistant-conversation-nodejs
assistant-conversation-nodejs copied to clipboard
Self Hosted Restify Server
Hi,
I'm trying to use the @assistant/conversation in restify, But I get this error:
(node:17) UnhandledPromiseRejectionWarning: Error: Handler not found for handle name: at Function.handler (/app/node_modules/@assistant/conversation/dist/conversation/conversation.js:109:23) at Function.standard [as handler] (/app/node_modules/@assistant/conversation/dist/assistant.js:49:32) at omni (/app/node_modules/@assistant/conversation/dist/assistant.js:41:20) at nextTick (/app/node_modules/restify/lib/chain.js:167:13) at process._tickCallback (internal/process/next_tick.js:61:11) (node:17) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:17) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Example:
// Import the appropriate service and chosen wrappers
const {
conversation,
Image,
Card
} = require('@assistant/conversation');
// Create an app instance
const app = conversation({ });
app.handle('greeting', conv => {
conv.add('Hi, how is it going?')
conv.add(new Image({
url: 'https://developers.google.com/web/fundamentals/accessibility/semantics-builtin/imgs/160204193356-01-cat-500.jpg',
alt: 'A cat',
}));
});
// ... restify code
server.post('/assistant', app);
I use the restify bodyParser
server.use(restify.plugins.bodyParser({ maxBodySize: 1000000 }));
Look like some JSON parser problem. JSON parse on body by restify:
{"handler":{"name":"greeting"},"intent":{"name":"YES","params":{},"query":"Sim"},"scene":{"name":"Start","slotFillingStatus":"UNSPECIFIED","slots":{},"next":{"name":"actions.scene.END_CONVERSATION"}},"session":{"id":"ABwppHHi7JYqhUAqDyFt63dcPtQ0or_Lx4ILhgWqoscrfrX74j2aECq4yHVPlPbloQ_uidDNS4swocEGjsletXOAt5E_RA7Z","params":{},"typeOverrides":[],"languageCode":""},"user":{"locale":"pt-BR","params":{},"accountLinkingStatus":"ACCOUNT_LINKING_STATUS_UNSPECIFIED","verificationStatus":"VERIFIED","packageEntitlements":[],"lastSeenTime":"2020-10-08T09:32:08Z"},"home":{"params":{}},"device":{"capabilities":["SPEECH","RICH_RESPONSE","LONG_FORM_AUDIO"]}}
console.log(`HANDLER NAME: ${req.body.handler.name}`);
HANDLER NAME: greeting
Without '@assistant/conversation' works fine: Example:
server.post('/assistant', (req, res, next) => {
res.json({
"session": {
"id": "example_session_id",
"params": {}
},
"prompt": {
"override": false,
"content": {
"card": {
"title": "Card Title",
"subtitle": "Card Subtitle",
"text": "Card Content",
"image": {
"alt": "Google Assistant logo",
"height": 0,
"url": "https://developers.google.com/assistant/assistant_96.png",
"width": 0
}
}
},
"firstSimple": {
"speech": "This is a card rich response.",
"text": ""
}
}
}
);
return next();
});