AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

How can I use javascript in pandorabots (playground)
 
 

Hello, i am new to aiml.

I learned aiml a few weeks ago and now i want to put javascript coding in aiml ( i saw that it is possible using javasript tags) but when i do it in pandorabots it is not working. Why? and if it is not possible to use javascript in pandorabots is there an aiml editor that can do it ?

By the way, i am using a macbook ( if that is helpful ).

Thanks alot!!
George

 

 
  [ # 1 ]

I do not believe you can use javascript in the AIML editor on Pandorabots playground.  You can call an external web service using the <sraix> tag.  You could create and host your own service and call that and the language you use to create the service functionality is up to you.  Pandorabots lets you edit the html file for the client web page for your chatbot.  You can add javascript to that file.  You can preprocess the user input using javascript before sending it as input to be processed by AIML.  You can use javascript in the html file to evaluate the AIML response and process [OOB] tags before displaying the output to the user.

What do you want to do with javascript in an AIML file? 

Using AIML you can:
1) “Reduce” / call another pattern/ call the same pattern or use recursion using the SRAI tag (~1000) times
2) Test a condition using an equals operator and branch based on it
3) Loop (100 times)

 

 

 
  [ # 2 ]

I want to make my bot do commands such as window.open(”“) of function popup and stuff like that. However I do not understand how to use the <sraix> tags you told me about. Can you show me a simple example?

 

 
  [ # 3 ]

It seems to me that Pandorabots used to allow JavaScript within the AIML itself, but that was a while ago. I don’t know if that’s still the case. I suggest trying something like this:

<category>
  <
pattern>GOOGLE *</pattern>
  <
template>
    
Here you go...
    <
script>var window.open('google.com?q=<star />');</script>
  
</template>
</
category

Not sure if it will work, but it’s at least worth a try. smile

 

 
  [ # 4 ]

I will try to see if it works, Thanks.

 

 
  [ # 5 ]

So, I tried to see if it works but this is what happened:

https://playground.pandorabots.com/en/bot/bot1/train/google.com?q=cars   

This is the link that opens up when i type google cars and it says 404 not found (obviously).

 

 
  [ # 6 ]

Then you need to change the URL to “HTTP://google.com/?q=” instead of what I had originally posted. My bad.

 

 
  [ # 7 ]

Yes!! it works. Thanks smile)

 

 
  [ # 8 ]

I want to clarify that this only works because you are talking to the bot via the Playground, which is a browser-based client for the Pandorabots API.

In Dave’s example, the actual conversation with the API looks like this:

Input: GOOGLE chatbots
Output: <script>var x = window.open(‘google.com?q=chatbots’);</script>

So this only works if you are rendering the bot response in a browser, which sees the script tags and decides to execute the contents as Javascript. This all happens after the Pandorabots API has responded. If you have a mobile client or otherwise, then you’ll need a different solution.

 

 
  [ # 9 ]
Dave Morton - Jan 29, 2016:

It seems to me that Pandorabots used to allow JavaScript within the AIML itself, but that was a while ago. I don’t know if that’s still the case. I suggest trying something like this:

<category>
  <
pattern>GOOGLE *</pattern>
  <
template>
    
Here you go...
    <
script>var window.open('google.com?q=<star />');</script>
  
</template>
</
category

Not sure if it will work, but it’s at least worth a try. smile

do you have editor supports aiml with javascript like pandorabots??

I found some it but it’s support aiml only… can you tell me please if you know??

I need that

 

 
  [ # 10 ]

Do you need a specific editor? Just add the script tags in as shown.

No, you can’t use javascript on the Pandorabots server as this would open all kinds of security issues.

 

 
  login or register to react