web-widget icon indicating copy to clipboard operation
web-widget copied to clipboard

The typing animation is working?

Open joaquin03 opened this issue 6 years ago • 17 comments

Hi! I saw there is a Typing file with the 3 dots, and the css is there.

I wonder if i can pretend that the bot is typing, i try with $bot->typesAndWaits(2), but only waits for 2 seconds, the animation is not display

I don't now if im doing something wrong or is not working for this case.

Thanks!

joaquin03 avatar Oct 17 '18 14:10 joaquin03

https://github.com/botman/botman/issues/939 - same problem

emresaracoglu avatar Dec 02 '18 12:12 emresaracoglu

Any updates ?

lakinmohapatra avatar Jan 24 '19 10:01 lakinmohapatra

@lakinmohapatra No.

emresaracoglu avatar Jan 24 '19 10:01 emresaracoglu

any update?

alokpaidalwar avatar Feb 23 '19 14:02 alokpaidalwar

I wrote jquery to do this.

Use this in chat.blade.php

setInterval(function () {
        // check if last message is by visitor. If yes, show indicator
        if($( "ol.chat li:last-child" ).attr('class') ==='visitor')
        {
            $( "ol.chat" ).append('<li class="indicator"><div class="loading-dots"><span class="dot"></span><span class="dot"></span><span class="dot"></span></div></li>');
        }
        else
        {
            // if last message is by bot and indicator is shown, then remove indicator from conversation
            if($( "ol.chat li:last-child" ).attr('class') ==='indicator' && $("ol.chat li:nth-last-child(2)").attr('class') ==='chatbot')
                $("ol.chat li .loading-dots").parent().remove();
        }
    }, 10);

Logic behind this code I thought as

  • Whatever user types in, expects respond from bot after that, right? So every message user types we have to show indicator after that.
  • class .visitor is used for message which user types in and class .chatbot is used for bot messages which is already in-built.
  • So every interval I will check that, from whom last message has been triggered. If it is visitor, then show type indicator till bot responds.
  • Once bot replies, now last message is of bot, so remove type indicator from conversation.

Hope it helps you.

chrome-capture

rohankhudedev avatar Feb 24 '19 09:02 rohankhudedev

@rohankhudedev is there a guide on how to implement your code? Thanks

ranrinc avatar Apr 09 '19 06:04 ranrinc

This will be coming in an upcoming release

danlopez00 avatar Jul 19 '19 18:07 danlopez00

Is it working now?

kevinp1005 avatar Dec 13 '19 14:12 kevinp1005

I havent checked that it is available in latest release. If not working, you can try the jquery code which i have given above.

rohankhudedev avatar Dec 14 '19 10:12 rohankhudedev

I wrote jquery to do this.

Use this in chat.blade.php

setInterval(function () {
        // check if last message is by visitor. If yes, show indicator
        if($( "ol.chat li:last-child" ).attr('class') ==='visitor')
        {
            $( "ol.chat" ).append('<li class="indicator"><div class="loading-dots"><span class="dot"></span><span class="dot"></span><span class="dot"></span></div></li>');
        }
        else
        {
            // if last message is by bot and indicator is shown, then remove indicator from conversation
            if($( "ol.chat li:last-child" ).attr('class') ==='indicator' && $("ol.chat li:nth-last-child(2)").attr('class') ==='chatbot')
                $("ol.chat li .loading-dots").parent().remove();
        }
    }, 10);

Logic behind this code I thought as

  • Whatever user types in, expects respond from bot after that, right? So every message user types we have to show indicator after that.
  • class .visitor is used for message which user types in and class .chatbot is used for bot messages which is already in-built.
  • So every interval I will check that, from whom last message has been triggered. If it is visitor, then show type indicator till bot responds.
  • Once bot replies, now last message is of bot, so remove type indicator from conversation.

Hope it helps you.

chrome-capture

Here is a version without needing jquery

setInterval(function () {
    var msg = document.querySelector('ol.chat li:last-child');
    if(msg) {
        if(msg.className  === 'visitor') {

            var node_li = document.createElement('li');
            node_li.className = 'indicator';

            var node_div = document.createElement('div');
            node_div.className = 'loading-dots';

            var node_span1 = document.createElement('span');
            var node_span2 = document.createElement('span');
            var node_span3 = document.createElement('span');
            node_span1.className = 'dot';
            node_span2.className = 'dot';
            node_span3.className = 'dot';

            node_div.appendChild(node_span1);
            node_div.appendChild(node_span2);
            node_div.appendChild(node_span3);
            node_li.appendChild(node_div);

            document.querySelector('ol.chat').appendChild(node_li);

        } else {
            var isbot = document.querySelector('ol.chat li:nth-last-child(2)');
            if(msg.className  === 'indicator' && isbot.className === 'chatbot') {
                document.querySelector('ol.chat li .loading-dots').parentNode.remove();
            }

        }

    }
}, 10);

codeplough avatar Jan 18 '20 21:01 codeplough

Thanks for the code I added a chunk of code that work for buttons as well. When a button is clicked, the typing animation pops out.

  setInterval(function () {
      // when button is clicked, change class to visitor
      $( ".btn" ).click(function(){
        $( "ol.chat li.chatbot:last-child" ).has( "div div.btn" ).removeClass("chatbot").addClass("visitor");
      });

        // check if last message is by visitor. If yes, show indicator
        if($( "ol.chat li:last-child" ).attr('class') ==='visitor')
        {
            $( "ol.chat" ).append('<li class="indicator"><div class="loading-dots"><span class="dot"></span><span class="dot"></span><span class="dot"></span></div></li>');
        }

        else
        {
            // if last message is by bot and indicator is shown, then remove indicator from conversation
            if($( "ol.chat li:last-child" ).attr('class') ==='indicator' && $("ol.chat li:nth-last-child(2)").attr('class') ==='chatbot'){
                $("ol.chat li .loading-dots").parent().remove();
              }

        }
    }, 10); ```

mathus1 avatar Mar 04 '20 12:03 mathus1

Thanks for the code I added a chunk of code that work for buttons as well. When a button is clicked, the typing animation pops out.

  setInterval(function () {
      // when button is clicked, change class to visitor
      $( ".btn" ).click(function(){
        $( "ol.chat li.chatbot:last-child" ).has( "div div.btn" ).removeClass("chatbot").addClass("visitor");
      });

        // check if last message is by visitor. If yes, show indicator
        if($( "ol.chat li:last-child" ).attr('class') ==='visitor')
        {
            $( "ol.chat" ).append('<li class="indicator"><div class="loading-dots"><span class="dot"></span><span class="dot"></span><span class="dot"></span></div></li>');
        }

        else
        {
            // if last message is by bot and indicator is shown, then remove indicator from conversation
            if($( "ol.chat li:last-child" ).attr('class') ==='indicator' && $("ol.chat li:nth-last-child(2)").attr('class') ==='chatbot'){
                $("ol.chat li .loading-dots").parent().remove();
              }

        }
    }, 10); ```

This code does not seem to work for me for buttons. I do not get any typing indicator when the user clicks a button. Any thoughts on how this could be implemented.

rvi2021 avatar Aug 13 '21 09:08 rvi2021

This code does not seem to work for me for buttons. I do not get any typing indicator when the user clicks a button. Any thoughts on how this could be implemented.

It worked well for me gif

I'm using the 2.0 version

mathus1 avatar Aug 26 '21 09:08 mathus1

I made a little modification to this script in order to set automatic scroll-down in the message area just after the dot animation (the original script fails to do that if the animation is located at the bottom of the message area). I did this change in my chat.html (framePoint) instead of chat.blade.php:

<!doctype html> 
<html>     
    <head>         
        <title>BotMan Widget</title>         
        <meta charset="UTF-8">
        <script type="text/javascript" src="jquery.min.js"></script>         
        <link rel="stylesheet" type="text/css" href="chat.css"> 
        <script>

            setInterval(function () 
            {        
                if($( "ol.chat li:last-child" ).attr('class') ==='visitor')
                {
                    $( "ol.chat" ).append('<li class="indicator"><div class="loading-dots"><span class="dot"></span><span class="dot"></span><span class="dot"></span></div></li>');
                    $("#messageArea").scrollTop($(document).height());
                }
                else
                {              
                    if($( "ol.chat li:last-child" ).attr('class') ==='indicator' && $("ol.chat li:nth-last-child(2)").attr('class') ==='chatbot') $("ol.chat li .loading-dots").parent().remove();
                }
            }, 10);
        
        </script>
    </head>     
    <body>         
        <script id="botmanWidget" src='chat.js'></script>     
    </body> 
</html>

Hope that helps someone!

nfsecurity avatar Jan 10 '23 14:01 nfsecurity

Hi!! I found the solution, maybe

use BotMan\BotMan\BotMan; use BotMan\BotMan\Interfaces\Middleware\Received; use BotMan\BotMan\Messages\Incoming\IncomingMessage;

class CustomReceivedMiddleware implements Received { /** * Handle an incoming message. * * @param IncomingMessage $message * @param callable $next * @param BotMan $bot * * @return mixed */ public function received(IncomingMessage $message, $next, BotMan $bot) { $bot->typesAndWaits(1);// HEREEEEEE return $next($message); } }

This code does not seem to work for me for buttons. I do not get any typing indicator when the user clicks a button. Any thoughts on how this could be implemented.

It worked well for me gif

I'm using the 2.0 version

Hi..

Could u pls share the entire project folder??

It would be great help..

Thanks

Siddhi

Sidvp avatar Dec 02 '23 19:12 Sidvp

I created a new package that solves this and several other issues https://www.npmjs.com/package/botman-extended-web-widget

EranGrin avatar Apr 22 '24 19:04 EranGrin