Set launch times for my web chatbot

Configuring your webchatbot according to days and times

Start by retrieving the code needed to display the Chatbot from the platform. You will find the procedure in the following documentation: How to install my chatbot on my website

Please replace the following lines:

(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = 'https://cbassets-stage.botnation.ai/js/widget.js';
js.async = true;
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'chatbox-jssdk'));

By the lines below:

        var now = new Date();
        var isOpened = false;
        var daysOpeningHours=[{
            dayOfWeek: 1,
            openingHours: [['8:00','12:00'],['13:00','19:00']]
        }, {
            dayOfWeek: 2,
            openingHours: [['8:00','12:00'],['13:00','19:00']]
        }, {
            dayOfWeek: 3,
            openingHours: [['8:00','12:00'],['13:00','19:00']]
        }, {
            dayOfWeek: 4,
            openingHours: [['8:00','12:00'],['13:00','19:00']]
        }, {
            dayOfWeek: 5,
            openingHours: [['8:00','12:00'],['13:00','19:00']]
        }];
        var dayOpeningHoursIndex = daysOpeningHours.findIndex(d => d.dayOfWeek == now.getDay());
        if (dayOpeningHoursIndex > -1) {
           var openingHours = daysOpeningHours[dayOpeningHoursIndex].openingHours;
           for (var i=0; i < openingHours.length; i++) {
              var start = openingHours[i][0].split(':').map(n => parseInt(n));
              var end = openingHours[i][1].split(':').map(n => parseInt(n));
              if ((start[0] < now.getHours() || (start[0] == now.getHours() && start[1] < now.getMinutes()))
                 && (end[0] > now.getHours() || (end[0] == now.getHours() && end[1] > now.getMinutes()))
              ) {
                 isOpened = true;
                 break;
              }
           }
        }
        setTimeout(() => {
           if (!isOpened) return;
           (function (d, s, id) {
              var js, fjs = d.getElementsByTagName(s)[0];
              if (d.getElementById(id)) {
                 return;
              }
              js = d.createElement(s);
              js.id = id;
              js.src = 'https://cbassets-stage.botnation.ai/js/widget.js';
              js.async = true;
              fjs.parentNode.insertBefore(js, fjs);
          }(document, 'script', 'chatbox-jssdk'));
       }, 0);

Then you can set your opening hours by modifying the table named daysOpeningHours

You can add as many time slots as you wish to each day, respecting the format :

[[‘hh:mm’, ‘hh:mm’], [‘hh:mm’, ‘hh:mm’], …, [‘hh:mm’, ‘hh:mm’]]]

dayOfWeek is: 0 for Sunday, 1 for Monday, …, 6 for Saturday.

Plus:
How to install my chatbot on my website

Create your Chatbot Easily and for Free!