apanitsch
Newbie
Posts: 3
Joined: Sun Jan 24, 2016 9:56 pm

Any example of javascript inside pattern?

Fri Feb 05, 2016 8:03 pm

I can't find any example of javascript inside pattern tags beyond this one:

XML Code

<Model>
 <Pattern><Js>10 > X;</Js></Pattern>
 <Response>Yes it is!</Response>
</Model>
But I don't get it. I expected some way to declare a javascript function receiving user input as a parameter, and returning true/false to activate the model.

Thanks in advance!

User avatar
Leslie
Lead Software Architect
Posts: 353
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Any example of javascript inside pattern?

Fri Feb 05, 2016 10:01 pm

JavaScript inside pattern in SIML must only be used in Private concepts. If used in public concepts, the same Model will get activated if the JavaScript returns true keeping the chat session stuck.

If you could give us a scenario explaining what you wish to accomplish we can help you with an SIML code for it.

apanitsch
Newbie
Posts: 3
Joined: Sun Jan 24, 2016 9:56 pm

Re: Any example of javascript inside pattern?

Fri Feb 05, 2016 10:43 pm

I'm writing my very first SIML code (so please be patient :) ), a prototype for a "salesman/woman". The main goal for the bot is to engage and extract any contact info or brand mentioned by the user (taken from a predefined set).

So It's important that any email address, telephone number, etc. to be stored as a user variable in any context (I prefer false positives to missing data) to avoid asking for something already mentioned.

The leading idea to my post was to intercept all user input in a javascript function inside the pattern element, and then let the engine follow its path. I could do this outside the Syn component, but I'd like to keep the "extraction" logic contained in the SIML code.

I'm just starting with all these tools, maybe I didn't take the best approach for my scenario, so any orientation is appreciated.

User avatar
Leslie
Lead Software Architect
Posts: 353
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Any example of javascript inside pattern?

Fri Feb 05, 2016 11:31 pm

There are a number of ways to achieve that in SIML. You could use JavaScript, nested Modelling or Previous based Models.

Here is one simple example that doesn't require JavaScript and makes use of SIML's Conditional elements.

SIML Code

<Siml xmlns:Think="http://syn.co.in/2014/siml#think">
  <Concept Name="Sales">

    <Model>
      <Pattern>*</Pattern>
      <Response>
        <If User="email-new" IsEmpty="true">Please type your email address?<Label>:Email</Label></If>
        <ElseIf User="name-new" IsEmpty="true">Please type your name?<Label>:Name</Label></ElseIf>
        <Else>Can you please rephrase that for me.</Else>
      </Response>
    </Model>

    <Model>
      <Pattern>*</Pattern>
      <Previous>:Email</Previous>
      <Response>Thank you for letting me know your email address.
      <User Think:Set="email-new"><Match /></User></Response>
    </Model>

    <Model>
      <Pattern>*</Pattern>
      <Previous>:Name</Previous>
      <Response>Thank you <Match />, I will now remember your name.
      <User Think:Set="name-new"><Match /></User></Response>
    </Model>

    <Model>
      <Pattern>HI</Pattern>
      <Response>Hello there.</Response>
    </Model>

  </Concept>
</Siml>

apanitsch
Newbie
Posts: 3
Joined: Sun Jan 24, 2016 9:56 pm

Re: Any example of javascript inside pattern?

Sat Feb 06, 2016 2:57 am

That looks much more like the right path. Thanks!

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest