@frogbotai/piece-telegram-bot 0.28.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/index.d.ts +5 -5
- package/dist/actions/index.js +165 -91
- package/dist/actions/index.js.map +1 -1
- package/dist/adapter.js +10 -9
- package/dist/adapter.js.map +1 -1
- package/dist/client.js +36 -26
- package/dist/client.js.map +1 -1
- package/dist/config.js +15 -10
- package/dist/config.js.map +1 -1
- package/dist/define.js +1 -0
- package/dist/define.js.map +1 -1
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +23 -18
- package/dist/files.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +20 -12
- package/dist/index.js.map +1 -1
- package/dist/questions/index.js +2 -1
- package/dist/questions/index.js.map +1 -1
- package/dist/questions/keyboard.js +132 -76
- package/dist/questions/keyboard.js.map +1 -1
- package/dist/questions/notify.js +38 -23
- package/dist/questions/notify.js.map +1 -1
- package/dist/questions/parse.js +128 -53
- package/dist/questions/parse.js.map +1 -1
- package/dist/questions/render.js +21 -5
- package/dist/questions/render.js.map +1 -1
- package/dist/questions/settled.js +30 -9
- package/dist/questions/settled.js.map +1 -1
- package/dist/questions/state.js +10 -8
- package/dist/questions/state.js.map +1 -1
- package/dist/questions/supports.js +2 -1
- package/dist/questions/supports.js.map +1 -1
- package/dist/questions/telegramThread.js +11 -7
- package/dist/questions/telegramThread.js.map +1 -1
- package/dist/questions/updated.js +19 -14
- package/dist/questions/updated.js.map +1 -1
- package/dist/triggers/newUpdate.d.ts +2 -2
- package/dist/triggers/newUpdate.js +35 -21
- package/dist/triggers/newUpdate.js.map +1 -1
- package/dist/webhook.js +8 -7
- package/dist/webhook.js.map +1 -1
- package/package.json +4 -4
package/dist/questions/parse.js
CHANGED
|
@@ -1,87 +1,162 @@
|
|
|
1
1
|
import { decodeAction, optionPages, selectedLabels } from './keyboard.js';
|
|
2
2
|
import { readState } from './state.js';
|
|
3
|
-
const IGNORE = {
|
|
4
|
-
|
|
3
|
+
const IGNORE = {
|
|
4
|
+
kind: 'ignore'
|
|
5
|
+
};
|
|
6
|
+
export const parseTelegramQuestion = ({ call, interaction, question, settled })=>{
|
|
5
7
|
const state = readState(question.state);
|
|
6
8
|
if (interaction.type === 'action') {
|
|
7
|
-
return parseAction({
|
|
9
|
+
return parseAction({
|
|
10
|
+
call,
|
|
11
|
+
data: interaction.event.actionId,
|
|
12
|
+
state
|
|
13
|
+
});
|
|
8
14
|
}
|
|
9
15
|
if (interaction.type === 'message' && !settled) {
|
|
10
|
-
return parseReply({
|
|
16
|
+
return parseReply({
|
|
17
|
+
call,
|
|
18
|
+
message: interaction.message,
|
|
19
|
+
question,
|
|
20
|
+
state
|
|
21
|
+
});
|
|
11
22
|
}
|
|
12
23
|
return IGNORE;
|
|
13
24
|
};
|
|
14
|
-
function parseAction({ call, data, state
|
|
25
|
+
function parseAction({ call, data, state }) {
|
|
15
26
|
const action = decodeAction(data);
|
|
16
|
-
if (!action)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (action.q !== state.q)
|
|
21
|
-
|
|
27
|
+
if (!action) return IGNORE;
|
|
28
|
+
if (action.kind === 'dismiss') return {
|
|
29
|
+
kind: 'dismiss'
|
|
30
|
+
};
|
|
31
|
+
if (action.q !== state.q) return {
|
|
32
|
+
kind: 'stale'
|
|
33
|
+
};
|
|
22
34
|
const item = call.input.questions[state.q];
|
|
23
|
-
if (!item)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
case '
|
|
41
|
-
|
|
42
|
-
return IGNORE;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
if (!item) return IGNORE;
|
|
36
|
+
switch(action.kind){
|
|
37
|
+
case 'choose':
|
|
38
|
+
{
|
|
39
|
+
const option = item.options[action.index];
|
|
40
|
+
if (item.multiple || !option) return IGNORE;
|
|
41
|
+
return advance({
|
|
42
|
+
call,
|
|
43
|
+
state,
|
|
44
|
+
answer: {
|
|
45
|
+
header: item.header,
|
|
46
|
+
selected: [
|
|
47
|
+
option.label
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
case 'toggle':
|
|
53
|
+
{
|
|
54
|
+
if (!item.multiple || !item.options[action.index]) return IGNORE;
|
|
55
|
+
const selected = state.selected.includes(action.index) ? state.selected.filter((index)=>index !== action.index) : [
|
|
56
|
+
...state.selected,
|
|
57
|
+
action.index
|
|
58
|
+
].sort((a, b)=>a - b);
|
|
59
|
+
return {
|
|
60
|
+
kind: 'partial',
|
|
61
|
+
state: {
|
|
62
|
+
...state,
|
|
63
|
+
selected
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
case 'done':
|
|
68
|
+
{
|
|
69
|
+
if (!item.multiple) return IGNORE;
|
|
70
|
+
const selected = selectedLabels({
|
|
71
|
+
item,
|
|
72
|
+
selected: state.selected
|
|
73
|
+
});
|
|
74
|
+
if (selected.length === 0) {
|
|
75
|
+
return {
|
|
76
|
+
kind: 'rejected',
|
|
77
|
+
reason: 'Select at least one option, then tap Done.'
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return advance({
|
|
81
|
+
call,
|
|
82
|
+
state,
|
|
83
|
+
answer: {
|
|
84
|
+
header: item.header,
|
|
85
|
+
selected
|
|
86
|
+
}
|
|
87
|
+
});
|
|
46
88
|
}
|
|
47
|
-
return advance({ call, state, answer: { header: item.header, selected } });
|
|
48
|
-
}
|
|
49
89
|
case 'type':
|
|
50
|
-
return item.custom ? {
|
|
90
|
+
return item.custom ? {
|
|
91
|
+
kind: 'partial',
|
|
92
|
+
state: {
|
|
93
|
+
...state,
|
|
94
|
+
typing: true
|
|
95
|
+
}
|
|
96
|
+
} : IGNORE;
|
|
51
97
|
case 'back':
|
|
52
|
-
return {
|
|
98
|
+
return {
|
|
99
|
+
kind: 'partial',
|
|
100
|
+
state: {
|
|
101
|
+
...state,
|
|
102
|
+
typing: false
|
|
103
|
+
}
|
|
104
|
+
};
|
|
53
105
|
case 'page':
|
|
54
|
-
return action.page < optionPages(item).length
|
|
55
|
-
|
|
56
|
-
:
|
|
106
|
+
return action.page < optionPages(item).length ? {
|
|
107
|
+
kind: 'partial',
|
|
108
|
+
state: {
|
|
109
|
+
...state,
|
|
110
|
+
page: action.page
|
|
111
|
+
}
|
|
112
|
+
} : IGNORE;
|
|
57
113
|
}
|
|
58
114
|
}
|
|
59
|
-
function parseReply({ call, message, question, state
|
|
115
|
+
function parseReply({ call, message, question, state }) {
|
|
60
116
|
const item = call.input.questions[state.q];
|
|
61
117
|
const bound = message.replyTo?.id === question.messages.at(-1)?.id;
|
|
62
|
-
if (!item?.custom || !state.typing || !bound)
|
|
63
|
-
return IGNORE;
|
|
118
|
+
if (!item?.custom || !state.typing || !bound) return IGNORE;
|
|
64
119
|
const custom = message.text.trim();
|
|
65
|
-
if (!custom)
|
|
66
|
-
|
|
120
|
+
if (!custom) return {
|
|
121
|
+
kind: 'rejected',
|
|
122
|
+
reason: 'Reply with your answer as text.'
|
|
123
|
+
};
|
|
67
124
|
return advance({
|
|
68
125
|
call,
|
|
69
126
|
state,
|
|
70
127
|
answer: {
|
|
71
128
|
header: item.header,
|
|
72
|
-
selected: item.multiple ? selectedLabels({
|
|
73
|
-
|
|
74
|
-
|
|
129
|
+
selected: item.multiple ? selectedLabels({
|
|
130
|
+
item,
|
|
131
|
+
selected: state.selected
|
|
132
|
+
}) : [],
|
|
133
|
+
custom
|
|
134
|
+
}
|
|
75
135
|
});
|
|
76
136
|
}
|
|
77
|
-
function advance({ answer, call, state
|
|
78
|
-
const answers = [
|
|
137
|
+
function advance({ answer, call, state }) {
|
|
138
|
+
const answers = [
|
|
139
|
+
...state.answers.slice(0, state.q),
|
|
140
|
+
answer
|
|
141
|
+
];
|
|
79
142
|
if (answers.length === call.input.questions.length) {
|
|
80
|
-
return {
|
|
143
|
+
return {
|
|
144
|
+
kind: 'answer',
|
|
145
|
+
output: {
|
|
146
|
+
answers
|
|
147
|
+
}
|
|
148
|
+
};
|
|
81
149
|
}
|
|
82
150
|
return {
|
|
83
151
|
kind: 'partial',
|
|
84
|
-
state: {
|
|
152
|
+
state: {
|
|
153
|
+
q: state.q + 1,
|
|
154
|
+
page: 0,
|
|
155
|
+
answers,
|
|
156
|
+
selected: [],
|
|
157
|
+
typing: false
|
|
158
|
+
}
|
|
85
159
|
};
|
|
86
160
|
}
|
|
161
|
+
|
|
87
162
|
//# sourceMappingURL=parse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/questions/parse.ts"],"names":["decodeAction","optionPages","selectedLabels","readState","IGNORE","kind","parseTelegramQuestion","call","interaction","question","settled","state","type","parseAction","data","event","actionId","parseReply","message","action","q","item","input","questions","option","options","index","multiple","advance","answer","header","selected","label","includes","filter","sort","a","b","length","reason","custom","typing","page","bound","replyTo","id","messages","at","text","trim","answers","slice","output"],"mappings":"AAQA,SAASA,YAAY,EAAEC,WAAW,EAAEC,cAAc,QAAQ,gBAAgB;AAE1E,SAASC,SAAS,QAAQ,aAAa;AAIvC,MAAMC,SAA8B;IAAEC,MAAM;AAAS;AAErD,OAAO,MAAMC,wBAAwD,CAAC,EACpEC,IAAI,EACJC,WAAW,EACXC,QAAQ,EACRC,OAAO,EACR;IACC,MAAMC,QAAQR,UAAUM,SAASE,KAAK;IAEtC,IAAIH,YAAYI,IAAI,KAAK,UAAU;QACjC,OAAOC,YAAY;YAAEN;YAAMO,MAAMN,YAAYO,KAAK,CAACC,QAAQ;YAAEL;QAAM;IACrE;IAEA,IAAIH,YAAYI,IAAI,KAAK,aAAa,CAACF,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AO;QAAEnC,MAAM;QAAYkC,QAAQ;IAAkC;IAElF,OAAOX,QAAQ;QACbrB;QACAI;QACAkB,QAAQ;YACNC,QAAQT,KAAKS,MAAM;YACnBC,UAAUV,KAAKM,QAAQ,GAAGzB,eAAe;gBAAEmB;gBAAMU,UAAUpB,MAAMoB,QAAQ;YAAC,KAAK,EAAE;YACjFS;QACF;IACF;AACF;AAEA,SAASZ,QAAQ,EACfC,MAAM,EACNtB,IAAI,EACJI,KAAK,EAKN;IACC,MAAMuC,UAAU;WAAIvC,MAAMuC,OAAO,CAACC,KAAK,CAAC,GAAGxC,MAAMS,CAAC;QAAGS;KAAO;IAE5D,IAAIqB,QAAQZ,MAAM,KAAK/B,KAAKe,KAAK,CAACC,SAAS,CAACe,MAAM,EAAE;QAClD,OAAO;YAAEjC,MAAM;YAAU+C,QAAQ;gBAAEF;YAAQ;QAAE;IAC/C;IAEA,OAAO;QACL7C,MAAM;QACNM,OAAO;YAAES,GAAGT,MAAMS,CAAC,GAAG;YAAGsB,MAAM;YAAGQ;YAASnB,UAAU,EAAE;YAAEU,QAAQ;QAAM;IACzE;AACF","file":"parse.js"}
|
package/dist/questions/render.js
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import { questionMessage } from './keyboard.js';
|
|
2
2
|
import { initialState } from './state.js';
|
|
3
3
|
import { postedAt, telegramTarget } from './telegramThread.js';
|
|
4
|
-
export const renderTelegramQuestion = async ({ calls, client, thread
|
|
4
|
+
export const renderTelegramQuestion = async ({ calls, client, thread })=>{
|
|
5
5
|
const [call] = calls;
|
|
6
|
-
if (!call)
|
|
7
|
-
return [];
|
|
6
|
+
if (!call) return [];
|
|
8
7
|
const target = telegramTarget(thread.id);
|
|
9
8
|
const state = initialState();
|
|
10
9
|
const response = await client.call('sendMessage', {
|
|
11
10
|
...target,
|
|
12
|
-
...questionMessage({
|
|
11
|
+
...questionMessage({
|
|
12
|
+
call,
|
|
13
|
+
state
|
|
14
|
+
})
|
|
13
15
|
});
|
|
14
16
|
const sent = response.result;
|
|
15
17
|
if (typeof sent?.message_id !== 'number') {
|
|
16
18
|
throw new Error('Telegram sendMessage did not return a message id.');
|
|
17
19
|
}
|
|
18
20
|
const id = `${String(sent.chat?.id ?? target.chat_id)}:${sent.message_id}`;
|
|
19
|
-
return [
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
calls: [
|
|
24
|
+
call.toolCallId
|
|
25
|
+
],
|
|
26
|
+
messages: [
|
|
27
|
+
{
|
|
28
|
+
id,
|
|
29
|
+
postedAt: postedAt(sent.date)
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
state
|
|
33
|
+
}
|
|
34
|
+
];
|
|
20
35
|
};
|
|
36
|
+
|
|
21
37
|
//# sourceMappingURL=render.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/questions/render.ts"],"names":["questionMessage","initialState","postedAt","telegramTarget","renderTelegramQuestion","calls","client","thread","call","target","id","state","response","sent","result","message_id","Error","String","chat","chat_id","toolCallId","messages","date"],"mappings":"AAGA,SAASA,eAAe,QAAQ,gBAAgB;AAChD,SAASC,YAAY,QAAQ,aAAa;AAC1C,SAASC,QAAQ,EAAEC,cAAc,QAAQ,sBAAsB;AAI/D,OAAO,MAAMC,yBAA6E,OAAO,EAC/FC,KAAK,EACLC,MAAM,EACNC,MAAM,EACP;IACC,MAAM,CAACC,KAAK,GAAGH;IAEf,IAAI,CAACG,MAAM,OAAO,EAAE;IAEpB,MAAMC,SAASN,eAAeI,OAAOG,EAAE;IACvC,MAAMC,QAAQV;IAEd,MAAMW,WAAW,MAAMN,OAAOE,IAAI,CAAC,eAAe;QAChD,GAAGC,MAAM;QACT,GAAGT,gBAAgB;YAAEQ;YAAMG;QAAM,EAAE;IACrC;IAEA,MAAME,OAAOD,SAASE,MAAM;IAE5B,IAAI,OAAOD,MAAME,eAAe,UAAU;QACxC,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMN,KAAK,GAAGO,OAAOJ,KAAKK,IAAI,EAAER,MAAMD,OAAOU,OAAO,EAAE,CAAC,EAAEN,KAAKE,UAAU,EAAE;IAE1E,OAAO;QAAC;YAAEV,OAAO;gBAACG,KAAKY,UAAU;aAAC;YAAEC,UAAU;gBAAC;oBAAEX;oBAAIR,UAAUA,SAASW,KAAKS,IAAI;gBAAE;aAAE;YAAEX;QAAM;KAAE;AACjG,EAAE","file":"render.js"}
|
|
@@ -1,18 +1,39 @@
|
|
|
1
1
|
import { settledMessage } from './keyboard.js';
|
|
2
2
|
import { readState } from './state.js';
|
|
3
3
|
import { actorName, editQuestionMessage } from './telegramThread.js';
|
|
4
|
-
export const settleTelegramQuestion = async ({ actor, call, client, outcome, question, req, thread
|
|
4
|
+
export const settleTelegramQuestion = async ({ actor, call, client, outcome, question, req, thread })=>{
|
|
5
5
|
const view = {
|
|
6
|
-
...
|
|
7
|
-
|
|
6
|
+
...actorName(actor) ? {
|
|
7
|
+
actor: actorName(actor)
|
|
8
|
+
} : {},
|
|
9
|
+
...'output' in outcome ? {
|
|
10
|
+
answers: outcome.output.answers
|
|
11
|
+
} : {}
|
|
8
12
|
};
|
|
9
|
-
const body = settledMessage({
|
|
13
|
+
const body = settledMessage({
|
|
14
|
+
...view,
|
|
15
|
+
call
|
|
16
|
+
});
|
|
10
17
|
try {
|
|
11
|
-
await Promise.all(question.messages.map(({ id })
|
|
18
|
+
await Promise.all(question.messages.map(({ id })=>editQuestionMessage({
|
|
19
|
+
body,
|
|
20
|
+
client,
|
|
21
|
+
messageId: id,
|
|
22
|
+
threadId: thread.id
|
|
23
|
+
})));
|
|
24
|
+
} catch (error) {
|
|
25
|
+
req.frogbot.logger.error({
|
|
26
|
+
err: error,
|
|
27
|
+
piece: 'telegramBot',
|
|
28
|
+
toolCallId: call.toolCallId
|
|
29
|
+
}, '[piece-telegram-bot] Could not mark a question answered.');
|
|
12
30
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
31
|
+
return {
|
|
32
|
+
state: {
|
|
33
|
+
...readState(question.state),
|
|
34
|
+
settled: view
|
|
35
|
+
}
|
|
36
|
+
};
|
|
17
37
|
};
|
|
38
|
+
|
|
18
39
|
//# sourceMappingURL=settled.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/questions/settled.ts"],"names":["settledMessage","readState","actorName","editQuestionMessage","settleTelegramQuestion","actor","call","client","outcome","question","req","thread","view","answers","output","body","Promise","all","messages","map","id","messageId","threadId","error","frogbot","logger","err","piece","toolCallId","state","settled"],"mappings":"AAGA,SAASA,cAAc,QAAQ,gBAAgB;AAC/C,SAASC,SAAS,QAAkC,aAAa;AACjE,SAASC,SAAS,EAAEC,mBAAmB,QAAQ,sBAAsB;AAErE,OAAO,MAAMC,yBAA8E,OAAO,EAChGC,KAAK,EACLC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACRC,GAAG,EACHC,MAAM,EACP;IACC,MAAMC,OAA4B;QAChC,GAAIV,UAAUG,SAAS;YAAEA,OAAOH,UAAUG;QAAO,IAAI,CAAC,CAAC;QACvD,GAAI,YAAYG,UAAU;YAAEK,SAASL,QAAQM,MAAM,CAACD,OAAO;QAAC,IAAI,CAAC,CAAC;IACpE;IAEA,MAAME,OAAOf,eAAe;QAAE,GAAGY,IAAI;QAAEN;IAAK;IAE5C,IAAI;QACF,MAAMU,QAAQC,GAAG,CACfR,SAASS,QAAQ,CAACC,GAAG,CAAC,CAAC,EAAEC,EAAE,EAAE,GAC3BjB,oBAAoB;gBAAEY;gBAAMR;gBAAQc,WAAWD;gBAAIE,UAAUX,OAAOS,EAAE;YAAC;IAG7E,EAAE,OAAOG,OAAO;QACdb,IAAIc,OAAO,CAACC,MAAM,CAACF,KAAK,CACtB;YAAEG,KAAKH;YAAOI,OAAO;YAAeC,YAAYtB,KAAKsB,UAAU;QAAC,GAChE;IAEJ;IAEA,OAAO;QAAEC,OAAO;YAAE,GAAG5B,UAAUQ,SAASoB,KAAK,CAAC;YAAEC,SAASlB;QAAK;IAAE;AAClE,EAAE","file":"settled.js"}
|
package/dist/questions/state.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
export function initialState() {
|
|
2
|
-
return {
|
|
2
|
+
return {
|
|
3
|
+
q: 0,
|
|
4
|
+
page: 0,
|
|
5
|
+
answers: [],
|
|
6
|
+
selected: [],
|
|
7
|
+
typing: false
|
|
8
|
+
};
|
|
3
9
|
}
|
|
4
10
|
export function readState(state) {
|
|
5
|
-
if (!state || typeof state !== 'object')
|
|
6
|
-
return initialState();
|
|
11
|
+
if (!state || typeof state !== 'object') return initialState();
|
|
7
12
|
const value = state;
|
|
8
|
-
const valid = isIndex(value.q) &&
|
|
9
|
-
isIndex(value.page) &&
|
|
10
|
-
Array.isArray(value.answers) &&
|
|
11
|
-
Array.isArray(value.selected) &&
|
|
12
|
-
typeof value.typing === 'boolean';
|
|
13
|
+
const valid = isIndex(value.q) && isIndex(value.page) && Array.isArray(value.answers) && Array.isArray(value.selected) && typeof value.typing === 'boolean';
|
|
13
14
|
return valid ? value : initialState();
|
|
14
15
|
}
|
|
15
16
|
function isIndex(value) {
|
|
16
17
|
return Number.isInteger(value) && value >= 0;
|
|
17
18
|
}
|
|
19
|
+
|
|
18
20
|
//# sourceMappingURL=state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/questions/state.ts"],"names":["initialState","q","page","answers","selected","typing","readState","state","value","valid","isIndex","Array","isArray","Number","isInteger"],"mappings":"AAkBA,OAAO,SAASA;IACd,OAAO;QAAEC,GAAG;QAAGC,MAAM;QAAGC,SAAS,EAAE;QAAEC,UAAU,EAAE;QAAEC,QAAQ;IAAM;AACnE;AAEA,OAAO,SAASC,UAAUC,KAAc;IACtC,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU,OAAOP;IAEhD,MAAMQ,QAAQD;IAEd,MAAME,QACJC,QAAQF,MAAMP,CAAC,KACfS,QAAQF,MAAMN,IAAI,KAClBS,MAAMC,OAAO,CAACJ,MAAML,OAAO,KAC3BQ,MAAMC,OAAO,CAACJ,MAAMJ,QAAQ,KAC5B,OAAOI,MAAMH,MAAM,KAAK;IAE1B,OAAOI,QAASD,QAAkCR;AACpD;AAEA,SAASU,QAAQF,KAAc;IAC7B,OAAOK,OAAOC,SAAS,CAACN,UAAU,AAACA,SAAoB;AACzD","file":"state.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/questions/supports.ts"],"names":["supportsTelegramQuestion","thread","id","startsWith"],"mappings":"AAEA,OAAO,MAAMA,2BAA2E,CAAC,EACvFC,MAAM,EACP,GAAK,CAACA,OAAOC,EAAE,CAACC,UAAU,CAAC,iBAAiB","file":"supports.js"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { TelegramApiError } from '../client.js';
|
|
2
2
|
export function telegramTarget(threadId) {
|
|
3
3
|
const [, chatId = '', topic] = threadId.split(':');
|
|
4
|
-
return {
|
|
4
|
+
return {
|
|
5
|
+
chat_id: chatId,
|
|
6
|
+
...topic ? {
|
|
7
|
+
message_thread_id: Number(topic)
|
|
8
|
+
} : {}
|
|
9
|
+
};
|
|
5
10
|
}
|
|
6
11
|
export function telegramMessageId(messageId) {
|
|
7
12
|
return Number(messageId.split(':').at(-1));
|
|
@@ -16,19 +21,18 @@ export function responderName(interaction) {
|
|
|
16
21
|
export function actorName(actor) {
|
|
17
22
|
return actor?.channel?.name || actor?.channel?.username || undefined;
|
|
18
23
|
}
|
|
19
|
-
export async function editQuestionMessage({ body, client, messageId, threadId
|
|
24
|
+
export async function editQuestionMessage({ body, client, messageId, threadId }) {
|
|
20
25
|
const { chat_id } = telegramTarget(threadId);
|
|
21
26
|
try {
|
|
22
27
|
await client.call('editMessageText', {
|
|
23
28
|
chat_id,
|
|
24
29
|
message_id: telegramMessageId(messageId),
|
|
25
|
-
...body
|
|
30
|
+
...body
|
|
26
31
|
});
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
32
|
+
} catch (error) {
|
|
29
33
|
const unchanged = error instanceof TelegramApiError && /message is not modified/i.test(error.description ?? '');
|
|
30
|
-
if (!unchanged)
|
|
31
|
-
throw error;
|
|
34
|
+
if (!unchanged) throw error;
|
|
32
35
|
}
|
|
33
36
|
}
|
|
37
|
+
|
|
34
38
|
//# sourceMappingURL=telegramThread.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/questions/telegramThread.ts"],"names":["TelegramApiError","telegramTarget","threadId","chatId","topic","split","chat_id","message_thread_id","Number","telegramMessageId","messageId","at","postedAt","date","Date","toISOString","responderName","interaction","author","type","message","event","user","fullName","userName","userId","actorName","actor","channel","name","username","undefined","editQuestionMessage","body","client","call","message_id","error","unchanged","test","description"],"mappings":"AAEA,SAASA,gBAAgB,QAAgC,eAAe;AAKxE,OAAO,SAASC,eAAeC,QAAgB;IAC7C,MAAM,GAAGC,SAAS,EAAE,EAAEC,MAAM,GAAGF,SAASG,KAAK,CAAC;IAE9C,OAAO;QAAEC,SAASH;QAAQ,GAAIC,QAAQ;YAAEG,mBAAmBC,OAAOJ;QAAO,IAAI,CAAC,CAAC;IAAE;AACnF;AAEA,OAAO,SAASK,kBAAkBC,SAAiB;IACjD,OAAOF,OAAOE,UAAUL,KAAK,CAAC,KAAKM,EAAE,CAAC,CAAC;AACzC;AAEA,OAAO,SAASC,SAASC,IAAa;IACpC,OAAO,OAAOA,SAAS,WAAW,IAAIC,KAAKD,OAAO,MAAME,WAAW,KAAK;AAC1E;AAEA,OAAO,SAASC,cAAcC,WAAgC;IAC5D,MAAMC,SACJD,YAAYE,IAAI,KAAK,YAAYF,YAAYG,OAAO,CAACF,MAAM,GAAGD,YAAYI,KAAK,CAACC,IAAI;IAEtF,OAAOJ,OAAOK,QAAQ,IAAIL,OAAOM,QAAQ,IAAIN,OAAOO,MAAM;AAC5D;AAEA,OAAO,SAASC,UAAUC,KAAuB;IAC/C,OAAOA,OAAOC,SAASC,QAAQF,OAAOC,SAASE,YAAYC;AAC7D;AAEA,OAAO,eAAeC,oBAAoB,EACxCC,IAAI,EACJC,MAAM,EACNxB,SAAS,EACTR,QAAQ,EAMT;IACC,MAAM,EAAEI,OAAO,EAAE,GAAGL,eAAeC;IAEnC,IAAI;QACF,MAAMgC,OAAOC,IAAI,CAAC,mBAAmB;YACnC7B;YACA8B,YAAY3B,kBAAkBC;YAC9B,GAAGuB,IAAI;QACT;IACF,EAAE,OAAOI,OAAO;QACd,MAAMC,YACJD,iBAAiBrC,oBAAoB,2BAA2BuC,IAAI,CAACF,MAAMG,WAAW,IAAI;QAE5F,IAAI,CAACF,WAAW,MAAMD;IACxB;AACF","file":"telegramThread.js"}
|
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
import { decodeAction, questionMessage } from './keyboard.js';
|
|
2
2
|
import { readState } from './state.js';
|
|
3
3
|
import { editQuestionMessage } from './telegramThread.js';
|
|
4
|
-
export const updateTelegramQuestion = async ({ call, client, interaction, question, req, thread })
|
|
5
|
-
const body = questionMessage({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
client,
|
|
9
|
-
messageId: question.messages.at(-1).id,
|
|
10
|
-
threadId: thread.id,
|
|
4
|
+
export const updateTelegramQuestion = async ({ call, client, interaction, question, req, thread })=>{
|
|
5
|
+
const body = questionMessage({
|
|
6
|
+
call,
|
|
7
|
+
state: readState(question.state)
|
|
11
8
|
});
|
|
9
|
+
const redraw = ()=>editQuestionMessage({
|
|
10
|
+
body,
|
|
11
|
+
client,
|
|
12
|
+
messageId: question.messages.at(-1).id,
|
|
13
|
+
threadId: thread.id
|
|
14
|
+
});
|
|
12
15
|
if (advances(interaction)) {
|
|
13
16
|
await redraw();
|
|
14
17
|
return;
|
|
15
18
|
}
|
|
16
19
|
try {
|
|
17
20
|
await redraw();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
} catch (error) {
|
|
22
|
+
req.frogbot.logger.error({
|
|
23
|
+
err: error,
|
|
24
|
+
piece: 'telegramBot',
|
|
25
|
+
toolCallId: call.toolCallId
|
|
26
|
+
}, '[piece-telegram-bot] Could not redraw a question.');
|
|
21
27
|
}
|
|
22
28
|
};
|
|
23
29
|
function advances(interaction) {
|
|
24
|
-
if (!interaction || interaction.type === 'message')
|
|
25
|
-
|
|
26
|
-
if (interaction.type !== 'action')
|
|
27
|
-
return false;
|
|
30
|
+
if (!interaction || interaction.type === 'message') return true;
|
|
31
|
+
if (interaction.type !== 'action') return false;
|
|
28
32
|
const action = decodeAction(interaction.event.actionId);
|
|
29
33
|
return action?.kind === 'choose' || action?.kind === 'done';
|
|
30
34
|
}
|
|
35
|
+
|
|
31
36
|
//# sourceMappingURL=updated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/questions/updated.ts"],"names":["decodeAction","questionMessage","readState","editQuestionMessage","updateTelegramQuestion","call","client","interaction","question","req","thread","body","state","redraw","messageId","messages","at","id","threadId","advances","error","frogbot","logger","err","piece","toolCallId","type","action","event","actionId","kind"],"mappings":"AAGA,SAASA,YAAY,EAAEC,eAAe,QAAQ,gBAAgB;AAC9D,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,mBAAmB,QAAQ,sBAAsB;AAE1D,OAAO,MAAMC,yBAET,OAAO,EAAEC,IAAI,EAAEC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,MAAM,EAAE;IAC7D,MAAMC,OAAOV,gBAAgB;QAAEI;QAAMO,OAAOV,UAAUM,SAASI,KAAK;IAAE;IAEtE,MAAMC,SAAS,IACbV,oBAAoB;YAClBQ;YACAL;YACAQ,WAAWN,SAASO,QAAQ,CAACC,EAAE,CAAC,CAAC,GAAIC,EAAE;YACvCC,UAAUR,OAAOO,EAAE;QACrB;IAEF,IAAIE,SAASZ,cAAc;QACzB,MAAMM;QAEN;IACF;IAEA,IAAI;QACF,MAAMA;IACR,EAAE,OAAOO,OAAO;QACdX,IAAIY,OAAO,CAACC,MAAM,CAACF,KAAK,CACtB;YAAEG,KAAKH;YAAOI,OAAO;YAAeC,YAAYpB,KAAKoB,UAAU;QAAC,GAChE;IAEJ;AACF,EAAE;AAEF,SAASN,SAASZ,WAA4C;IAC5D,IAAI,CAACA,eAAeA,YAAYmB,IAAI,KAAK,WAAW,OAAO;IAE3D,IAAInB,YAAYmB,IAAI,KAAK,UAAU,OAAO;IAE1C,MAAMC,SAAS3B,aAAaO,YAAYqB,KAAK,CAACC,QAAQ;IAEtD,OAAOF,QAAQG,SAAS,YAAYH,QAAQG,SAAS;AACvD","file":"updated.js"}
|
|
@@ -10,10 +10,10 @@ export declare const newUpdate: {
|
|
|
10
10
|
edited_message: "edited_message";
|
|
11
11
|
channel_post: "channel_post";
|
|
12
12
|
edited_channel_post: "edited_channel_post";
|
|
13
|
-
poll: "poll";
|
|
14
13
|
callback_query: "callback_query";
|
|
15
14
|
inline_query: "inline_query";
|
|
16
15
|
chosen_inline_result: "chosen_inline_result";
|
|
16
|
+
poll: "poll";
|
|
17
17
|
poll_answer: "poll_answer";
|
|
18
18
|
my_chat_member: "my_chat_member";
|
|
19
19
|
chat_member: "chat_member";
|
|
@@ -31,7 +31,7 @@ export declare const newUpdate: {
|
|
|
31
31
|
type: "app";
|
|
32
32
|
event: string;
|
|
33
33
|
run(args: import("frogbot").PieceRunArgs<{
|
|
34
|
-
updateTypes: ("message" | "edited_message" | "channel_post" | "edited_channel_post" | "
|
|
34
|
+
updateTypes: ("message" | "edited_message" | "channel_post" | "edited_channel_post" | "callback_query" | "inline_query" | "chosen_inline_result" | "poll" | "poll_answer" | "my_chat_member" | "chat_member" | "chat_join_request")[];
|
|
35
35
|
}, {
|
|
36
36
|
webhookSecret?: string | undefined;
|
|
37
37
|
botUsername?: string | undefined;
|