1 | concept HandoverConfig {
|
2 | int handoverTimeout = 20; |
3 | } |
4 | |
5 | sclass Handover {
|
6 | sclass Form_DoYouWantAHuman > FormInFlight {
|
7 | private *() {}
|
8 | *(Conversation conversation) {
|
9 | steps.add(nu FormStep( |
10 | key := "answer", |
11 | displayText := getCannedAnswer("#DoYouWantAHuman", conversation),
|
12 | placeholder := "", |
13 | buttons := ll("Yes", "No")
|
14 | )); |
15 | } |
16 | |
17 | S complete() {
|
18 | if (isYes(getValue("answer")))
|
19 | ret conversation.setForm(new ConnectToWorkerForm).initialMessage(); |
20 | else |
21 | ret getCannedAnswer("#dontConnectMe", conversation);
|
22 | } |
23 | |
24 | bool allowGeneralOverride() { true; }
|
25 | } |
26 | |
27 | sS handleHashtag(Conversation conv, S tag) null {
|
28 | if (eqic(tag, "#ConnectMeToAHuman")) |
29 | ret tryToConnect(conv); |
30 | |
31 | if (eqic(tag, "#DoYouWantAHuman")) {
|
32 | if (conv.form instanceof ConnectToWorkerForm) |
33 | ret getCannedAnswer("#stillConnecting", conv);
|
34 | |
35 | conv.setForm(new Form_DoYouWantAHuman(conv)); |
36 | ret ""; // Text comes from Q&A admin |
37 | } |
38 | } |
39 | |
40 | sS tryToConnect(Conversation conversation) {
|
41 | print("Handover tryToConnect");
|
42 | if (workerChat.anyWorkersAvailable()) |
43 | ret conversation.setForm(new ConnectToWorkerForm).initialMessage(); |
44 | else |
45 | ret getCannedAnswer("#away", conversation);
|
46 | } |
47 | |
48 | sclass ConnectToWorkerForm > FormInFlight {
|
49 | runnable class TimeoutAction { onTimeout(); }
|
50 | |
51 | void update(Runnable change) {
|
52 | super.update(change); |
53 | if (conversation.worker != null) |
54 | onWorkerAccepts(); |
55 | } |
56 | |
57 | S initialMessage() {
|
58 | addTimeout((double) uniq(HandoverConfig).handoverTimeout, new TimeoutAction); |
59 | workerChat.lastWorkerRequested = now(); // play special notification sound |
60 | ret getCannedAnswer("#connecting", conversation);
|
61 | } |
62 | |
63 | void onWorkerAccepts() {
|
64 | if (conversation == null) ret; // cancelled in the meantime |
65 | print("Handover accept");
|
66 | conversation.add(new Msg(getCannedAnswer("#connected", conversation), false));
|
67 | conversation.cancelForm(); |
68 | } |
69 | |
70 | void onTimeout() {
|
71 | if (conversation == null) ret; // cancelled in the meantime |
72 | print("Handover timeout");
|
73 | conversation.add(new Msg(getCannedAnswer("#away", conversation), false));
|
74 | conversation.cancelForm(); |
75 | } |
76 | } |
77 | |
78 | sO html(S uri, SS params, AuthedDialogID auth) null {
|
79 | S uri2 = appendSlash(uri); |
80 | bool requestAuthed = auth != null; |
81 | |
82 | if (startsWith(uri2, "/handover-admin/")) {
|
83 | if (!requestAuthed) ret serveAuthForm(params.get('uri));
|
84 | ret serveHandoverAdmin(uri, params); |
85 | } |
86 | } |
87 | |
88 | sS serveHandoverAdmin(S uri, SS params) {
|
89 | uniq(HandoverConfig); |
90 | |
91 | S _nav = p(ahref(rawBotLink(dbBotID), "Main admin") + " | " + ahref(baseLink + "/handover-admin", "Handover admin")); |
92 | |
93 | HCRUD_Concepts<HandoverConfig> data = new HCRUD_Concepts<>(HandoverConfig); |
94 | data.fieldHelp = litmap( |
95 | handoverTimeout := "How long bot waits for an available worker (in seconds)", |
96 | ); |
97 | |
98 | HCRUD crud = new(rawLink("handover-admin"), data) {
|
99 | S frame(S title, S contents) {
|
100 | ret hhtml(hhead_title_htmldecode(title) + hbody( |
101 | hsansserif() + hcss_responstable() |
102 | + _nav + h1(title) |
103 | + contents)); |
104 | } |
105 | }; |
106 | crud.singleton = true; |
107 | crud.cmdsLeft = true; |
108 | crud.tableClass = "responstable"; |
109 | ret crud.renderPage(params); |
110 | } |
111 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1028517 |
| Snippet name: | Handover [have web chat bot switch to sales rep, Include] |
| Eternal ID of this version: | #1028517/37 |
| Text MD5: | 2936d80e8c35df876df8a501485a817b |
| Author: | stefan |
| Category: | javax / web chat bot |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-10-24 12:07:40 |
| Source code size: | 3501 bytes / 111 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 527 / 771 |
| Version history: | 36 change(s) |
| Referenced in: | [show references] |