Rasa-webchat - Problem with link uttered

Hello everyone,

I’m trying to utter a link to the chat with the javascript action. The javascript works, but only without the attribute “target” if I remove this attribute it works as expected.

I’m working with botfront/rasa-webchat.

I utter the response from action server with the code below:

dispatcher.utter_message(

f"Informações encontradas:\n \n{response[0]['text']} \n \n"

f"Para mais detalhes acesse:\n{response[0]['link']}"

)

The uttering above results on this message at webchat:

Inspecting the element, this is the source and here is the evil “target”:

<a href="javascript:Ext.apdata.funcs[4]().show()" target="_blank" rel="noopener noreferrer">teste</a>

I just need to utter a clickable text with some javascript on it, doesn’t have to be a link, any suggestion/option is welcome.

Att.

Luchini

No one?

@erohmensing @Juste

:disappointed_relieved:

Hey @lluchini I think this is more of a question for the botfront team, maybe you can open an issue there?

@akelad

I know, but I was hoping someone here already done it. But I was debugging the Botfront and it seems a bug, there’s a feature to react that when the URL starts with “javascript” or “docviewer” it already removes the target attribute, for the normal web interface the target is fixed.

I’m forking the repo now to confirm it (I was debugging the minified source) and as I confirm it I’ll adjust and send a PR.

So, if you could please keep this open so I can update for future use I appreciate it.

Thanks!

Hello @akelad,

I was able to make it work but was a team effort, I had to adjust Botfront for RASA as the SocketChannel from rasa, I’m gonna explain and as you if I should do a PR to RASA about it.

At Botfront, it had implemented some treatment to deal with target when the URL starts with “mailto” or “javascript”, but it wasn’t very well implemented, so I made some fixes, the link to PR is below:

fix: The quick replies weren’t able to deal with other targets than “_blank” #231

At RASA Socketchannel.py I had to add some treatment to quick replies because they can be of two types, the default with a payload or the type “web_url” which carry a URL instead Payload, the channel was ready to deal only the default type (with payload), below I show the changes. Let me know if I should open a PR to it.

Before:

    for button in buttons:
        messages[-1]["quick_replies"].append(
            {
                "content_type": "text",
                "title": button["title"],
                "payload": button["payload"],
            }
        )

After:

    for button in buttons:
        b = {
                "content_type": "text",
                "title": button["title"]
        }

        if "type" in button:
            b["type"] = button["type"]

        if "payload" in button:
            b["payload"] = button["payload"]

        if "url" in button:
            b["url"] = button["url"]

        messages[-1]["quick_replies"].append(b)

Thanks.