AI Zone Admin Forum Add your forum
problem regarding href tag integration
 
 

please see the image

Image Attachments
Untitled.jpg
 

 
  [ # 1 ]

Hello, Balbir, and welcome to chatbots.org.

I see from the image that you’re using AIML, but there are a LOT of different AIML interpreters out there, and they all behave a little differently, so knowing which one you’re using is important.

Also, there are some generic problems with your AIML in the first place. First is that AIML in general doesn’t handle CDATA tags very well (that is to say that most AIML interpreters don’t), so removing the CDATA tags will help considerably. Secondly, most AIML interpreters cannot parse AIML tags that lie inside attributes of other tags, such as an HTML anchor tag, which would be what you need to do to make such a link work. A workaround exists for the problem in the use of JavaScript to change the HREF attribute of the link using the onClick event, but this is cumbersome at best, and some AIML interpreters have the use of JavaScript disabled for security reasons. I know that this is probably not what you wanted to hear, but there it is.

 

 
  [ # 2 ]

Hey Dave!
I am using pandorabot and the above code snippet is copied from this website. The only change i did was to delete the tag written at the end of href link. Its of no use as it search the persona in google for obvious reason. Please tell what is the alternative of the above to solve the purpose.
Thanks

 

 
  [ # 3 ]

I’m pretty sure that Pandorabots is one of the many AIML interpreters that cannot parse AIML that lies within the attribute tag of an HTML tag, but you can certainly try, I suppose. Try the following:

<category>
    <
pattern>GOOGLE *</pattern>
    <
template>
        <
a href="http://google.com/search?q=<star/>">Google Search for <star/></a></template>
</
category

If that does not work (and I seriously doubt that it will), the next thing to try is the use of JavaScript to do the job. Now this is a two part solution, and requires some JavaScript code to be put into the HTML page of the chatbot’s interface. Here’s that JS code:

<script type="text/javascript">
    var 
search;
    function 
linkClick(link{
        
var href link.getAttribute('href');
        var 
newHref href '?q=' search;
        
location.href newHref// This opens the new link in the current tab or window
        
var newPage window.open(newHref'_blank'); this opens the new page in a new tab or window
        
return false;
    
}
</script> 

That was, of course, the first step. The second requires some changes to the AIML category I posted above:

<category>
    <
pattern>GOOGLE *</pattern>
    <
template>
        <
a href="http://google.com/search" onclick="linkClick(); return false;">Google Search for <star/></a>
        <
script>search = <star/></script>
    
</template>
</
category

What this does is print out the link as before, but with just the basic Google search URL. Then the short script tag sets the value of the JS variable ‘search’ to the value of <star>. when the user clicks the link, the function linkClick() is executed, which modifies the link’s URL to include the new query string, and then (depending on your preferences) either opens the new page in the same tab or window, or a new one. The only drawback to this is that Pandorabots may not allow the use of JavaScript on their UI pages. this is only an issue if you’re using one of their UI pages to interact with the chatbot. If you’re using a custom page, or one from a website of your own, this shouldn’t be a problem.

 

 

 

 
  [ # 4 ]

The code that i have posted works fine but the only problem is putting that variable value into search. Can we put the <star> in a variable and later use the variable in the href tag??
The first code is no use as it will just post a text message without hyperlink.
The second one uses JavaScript which looks promising as this is something i was looking for. I will give it a try and let you know.
Thanks for all the knowledge. I really appreciate it!

 

 
  [ # 5 ]
balbir bani - Apr 12, 2017:

Can we put the <star> in a variable and later use the variable in the href tag?

Sadly, not with just HTML and AIML.

balbir bani - Apr 12, 2017:

Thanks for all the knowledge. I really appreciate it!

that’s what we’re here for. smile

 

 
  [ # 6 ]
Dave Morton - Apr 12, 2017:
<script type="text/javascript">
    var 
search;
    function 
linkClick(link{
        
var href link.getAttribute('href');
        var 
newHref href '?q=' search;
        
location.href newHref// This opens the new link in the current tab or window
        
var newPage window.open(newHref'_blank'); this opens the new page in a new tab or window
        
return false;
    
}
</script> 

That was, of course, the first step. The second requires some changes to the AIML category I posted above:

<category>
    <
pattern>GOOGLE *</pattern>
    <
template>
        <
a href="http://google.com/search" onclick="linkClick(); return false;">Google Search for <star/></a>
        <
script>search = <star/></script>
    
</template>
</
category

 

This is not working for me. I am getting the reply as such.

usergoogle chatbot
bot 
: <a href="http://google.com/search">Google Search for CHATBOT</a[removed]search CHATBOT[removed] 

What am I doing wrong?

 

 
  [ # 7 ]

Do you have this installed on a page that can be seen on the internet? If so I could check it out and see what’s happening first hand. This would help me to figure out what’s going on.

 

 
  [ # 8 ]
Dave Morton - Apr 12, 2017:

I’m pretty sure that Pandorabots is one of the many AIML interpreters that cannot parse AIML that lies within the attribute tag of an HTML tag, but you can certainly try, I suppose. Try the following:

<category>
    <
pattern>GOOGLE *</pattern>
    <
template>
        <
a href="http://google.com/search?q=<star/>">Google Search for <star/></a></template>
</
category

If that does not work (and I seriously doubt that it will), the next thing to try is the use of JavaScript to do the job. Now this is a two part solution, and requires some JavaScript code to be put into the HTML page of the chatbot’s interface. Here’s that JS code:

<script type="text/javascript">
    var 
search;
    function 
linkClick(link{
        
var href link.getAttribute('href');
        var 
newHref href '?q=' search;
        
location.href newHref// This opens the new link in the current tab or window
        
var newPage window.open(newHref'_blank'); this opens the new page in a new tab or window
        
return false;
    
}
</script> 

That was, of course, the first step. The second requires some changes to the AIML category I posted above:

<category>
    <
pattern>GOOGLE *</pattern>
    <
template>
        <
a href="http://google.com/search" onclick="linkClick(); return false;">Google Search for <star/></a>
        <
script>search = <star/></script>
    
</template>
</
category

What this does is print out the link as before, but with just the basic Google search URL. Then the short script tag sets the value of the JS variable ‘search’ to the value of <star>. when the user clicks the link, the function linkClick() is executed, which modifies the link’s URL to include the new query string, and then (depending on your preferences) either opens the new page in the same tab or window, or a new one. The only drawback to this is that Pandorabots may not allow the use of JavaScript on their UI pages. this is only an issue if you’re using one of their UI pages to interact with the chatbot. If you’re using a custom page, or one from a website of your own, this shouldn’t be a problem.

 

it does not work for me too. it runs but not searching the value of<star>

 

 
  [ # 9 ]

Balbir, I’ll ask the same question of you. Is your chatbot served from a location that I could access over the Internet? If so, could you please provide the URL so that I can test it, and see what’s happening?

 

 
  [ # 10 ]

I am using pandorabot and already published it on its portal with the name “enquirybot”. You can access it by logging into pandorabot..com

 

 
  [ # 11 ]

The generic Pandorabots portal doesn’t allow for customization, so you won’t be able to add the JavaScript code that’s necessary for my solution to work. You would need to have an interface page that allows you to add the necessary JS code. Setting something like that up isn’t hard, as free web hosting is available from a number of sources, so I suggest looking into that. Program O has a jquery interface that can easily be adapted to use Pandorabots if you need a template page to use.

 

 
  [ # 12 ]

If you just want to integrate it with pandorabot, I have a workaround for you.

<aiml>
    <
category>
        <
pattern>XFIND *</pattern>
        <
template>
            <
>click and Type in your query here and let me see if I know about <star /></a>
        </
template>
    </
category>
</
aiml

 

 

 
  login or register to react