Mibew Messenger Community

General => Support => Topic started by: Bert on January 29, 2018, 03:04:09 PM

Title: cronjob to set away/offline at a certain time
Post by: Bert on January 29, 2018, 03:04:09 PM
We currently happily use Mibew on several of our websites.

To make sure we don't accidentally leave the chat Available outside business hours, I would like to add a cronjob to automatically set the chat to Away/Offline.
I'm looking for which SQL query to use.

I've already tried using...

Code: [Select]
UPDATE `operator` SET idisabled=1
...but this doesn't seem to have the intended effect.
(In fact, it somehow made it impossible for me to close the chat manually...)

Which query can I run to automatically close the chat?
Title: Re: cronjob to set away/offline at a certain time
Post by: faf on January 29, 2018, 04:52:44 PM
To mess with the system on its low level is not the best way to do the job.

However, one can take a look on this function (https://github.com/Mibew/mibew/blob/9608c5a83d711f3d57d2beadeaf9848d7287a242/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php#L147) as a starting point.
Title: Re: cronjob to set away/offline at a certain time
Post by: Bert on January 30, 2018, 08:31:20 AM
To mess with the system on its low level is not the best way to do the job.

Hm, good point.

However, one can take a look on this function (https://github.com/Mibew/mibew/blob/9608c5a83d711f3d57d2beadeaf9848d7287a242/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php#L147) as a starting point.

Are you sure that function is in use, I don't see any calls to it in the code.
I think maybe I need to use notify_operator_alive() (https://github.com/Mibew/mibew/blob/9608c5a83d711f3d57d2beadeaf9848d7287a242/src/mibew/libs/operator.php#L442)?

[Edit:]
Maybe this is a bit closer?
Code: [Select]
UPDATE operator SET istatus=1,idisabled=1,dtmlastvisited=UNIX_TIMESTAMP(NOW());
Title: Re: cronjob to set away/offline at a certain time
Post by: faf on January 30, 2018, 12:53:17 PM
However, one can take a look on this function (https://github.com/Mibew/mibew/blob/9608c5a83d711f3d57d2beadeaf9848d7287a242/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php#L147) as a starting point.

Are you sure that function is in use, I don't see any calls to it in the code.

Yes, I'm sure (https://github.com/Mibew/mibew/blob/9608c5a83d711f3d57d2beadeaf9848d7287a242/src/mibew/js/source/users/models/agent.js#L78).  ;D

It's a part of the core Client-Server interaction for the Users application. It's called during the special RPC-like interaction between the client and the server. However, it's a little bit complicated matter that can be hard to explain. If you really want to understand it you should start with the docs: https://docs.mibew.org/development/core-architecture.html

I think maybe I need to use notify_operator_alive() (https://github.com/Mibew/mibew/blob/9608c5a83d711f3d57d2beadeaf9848d7287a242/src/mibew/libs/operator.php#L442)?

Yes, probably you could write a plugin that utilizes the CRON_RUN event (https://docs.mibew.org/development/server-side-events.html#cron-events) and calls this function.

[Edit:]
Maybe this is a bit closer?
Code: [Select]
UPDATE operator SET istatus=1,idisabled=1,dtmlastvisited=UNIX_TIMESTAMP(NOW());

To begin with, you don't need idisabled. You don't have to disable an operator, just alter the status. And as it was written before, bare SQL-requests is a bad idea.
Title: Re: cronjob to set away/offline at a certain time
Post by: Bert on January 30, 2018, 02:27:37 PM
Thanks for the feedback.

In the end, I decided to go for a different approach.
I now hide the mibew button itself outside business hours.
So, during the day, they can on-/offline the button...
...and when we're closed visitors don't see the button, which means it's not an issue if an employee accidentally leaves the chat online.