├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .github
├── codeql
│ └── codeql-config.yml
├── dependabot.yml
└── workflows
│ ├── ci.yml
│ └── codeql.yml
├── .gitignore
├── .npmrc
├── .vscode
└── launch.json
├── LICENSE
├── README.md
├── docs
├── LocalSession.html
├── fonts
│ ├── Montserrat
│ │ ├── Montserrat-Bold.eot
│ │ ├── Montserrat-Bold.ttf
│ │ ├── Montserrat-Bold.woff
│ │ ├── Montserrat-Bold.woff2
│ │ ├── Montserrat-Regular.eot
│ │ ├── Montserrat-Regular.ttf
│ │ ├── Montserrat-Regular.woff
│ │ └── Montserrat-Regular.woff2
│ └── Source-Sans-Pro
│ │ ├── sourcesanspro-light-webfont.eot
│ │ ├── sourcesanspro-light-webfont.svg
│ │ ├── sourcesanspro-light-webfont.ttf
│ │ ├── sourcesanspro-light-webfont.woff
│ │ ├── sourcesanspro-light-webfont.woff2
│ │ ├── sourcesanspro-regular-webfont.eot
│ │ ├── sourcesanspro-regular-webfont.svg
│ │ ├── sourcesanspro-regular-webfont.ttf
│ │ ├── sourcesanspro-regular-webfont.woff
│ │ └── sourcesanspro-regular-webfont.woff2
├── global.html
├── index.html
├── module-telegraf-session-local.html
├── scripts
│ ├── collapse.js
│ ├── commonNav.js
│ ├── linenumber.js
│ ├── nav.js
│ ├── polyfill.js
│ ├── prettify
│ │ ├── Apache-License-2.0.txt
│ │ ├── lang-css.js
│ │ └── prettify.js
│ └── search.js
├── session.js.html
└── styles
│ ├── jsdoc.css
│ └── prettify.css
├── examples
├── extra.js
└── simple.js
├── jsdoc.json
├── lib
├── lodash-id.js
├── session.d.ts
└── session.js
├── package.json
└── tests
├── general.js
├── lodash-id.js
├── sessionKeyUpdateTypes.js
├── storageCustom.js
├── storageFileAsync.js
├── storageFileSync.js
└── storageMemory.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
14 |
15 | [*.txt]
16 | trim_trailing_whitespace = false
17 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | docs/
3 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "es6": true,
4 | "node": true,
5 | "mocha": true
6 | },
7 | "extends": "standard",
8 | "plugins": ["mocha"],
9 | "parserOptions": {
10 | "ecmaVersion": 2017
11 | },
12 | "rules": {
13 | "one-var": 0,
14 | "comma-dangle": 0,
15 | "new-cap": 0,
16 | "padded-blocks": 0,
17 | "brace-style": [0, "1tbs", { "allowSingleLine": true }],
18 | "object-shorthand": ["warn", "consistent"]
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/.github/codeql/codeql-config.yml:
--------------------------------------------------------------------------------
1 | name: "CodeQL config"
2 |
3 | paths-ignore:
4 | - docs
5 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: npm
4 | directory: "/"
5 | schedule:
6 | interval: monthly
7 | open-pull-requests-limit: 30
8 | assignees:
9 | - TemaSM
10 | labels:
11 | - "Type: Maintenance"
12 | - dependencies
13 | versioning-strategy: increase
14 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on: [push, pull_request]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 | strategy:
9 | matrix:
10 | node-version: [14, 16, 18]
11 | name: Node.js ${{ matrix.node-version }}
12 | steps:
13 | - name: Checkout
14 | uses: actions/checkout@v3
15 |
16 | - name: Use Node.js ${{ matrix.node-version }}
17 | uses: actions/setup-node@v3
18 | with:
19 | node-version: ${{ matrix.node-version }}
20 |
21 | - name: Install pnpm
22 | uses: pnpm/action-setup@v2
23 | id: pnpm-install
24 | with:
25 | version: 7
26 | run_install: false
27 |
28 | - name: Get pnpm store directory
29 | id: pnpm-cache
30 | shell: bash
31 | run: |
32 | echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
33 |
34 | - name: Setup pnpm cache
35 | uses: actions/cache@v3
36 | with:
37 | path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
38 | key: ${{ runner.os }}-pnpm-store-node-${{ matrix.node-version }}
39 | restore-keys: |
40 | ${{ runner.os }}-pnpm-store-node-${{ matrix.node-version }}
41 |
42 | - name: Install dependencies
43 | run: pnpm install
44 |
45 | # Here we will use pnpx to run executables, instead of running `npm run
16 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
45 |
46 |
LocalSession
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
Constructor
77 |
78 |
79 |
new LocalSession(optionsopt)
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | - Source:
91 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
Parameters:
140 |
141 |
142 |
143 |
144 |
145 |
146 | Name |
147 |
148 |
149 | Type |
150 |
151 |
152 | Attributes |
153 |
154 |
155 |
156 |
157 | Description |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 | options |
167 |
168 |
169 |
170 |
171 |
172 | Object
173 |
174 |
175 |
176 |
177 | |
178 |
179 |
180 |
181 |
182 | <optional>
183 |
184 |
185 |
186 |
187 |
188 | |
189 |
190 |
191 |
192 |
193 | Options for LocalSession & lowdb
194 | Properties
195 |
196 |
197 |
198 |
199 |
200 |
201 | Name |
202 |
203 |
204 | Type |
205 |
206 |
207 | Attributes |
208 |
209 |
210 |
211 |
212 | Description |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 | database |
222 |
223 |
224 |
225 |
226 |
227 | String
228 |
229 |
230 |
231 |
232 | |
233 |
234 |
235 |
236 |
237 | <optional>
238 |
239 |
240 |
241 |
242 |
243 | |
244 |
245 |
246 |
247 |
248 | Name or path to database file default: 'sessions.json' |
249 |
250 |
251 |
252 |
253 |
254 |
255 | property |
256 |
257 |
258 |
259 |
260 |
261 | String
262 |
263 |
264 |
265 |
266 | |
267 |
268 |
269 |
270 |
271 | <optional>
272 |
273 |
274 |
275 |
276 |
277 | |
278 |
279 |
280 |
281 |
282 | Name of property in Telegraf Context where session object will be located default: 'session' |
283 |
284 |
285 |
286 |
287 |
288 |
289 | state |
290 |
291 |
292 |
293 |
294 |
295 | Object
296 |
297 |
298 |
299 |
300 | |
301 |
302 |
303 |
304 |
305 | <optional>
306 |
307 |
308 |
309 |
310 |
311 | |
312 |
313 |
314 |
315 |
316 | Initial state of database. You can use it to pre-init database Arrays/Objects to store your own data default: {} |
317 |
318 |
319 |
320 |
321 |
322 |
323 | getSessionKey |
324 |
325 |
326 |
327 |
328 |
329 | function
330 |
331 |
332 |
333 |
334 | |
335 |
336 |
337 |
338 |
339 | <optional>
340 |
341 |
342 |
343 |
344 |
345 | |
346 |
347 |
348 |
349 |
350 | Function to get identifier for session from Telegraf Context (may implement it on your own) |
351 |
352 |
353 |
354 |
355 |
356 |
357 | storage |
358 |
359 |
360 |
361 |
362 |
363 | Object
364 |
365 |
366 |
367 |
368 | |
369 |
370 |
371 |
372 |
373 | <optional>
374 |
375 |
376 |
377 |
378 |
379 | |
380 |
381 |
382 |
383 |
384 | lowdb storage option for implementing your own storage read/write operations default: LocalSession.storageFileSync
385 | Properties
386 |
387 |
388 |
389 |
390 |
391 |
392 | Name |
393 |
394 |
395 | Type |
396 |
397 |
398 | Attributes |
399 |
400 |
401 |
402 |
403 | Description |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 | read |
413 |
414 |
415 |
416 |
417 |
418 | function
419 |
420 |
421 |
422 |
423 | |
424 |
425 |
426 |
427 |
428 | <optional>
429 |
430 |
431 |
432 |
433 |
434 | |
435 |
436 |
437 |
438 |
439 | lowdb storage read function, must return an object or a Promise |
440 |
441 |
442 |
443 |
444 |
445 |
446 | write |
447 |
448 |
449 |
450 |
451 |
452 | function
453 |
454 |
455 |
456 |
457 | |
458 |
459 |
460 |
461 |
462 | <optional>
463 |
464 |
465 |
466 |
467 |
468 | |
469 |
470 |
471 |
472 |
473 | lowdb storage write function, must return undefined or a Promise |
474 |
475 |
476 |
477 |
478 |
479 |
480 | |
481 |
482 |
483 |
484 |
485 |
486 |
487 | format |
488 |
489 |
490 |
491 |
492 |
493 | Object
494 |
495 |
496 |
497 |
498 | |
499 |
500 |
501 |
502 |
503 | <optional>
504 |
505 |
506 |
507 |
508 |
509 | |
510 |
511 |
512 |
513 |
514 | lowdb storage format option for implementing your own database format for read/write operations
515 | Properties
516 |
517 |
518 |
519 |
520 |
521 |
522 | Name |
523 |
524 |
525 | Type |
526 |
527 |
528 | Attributes |
529 |
530 |
531 |
532 |
533 | Description |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 | serialize |
543 |
544 |
545 |
546 |
547 |
548 | function
549 |
550 |
551 |
552 |
553 | |
554 |
555 |
556 |
557 |
558 | <optional>
559 |
560 |
561 |
562 |
563 |
564 | |
565 |
566 |
567 |
568 |
569 | lowdb storage serialize function, must return data (usually string) default: JSON.stringify() |
570 |
571 |
572 |
573 |
574 |
575 |
576 | deserialize |
577 |
578 |
579 |
580 |
581 |
582 | function
583 |
584 |
585 |
586 |
587 | |
588 |
589 |
590 |
591 |
592 | <optional>
593 |
594 |
595 |
596 |
597 |
598 | |
599 |
600 |
601 |
602 |
603 | lowdb storage deserialize function, must return an object default: JSON.parse() |
604 |
605 |
606 |
607 |
608 |
609 |
610 | |
611 |
612 |
613 |
614 |
615 |
616 |
617 | |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
Returns:
640 |
641 |
642 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 | Members
670 |
671 |
672 |
673 | (readonly) .storagefileAsync
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 | - Description:
682 |
683 |
684 |
685 |
686 | - Source:
687 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 |
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
lowdb storage named fileAsync before lowdb@0.17.0
729 |
730 |
731 |
732 |
733 |
734 |
735 |
736 |
737 |
738 |
739 |
740 | (readonly) .storagefileSync
741 |
742 |
743 |
744 |
745 |
746 |
747 |
748 | - Description:
749 |
750 |
751 |
752 |
753 | - Source:
754 |
757 |
758 |
759 |
760 |
761 |
762 |
763 |
764 |
765 |
766 |
767 |
768 |
769 |
770 |
771 |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 |
780 |
781 |
782 |
783 |
784 |
785 |
786 |
787 |
788 |
789 |
790 |
791 |
792 |
793 |
794 |
795 |
lowdb storage named fileSync before lowdb@0.17.0
796 |
797 |
798 |
799 |
800 |
801 |
802 |
803 |
804 |
805 |
806 |
807 |
808 |
809 | Methods
810 |
811 |
812 |
813 |
814 |
815 |
816 | getSession(key) → {Object}
817 |
818 |
819 |
820 |
821 |
822 |
823 |
824 |
825 | - Description:
826 |
827 |
828 |
829 |
830 | - Source:
831 |
834 |
835 |
836 |
837 |
838 |
839 |
840 |
841 |
842 |
843 |
844 |
845 |
846 |
847 |
848 |
849 |
850 |
851 |
852 |
853 |
854 |
855 |
856 |
857 |
858 |
859 |
860 |
861 |
862 |
863 |
864 |
865 |
866 |
867 |
868 |
869 |
870 |
871 |
872 |
873 |
874 |
875 |
876 |
877 |
878 |
879 | Parameters:
880 |
881 |
882 |
883 |
884 |
885 |
886 | Name |
887 |
888 |
889 | Type |
890 |
891 |
892 |
893 |
894 |
895 | Description |
896 |
897 |
898 |
899 |
900 |
901 |
902 |
903 |
904 | key |
905 |
906 |
907 |
908 |
909 |
910 | String
911 |
912 |
913 |
914 |
915 | |
916 |
917 |
918 |
919 |
920 |
921 | Key which will be used to find associated session object |
922 |
923 |
924 |
925 |
926 |
927 |
928 |
929 |
930 |
931 |
932 |
933 |
934 |
935 |
936 |
937 |
938 |
939 |
940 |
941 |
942 |
943 | Returns:
944 |
945 |
946 |
947 |
Session data object or empty object if there's no session in database with this key
948 |
949 |
950 |
951 |
952 |
953 | -
954 | Type
955 |
956 | -
957 |
958 | Object
959 |
960 |
961 |
962 |
963 |
964 |
965 |
966 |
967 |
968 |
969 |
970 |
971 |
972 |
973 |
974 | getSessionKey(ctx) → {String}
975 |
976 |
977 |
978 |
979 |
980 |
981 |
982 |
983 | - Description:
984 |
985 |
986 |
987 |
988 | - Source:
989 |
992 |
993 |
994 |
995 |
996 |
997 |
998 |
999 |
1000 |
1001 |
1002 |
1003 |
1004 |
1005 |
1006 |
1007 |
1008 |
1009 |
1010 |
1011 |
1012 |
1013 |
1014 |
1015 |
1016 |
1017 |
1018 |
1019 |
1020 |
1021 |
1022 |
1023 |
1024 |
1025 |
1026 |
1027 |
1028 |
1029 |
1030 |
1031 |
1032 |
1033 |
1034 |
1035 |
1036 |
1037 | Parameters:
1038 |
1039 |
1040 |
1041 |
1042 |
1043 |
1044 | Name |
1045 |
1046 |
1047 | Type |
1048 |
1049 |
1050 |
1051 |
1052 |
1053 | Description |
1054 |
1055 |
1056 |
1057 |
1058 |
1059 |
1060 |
1061 |
1062 | ctx |
1063 |
1064 |
1065 |
1066 |
1067 |
1068 | Object
1069 |
1070 |
1071 |
1072 |
1073 | |
1074 |
1075 |
1076 |
1077 |
1078 |
1079 | Telegraf Context |
1080 |
1081 |
1082 |
1083 |
1084 |
1085 |
1086 |
1087 |
1088 |
1089 |
1090 |
1091 |
1092 |
1093 |
1094 |
1095 |
1096 |
1097 |
1098 |
1099 |
1100 |
1101 | Returns:
1102 |
1103 |
1104 |
1105 |
Session key in format number:number
(chat.id:from.id)
1106 |
1107 |
1108 |
1109 |
1110 |
1111 | -
1112 | Type
1113 |
1114 | -
1115 |
1116 | String
1117 |
1118 |
1119 |
1120 |
1121 |
1122 |
1123 |
1124 |
1125 |
1126 |
1127 |
1128 |
1129 |
1130 |
1131 |
1132 | middleware(propertyopt) → {Promise}
1133 |
1134 |
1135 |
1136 |
1137 |
1138 |
1139 |
1140 |
1141 | - Description:
1142 |
1143 |
1144 |
1145 |
1146 | - Source:
1147 |
1150 |
1151 |
1152 |
1153 |
1154 |
1155 |
1156 |
1157 |
1158 |
1159 |
1160 |
1161 |
1162 |
1163 |
1164 |
1165 |
1166 |
1167 |
1168 |
1169 |
1170 |
1171 |
1172 |
1173 |
1174 |
1175 |
1176 |
1177 |
1178 |
1179 |
1180 |
1181 |
1182 |
1183 |
1184 |
1185 |
1186 |
1187 |
1188 |
1189 |
1190 |
1191 |
1192 |
1193 |
1194 |
1195 | Parameters:
1196 |
1197 |
1198 |
1199 |
1200 |
1201 |
1202 | Name |
1203 |
1204 |
1205 | Type |
1206 |
1207 |
1208 | Attributes |
1209 |
1210 |
1211 |
1212 |
1213 | Description |
1214 |
1215 |
1216 |
1217 |
1218 |
1219 |
1220 |
1221 |
1222 | property |
1223 |
1224 |
1225 |
1226 |
1227 |
1228 | String
1229 |
1230 |
1231 |
1232 |
1233 | |
1234 |
1235 |
1236 |
1237 |
1238 | <optional>
1239 |
1240 |
1241 |
1242 |
1243 |
1244 | |
1245 |
1246 |
1247 |
1248 |
1249 | Name of property in Telegraf Context where session object will be located (overrides property at LocalSession constructor) |
1250 |
1251 |
1252 |
1253 |
1254 |
1255 |
1256 |
1257 |
1258 |
1259 |
1260 |
1261 |
1262 |
1263 |
1264 |
1265 |
1266 |
1267 |
1268 |
1269 |
1270 |
1271 | Returns:
1272 |
1273 |
1274 |
1275 |
1276 |
1277 | -
1278 | Type
1279 |
1280 | -
1281 |
1282 | Promise
1283 |
1284 |
1285 |
1286 |
1287 |
1288 |
1289 |
1290 |
1291 |
1292 |
1293 |
1294 |
1295 |
1296 |
1297 |
1298 | (async) saveSession(key, data) → {Promise|function}
1299 |
1300 |
1301 |
1302 |
1303 |
1304 |
1305 |
1306 |
1307 | - Description:
1308 |
1309 |
1310 |
1311 |
1312 | - Source:
1313 |
1316 |
1317 |
1318 |
1319 |
1320 |
1321 |
1322 |
1323 |
1324 |
1325 |
1326 |
1327 |
1328 |
1329 |
1330 |
1331 |
1332 |
1333 |
1334 |
1335 |
1336 |
1337 |
1338 |
1339 |
1340 |
1341 |
1342 |
1343 |
1344 |
1345 |
1346 |
1347 |
1348 |
1349 |
1350 |
1351 |
1352 |
1353 |
1354 |
1355 |
1356 |
1357 |
1358 |
1359 |
1360 |
1361 | Parameters:
1362 |
1363 |
1364 |
1365 |
1366 |
1367 |
1368 | Name |
1369 |
1370 |
1371 | Type |
1372 |
1373 |
1374 |
1375 |
1376 |
1377 | Description |
1378 |
1379 |
1380 |
1381 |
1382 |
1383 |
1384 |
1385 |
1386 | key |
1387 |
1388 |
1389 |
1390 |
1391 |
1392 | String
1393 |
1394 |
1395 |
1396 |
1397 | |
1398 |
1399 |
1400 |
1401 |
1402 |
1403 | Unique Key which will be used to store session object |
1404 |
1405 |
1406 |
1407 |
1408 |
1409 |
1410 | data |
1411 |
1412 |
1413 |
1414 |
1415 |
1416 | Object
1417 |
1418 |
1419 |
1420 |
1421 | |
1422 |
1423 |
1424 |
1425 |
1426 |
1427 | Session data object (if empty, session will be removed from database) |
1428 |
1429 |
1430 |
1431 |
1432 |
1433 |
1434 |
1435 |
1436 |
1437 |
1438 |
1439 |
1440 |
1441 |
1442 |
1443 |
1444 |
1445 |
1446 |
1447 |
1448 |
1449 | Returns:
1450 |
1451 |
1452 |
1453 |
1454 | - Promise or Promise-like
.then()
function, with session object at 1-st argument
1455 |
1456 |
1457 |
1458 |
1459 |
1460 |
1461 | -
1462 | Type
1463 |
1464 | -
1465 |
1466 | Promise
1467 | |
1468 |
1469 | function
1470 |
1471 |
1472 |
1473 |
1474 |
1475 |
1476 |
1477 |
1478 |
1479 |
1480 |
1481 |
1482 |
1483 |
1484 |
1485 |
1486 |
1487 |
1488 |
1489 |
1490 |
1491 |
1492 |
1493 |
1494 |
1495 |
1496 |
1497 |