Warning: session_start(): open(/var/lib/php/sessions/sess_3v6qv0togln5ng0to92aj9onv7, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
concept HandoverConfig {
int handoverTimeout = 20;
}
sclass Handover {
sclass Form_DoYouWantAHuman > FormInFlight {
private *() {}
*(Conversation conversation) {
steps.add(nu FormStep(
key := "answer",
displayText := getCannedAnswer("#DoYouWantAHuman", conversation),
buttons := ll("Yes", "No")
));
}
S complete() {
if (isYes(getValue("answer")))
ret conversation.setForm(new ConnectToWorkerForm).initialMessage();
else
ret getCannedAnswer("#dontConnectMe", conversation);
}
}
sS handleHashtag(Conversation conversation, S tag) null {
if (eqic(tag, "#ConnectMeToAHuman"))
ret tryToConnect(conversation);
if (eqic(tag, "#DoYouWantAHuman")) {
conversation.setForm(new Form_DoYouWantAHuman(conversation));
ret ""; // Text comes from Q&A admin
}
}
sS tryToConnect(Conversation conversation) {
print("Handover tryToConnect");
if (workerChat.anyWorkersAvailable())
ret conversation.setForm(new ConnectToWorkerForm).initialMessage();
else
ret getCannedAnswer("#away", conversation);
}
sclass ConnectToWorkerForm > FormInFlight {
runnable class TimeoutAction { onTimeout(); }
void update(Runnable change) {
super.update(change);
if (conversation.worker != null)
onWorkerAccepts();
}
S initialMessage() {
addTimeout((double) uniq(HandoverConfig).handoverTimeout, new TimeoutAction);
workerChat.lastWorkerRequested = now(); // play special notification sound
ret getCannedAnswer("#connecting", conversation);
}
void onWorkerAccepts() {
if (conversation == null) ret; // cancelled in the meantime
print("Handover accept");
conversation.add(new Msg(getCannedAnswer("#connected", conversation), false));
conversation.cancelForm();
}
void onTimeout() {
if (conversation == null) ret; // cancelled in the meantime
print("Handover timeout");
conversation.add(new Msg(getCannedAnswer("#away", conversation), false));
conversation.cancelForm();
}
}
sS serveHandoverAdmin(S uri, SS params) {
uniq(HandoverConfig);
S nav = p(ahref(rawBotLink(dbBotID), "Main admin") + " | " + ahref(baseLink + "/handover-admin", "Handover admin"));
HCRUD_Concepts data = new HCRUD_Concepts<>(HandoverConfig);
data.fieldHelp = litmap(
handoverTimeout := "How long bot waits for an available worker (in seconds)",
);
HCRUD crud = new(rawLink("handover-admin"), data) {
S frame(S title, S contents) {
ret hhtml(hhead_title_htmldecode(title) + hbody(
hsansserif() + hcss_responstable()
+ nav + h1(title)
+ contents));
}
};
crud.allowCreateOrDelete = false;
crud.cmdsLeft = true;
crud.tableClass = "responstable";
ret crud.renderPage(params);
}
}