-3

I'm trying to get the implantation for auto refresh on my project which is chat bot. When the chat page is open and a conversation is loaded, I should periodically refresh the conversation entries list. By default, every 5 seconds.

  1. If there are no additional conversation entries on a refresh, we should increment the wait time by 5 seconds, up to a maximum of 120 seconds.
  2. If there are additional conversation entries on a refresh, we should reset the wait time to 5 seconds.
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

2 Answers2

0

You can use WebSocket for your chat bot. you see https://www.html5rocks.com/es/tutorials/websockets/basics/

Jorge Novo
  • 377
  • 3
  • 4
0

var delayTime = 5000;

    function refresh() {
        if(chatid.length > 0) {
        ChatService.getChatDetailsById(chatid)
            .then(function (result) {
                if (result.Data.Messages.length > $scope.chatDetails.Messages.length) {
                    getChatDetails(chatid)
                    delayTime = 5000;
                } else {
                    increseDelay();
                }
                timeout();
            });
            function increseDelay() {
                if (delayTime !== 120000)
                    delayTime += 5000;
            }
        }
    }
    function timeout() {
        setTimeout(function () {
            refresh();
        }, delayTime);
    };
    timeout();