Conversational Component - Plugin integration and Handler extraction


#1

Hi,
I have two questions upon conversational components:

  1. Handler Extraction
  • We split code in conversational components to use the standard flow (-> delegate to the component and wait till completed). But there are always some intents which are needed on root level of the skill (and delegate to the component itself). Therefore I wrote a Class “GlobalHandler” of Type Handler and exported it. When I import it in my app.js of the skill and try to set it via app.setHandler everything works fine in local mode. But when I upload it to lambda I get the error “Handlers must be of type object”.
  • some additional information: Our skill is (momently) written in node. But the components are written in typescript. I do not understand why this error occurs. My “nodeHandler” should be of type “any” right? So the exported Handler of type “Handler” should not be a problem.
  1. Plugin integration:
  • the component above also needs a plugin. So I am trying to set it in the components constructor ( like the documentation tells us for nested components). Instead of using this.useComponent() I am using this.use() like you normally do for plugins. Is there something missing? If I export the plugin manually and add it in the app.js everthing works fine. But I would like to find a solution which is working without the need to touch more project files.

Could you give some advice?
Thanks in advance :slight_smile:
André


#2

Hey, could you provide sample code for both of the issues please?


#3

Hi @Kaan_Kilic, I can not reproduce my first question anymore. It is working now. Because the problem only occurred when not running locally I think the problem was updating the node_modules inside the bundle folder. I saw that jovo update is deleting this node_modules folder before running npm update. Did you have similar issues?

Second Question: Plugin integration
What I did was using the components constructor to register a plugin -> grafik
This did not seem to have any effect. Inside the constructor was a second strange behavior. Even if the constructor gets the “config” via a parameter config is always undefined.
I tried to solve the plugin problem by using the install method of the component itself. Because a component is a plugin itself I would not need an additional plugin when I can define my hooks there:


Now the plugin is working and I am able to access the runtime config…but i18n is not working any longer for the component. I tried to delete code step by step and as long as there is a install method inside my component the skill is not able to load the components i18n files.


#4

Hey,

What I did was using the components constructor to register a plugin. This did not seem to have any effect.

Using the install() method to add plugins is the correct approach.

I tried to delete code step by step and as long as there is a install method inside my component the skill is not able to load the components i18n files.

Yeah because you’re overwriting the base install() method without calling it inside your own one. Adding a call to super.install() should do the trick:

install(app) {
  super.install(app);
  // rest of your code
}

Inside the constructor was a second strange behavior. Even if the constructor gets the “config” via a parameter config is always undefined .

So, it’s not possible to parse the component’s config using its constructor?

new TestComponent({
  // config...
});

this doesn’t work?


#5

Hi, this worked perfectly. Thanks! The super.install(app) part solved the problems.