-
Notifications
You must be signed in to change notification settings - Fork 569
/
index.html
1834 lines (1672 loc) · 74.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
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
640
641
642
643
644
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
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
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
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="format-detection" content="telephone=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="MobileOptimized" content="176" />
<meta name="HandheldFriendly" content="True" />
<meta name="robots" content="noindex,nofollow" />
<script src="https://telegram.org/js/telegram-web-app.js?2"></script>
<script>
function setThemeClass() {
document.documentElement.className = Telegram.WebApp.colorScheme;
}
Telegram.WebApp.onEvent('themeChanged', setThemeClass);
setThemeClass();
</script>
<title></title>
<style>
body {
--bg-color: var(--tg-theme-bg-color, #fff);
font-family: sans-serif;
background-color: var(--bg-color);
color: var(--tg-theme-text-color, #222);
font-size: 14px;
margin: 0;
padding: 0;
color-scheme: var(--tg-color-scheme);
}
body.gray {
background-color: var(--tg-theme-secondary-bg-color, #efefef);
}
a {
color: var(--tg-theme-link-color, #2678b6);
}
.btn {
font-size: 14px;
padding: 10px 17px;
}
.btn-primary {
background-color: var(--tg-theme-button-color, #50a8eb);
color: var(--tg-theme-button-text-color, #fff);
border: none;
}
button {
display: block;
width: 100%;
font-size: 14px;
margin: 15px 0;
padding: 12px 20px;
border: none;
border-radius: 4px;
background-color: var(--tg-theme-button-color, #50a8eb);
color: var(--tg-theme-button-text-color, #ffffff);
cursor: pointer;
}
.main-container {
padding: 15px;
}
.list-header {
text-transform: uppercase;
font-size: .92em;
color: var(--tg-theme-hint-color, #ccc);
margin: 0 0 10px;
}
a.list-group-item,
button.list-group-item {
color: var(--tg-theme-text-color, #222);
}
.main-container p {
margin: 0 0 10px;
}
.main-container pre,
.main-container > .btn {
margin: 0 0 7px;
}
.main-container pre + .hint,
.main-container > .btn + .hint {
text-align: center;
margin: 0 0 15px;
}
button[disabled] {
opacity: 0.6;
cursor: auto;
pointer-events: none;
}
button.close_btn {
/*position: fixed;*/
position: absolute;
left: 0;
right: 0;
bottom: 0;
border-radius: 0;
margin: 0;
padding: 16px 20px;
text-transform: uppercase;
}
input[type="text"],
.input[contenteditable] {
display: block;
box-sizing: border-box;
font-size: 14px;
width: 100%;
padding: 12px 20px;
margin: 15px 0;
border: 1px solid var(--tg-theme-link-color, #000);
background-color: var(--tg-theme-bg-color, #ffffff);
border-radius: 4px;
color: var(--tg-theme-text-color, #222222);
text-align: start;
}
input[type="text"]::-webkit-input-placeholder {
color: var(--tg-theme-hint-color, #ccc);
}
input[type="text"]::-moz-placeholder {
color: var(--tg-theme-hint-color, #ccc);
}
input[type="text"]:-ms-input-placeholder {
color: var(--tg-theme-hint-color, #ccc);
}
.input[data-placeholder] {
position: relative;
}
.input[data-placeholder]:empty:before {
position: absolute;
left: 0;
right: 0;
content: attr(data-placeholder);
color: var(--tg-theme-hint-color, #ccc);
padding: 0 20px;
font-weight: normal;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
pointer-events: none;
z-index: -1;
}
section {
padding: 15px;
text-align: center;
background-color: var(--bg-color, #ffffff);
}
section#top_sect {
background-color: var(--tg-theme-bg-color, #ffffff);
}
section#top_sect.second {
background-color: var(--tg-theme-secondary-bg-color, #efefef);
}
section .sect_row {
margin: 10px 0;
}
section + section {
padding: 0 15px 65px;
}
p {
margin: 40px 0 15px;
}
ul {
text-align: left;
}
li {
color: var(--tg-theme-hint-color, #a8a8a8);
}
textarea {
width: 100%;
box-sizing: border-box;
padding: 7px;
}
pre {
background: rgba(0, 0, 0, .07);
color: var(--tg-theme-text-color, #222);
font-size: 12px;
border: none;
border-radius: 4px;
padding: 8px;
margin: 7px 0;
word-break: break-word;
white-space: pre-wrap;
text-align: left;
}
.dark pre {
background: rgba(255, 255, 255, .15);
}
.chat_img {
width: 30px;
border-radius: 15px;
margin-right: 10px;
}
.columns {
display: flex;
}
.columns > * {
flex-grow: 1;
}
.hint {
font-size: .8em;
color: var(--tg-theme-hint-color, #a8a8a8);
}
.ok {
color: green;
}
.err {
color: red;
}
.status_need {
display: none;
}
#fixed_wrap {
position: fixed;
left: 0;
right: 0;
top: 0;
transform: translateY(100vh);
}
.viewport-container {
position: fixed;
left: 0;
right: 0;
top: 0;
height: var(--tg-viewport-stable-height, 100vh);
transition: height .2s ease;
}
.viewport-container .main-container {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
}
.viewport-container .main-container button {
width: auto;
}
.viewport-border,
.viewport-stable_border {
position: fixed;
left: 0;
right: 0;
top: 0;
height: var(--tg-viewport-height, 100vh);
pointer-events: none;
}
.viewport-stable_border {
height: var(--tg-viewport-stable-height, 100vh);
}
.viewport-border:before,
.viewport-stable_border:before {
content: attr(text);
display: inline-block;
position: absolute;
background: gray;
right: 0;
top: 0;
font-size: 7px;
padding: 2px 4px;
vertical-align: top;
}
.viewport-stable_border:before {
background: green;
left: 0;
right: auto;
}
.viewport-border:after,
.viewport-stable_border:after {
content: '';
display: block;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
border: 2px dashed gray;
}
.viewport-stable_border:after {
border-color: green;
}
small {
font-size: 12px;
}
.small {
font-size: 12px;
}
.table {
width: 100%;
border-collapse: collapse;
}
.table td {
padding: 2px;
}
.table-bordered {
border: 1px solid var(--tg-theme-hint-color, #ccc);
}
.table-bordered th, .table-bordered td {
border: 1px solid var(--tg-theme-hint-color, #ccc);
padding: 4px;
}
.table.small button {
padding: 3px 6px;
font-size: 12px;
margin: 4px 0;
}
.table.small input {
padding: 3px 6px;
font-size: 12px;
margin: 4px 0;
}
</style>
</head>
<body class="" style="visibility: hidden;">
<section id="top_sect" class="second">
<button id="main_btn" onclick="DemoApp.sendMessage('');">Send «Hello, World!»</button>
<button id="with_webview_btn" onclick="DemoApp.sendMessage('', true);">Send «Hello, World!» with inline webview button</button>
<button id="share_btn" onclick="DemoApp.sendMessage('', false, true);">Share «Hello, World!»</button>
<button id="share_ww_btn" onclick="DemoApp.sendMessage('', true, true);">Share «Hello, World!» with inline button</button>
<button id="data_btn" onclick="DemoApp.sendTime(true);">Send current time to bot (x10)</button>
<button onclick="DemoApp.expand();">Expand Webview</button>
<button onclick="DemoApp.toggleBackButton(this);">Show Back Button</button>
<button onclick="DemoApp.toggleSettingsButton(this);">Show Settings Button</button>
<button onclick="DemoApp.toggleMainButton(this);">Hide Main Button</button>
<button onclick="DemoApp.toggleSecondaryButton(this);">Hide Secondary Button</button>
<button onclick="DemoApp.toggleButtonsProgress(this);">Show Progress</button>
<button onclick="DemoApp.toggleSwipeBehavior(this);">Disable Vertical Swypes</button>
<button id="fullscreen_btn" onclick="DemoApp.toggleFullscreen(this);">Request Fullscreen</button>
<button id="orient_btn" onclick="DemoApp.toggleOrientationLock(this);">Lock Orientation</button>
<input type="text" placeholder="Input text in regular input..." id="regular_field" />
<div
class="input"
contenteditable="true"
data-placeholder="Input text in contenteditable field..."
id="text_field"
></div>
<div id="peer_wrap" style="display:none">
<img id="peer_photo" class="chat_img" src="">
<span id="peer_name"></span>
</div>
<div class="sect_row">Header: <input type="color" id="header_color_input" />
<select id="header_color_sel">
<option value="bg_color" selected>bg_color</option>
<option value="secondary_bg_color">secondary_bg_color</option>
<option value="custom" id="header_color_val">custom...</option>
</select>
</div>
<div class="sect_row">Background: <input type="color" id="bg_color_input" />
<select id="bg_color_sel">
<option value="bg_color" selected>bg_color</option>
<option value="secondary_bg_color">secondary_bg_color</option>
<option value="custom" id="bg_color_val">custom...</option>
</select>
</div>
<div class="sect_row">Bottom Bar: <input type="color" id="bbar_color_input" />
<select id="bbar_color_sel">
<option value="bg_color">bg_color</option>
<option value="secondary_bg_color">secondary_bg_color</option>
<option value="bottom_bar_bg_color" selected>bottom_bar_bg_color</option>
<option value="custom" id="bbar_color_val">custom...</option>
</select>
</div>
</section>
<section>
<div id="btn_status" class="hint" style="display: none;"></div>
<p>Test links:</p>
<ul>
<li><a id="regular_link" href="?nextpage=1">Regular link #1</a> (opens inside webview)</li>
<li><a href="https://telegram.org/" target="_blank">target="_blank" link</a> (opens outside webview)</li>
<li><a href="javascript:window.open('https://telegram.org/');">window.open() link</a> (opens outside webview)</li>
<li><a href="https://t.me/like">LikeBot t.me link</a> (opens inside Telegram app)</li>
<li><a href="javascript:Telegram.WebApp.openTelegramLink('https://t.me/vote');">web_app_open_tg_link()</a> (opens inside Telegram app)</li>
<li><a href="javascript:Telegram.WebApp.openLink('https://google.com/');">web_app_open_link()</a> (opens outside webview)</li>
<li><a href="tg://resolve?domain=vote">VoteBot tg:// link</a> (does not open)</li>
<li><a href="javascript:Telegram.WebApp.openLink('https://telegra.ph/api',{try_instant_view:true});">web_app_open_link({try_instant_view:true})</a> (opens IV inside Telegram app)</li>
<li><a href="javascript:Telegram.WebApp.openTelegramLink('https://t.me/DurgerKingBot/menu');">web_app_open_tg_link(webapp_direct_link)</a> (opens with confirm for the first time, then without)</li>
</ul>
<ul>
<li><a href="javascript:Telegram.WebApp.openLink('https://telegram.org',{try_browser:'chrome'});">telegram.org</a> (opens in Chrome)</li>
<li><a href="javascript:Telegram.WebApp.openLink('https://telegram.org',{try_browser:'firefox'});">telegram.org</a> (opens in Firefox)</li>
<li><a href="javascript:Telegram.WebApp.openLink('https://telegram.org',{try_browser:'safari'});">telegram.org</a> (opens in Safari)</li>
<li><a href="javascript:Telegram.WebApp.openLink('https://telegram.org',{try_browser:'opera'});">telegram.org</a> (opens in Opera)</li>
<li><a href="javascript:Telegram.WebApp.close({return_back:true});">Return back</a> (Android only)</li>
</ul>
<ul>
<li><a href="javascript:Telegram.WebApp.shareToStory('https://telegra.ph/file/5583ac37c90979f052b7b.png');">Share picture to story</a></li>
<li><a href="javascript:Telegram.WebApp.shareToStory('https://telegra.ph/file/5583ac37c90979f052b7b.png',{text:'Test caption'});">Share picture to story</a> (with caption)</li>
<li><a href="javascript:Telegram.WebApp.shareToStory('https://telegra.ph/file/5583ac37c90979f052b7b.png',{widget_link:{url:'https://telegra.ph/Almost-done-07-23'}});">Share picture to story</a> (with link widget)</li>
<li><a href="javascript:Telegram.WebApp.shareToStory('https://telegra.ph/file/61f1dac694c3131a7b4ac.mp4',{text:'Test caption',widget_link:{url:'https://telegra.ph/Almost-done-07-23',name:'Link'}});">Share video to story</a> (with caption and link widget)</li>
</ul>
<ul>
<li><a href="javascript:DemoApp.downloadFile(this, 'https://telegra.ph/file/5583ac37c90979f052b7b.png', 'Photo.png');">Download picture</a> <span></span></li>
<li><a href="javascript:DemoApp.downloadFile(this, 'https://telegra.ph/file/61f1dac694c3131a7b4ac.mp4', 'Video.mp4');">Download video</a> <span></span></li>
<li><a href="javascript:DemoApp.downloadFile(this, 'https://pdfobject.com/pdf/sample.pdf', 'Sample.pdf');">Download PDF</a> <span></span></li>
</ul>
<ul>
<li><a href="javascript:Telegram.WebApp.openTelegramLink('https://t.me/addstickers/fltmp');">Stickerpack</a></li>
<li><a href="javascript:Telegram.WebApp.openTelegramLink('https://t.me/addstickers/fltmp', {force_request:true});">Stickerpack</a> (nocache)</li>
</ul>
<ul>
<li><a href="javascript:;" onclick="return DemoApp.checkHomeScreenStatus(this);">Check Home Screen Status</a> <span></span></li>
<li><a id="add_to_home_btn" href="javascript:;" onclick="return DemoApp.addToHomeScreen(this);">Add to Home Screen</a></li>
</ul>
<ul>
<li><a href="javascript:DemoApp.setEmojiStatus(this, '5213305508034783384');">Set emoji status</a> <span></span></li>
<li><a href="javascript:DemoApp.setEmojiStatus(this, '5213305508034783384', 300);">Set emoji status</a> for 5 min <span></span></li>
<li><a href="javascript:DemoApp.setEmojiStatus(this, '123');">Set emoji status</a> (invalid id) <span></span></li>
</ul>
<p>Test permissions:</p>
<div class="columns">
<ul>
<li><a href="javascript:;" onclick="return DemoApp.requestLocation(this);">Request Location</a> <span></span></li>
<li><a href="javascript:;" onclick="return DemoApp.requestVideo(this);">Request Video</a> <span></span></li>
<li><a href="javascript:;" onclick="return DemoApp.requestAudio(this);">Request Audio</a> <span></span></li>
<li><a href="javascript:;" onclick="return DemoApp.requestAudioVideo(this);">Request Audio+Video</a> <span></span></li>
<li><a href="javascript:;" onclick="return DemoApp.testClipboard(this);" id="clipboard_test">Read from clipboard</a> <span></span></li>
</ul>
<ul>
<li><a href="javascript:;" onclick="return DemoApp.requestWriteAccess(this);">Request write access</a> <span></span></li>
<li><a href="javascript:;" onclick="return DemoApp.requestPhoneNumber(this);">Request phone number</a> <span></span><br><br></li>
<li><a href="javascript:;" onclick="return DemoApp.requestServerTime(this);">Request server time</a> (invokes custom method) <span></span></li>
</ul>
</div>
<p>Sensors:</p>
<div class="columns">
<ul>
<li><a id="accelerometer_btn" href="javascript:;" onclick="return DemoApp.toggleAccelerometer(this);">Start Accelerometer</a> <span></span></li>
<li><a id="device_orientation_btn" href="javascript:;" onclick="return DemoApp.toggleDeviceOrientation(this);">Start DeviceOrientation(need_absolute=false)</a> <span></span></li>
<li id="device_orientation_abs_item"><a href="javascript:;" onclick="return DemoApp.toggleDeviceOrientation(this, true);">Start DeviceOrientation(need_absolute=true)</a> <span></span></li>
<li><a id="gyroscope_btn" href="javascript:;" onclick="return DemoApp.toggleGyroscope(this);">Start Gyroscope</a> <span></span></li>
</ul>
</div>
<p>Test alerts:</p>
<div class="columns">
<ul>
<li><a href="javascript:;" onclick="alert('Hello!');">alert</a></li>
<li><a href="javascript:;" onclick="confirm('Are you sure?');">confirm</a></li>
<li><a href="javascript:;" onclick="prompt('How old are you?');">prompt</a></li>
</ul>
<ul>
<li><a href="javascript:;" onclick="DemoApp.showAlert('Hello!');">showAlert</a></li>
<li><a href="javascript:;" onclick="DemoApp.showConfirm('Are you sure?');">showConfirm</a></li>
<li><a href="javascript:;" onclick="DemoApp.requestWriteAccess();">requestWriteAccess</a></li>
<li><a href="javascript:;" onclick="DemoApp.requestContact();">requestContact</a></li>
<li><a href="javascript:;" onclick="DemoApp.showPopup();">showPopup</a></li>
<li><a href="javascript:;" onclick="DemoApp.showScanQrPopup();">showScanQrPopup</a></li>
<li><a href="javascript:;" onclick="DemoApp.showScanQrPopup(true);">showScanQrPopup (links only)</a></li>
</ul>
</div>
<p>Haptics:</p>
<ul>
<li>Impact: <a href="javascript:Telegram.WebApp.HapticFeedback.impactOccurred('heavy');">heavy</a>, <a href="javascript:Telegram.WebApp.HapticFeedback.impactOccurred('light');">light</a>, <a href="javascript:Telegram.WebApp.HapticFeedback.impactOccurred('medium');">medium</a>, <a href="javascript:Telegram.WebApp.HapticFeedback.impactOccurred('rigid');">rigid</a>, <a href="javascript:Telegram.WebApp.HapticFeedback.impactOccurred('soft');">soft</a><br><br></li>
<li>Notification: <a href="javascript:Telegram.WebApp.HapticFeedback.notificationOccurred('error');">error</a>, <a href="javascript:Telegram.WebApp.HapticFeedback.notificationOccurred('success');">success</a>, <a href="javascript:Telegram.WebApp.HapticFeedback.notificationOccurred('warning');">warning</a><br><br></li>
<li>Selection: <a href="javascript:Telegram.WebApp.HapticFeedback.selectionChanged();">changed</a><br><br></li>
</ul>
<p>Cloud storage:</p>
<form onsubmit="DemoApp.saveCloudForm(this, event);">
<table class="table table-bordered small">
<thead>
<tr>
<th width="20%">Key</th>
<th width="70%">Value</th>
<th width="10%"></th>
</tr>
</thead>
<tbody id="cloud_rows"></tbody>
<tfoot>
<tr>
<td><input type="text" name="key" /></td>
<td><input type="text" name="value" /></td>
<td>
<button type="submit">Save</button>
<button type="reset">Clear</button>
</td>
</tr>
</tfoot>
</table>
</form>
<p>Biometrics:</p>
<div class="columns">
<ul>
<li>isInited: <span class="txt" id="bm_inited">false</span></li>
<li>available: <span class="txt" id="bm_available">false</span></li>
<li>type: <span class="txt" id="bm_type"></span></li>
<li>access_requested: <span class="txt" id="bm_access_requested">false</span> (<a href="javascript:;" onclick="return DemoApp.biometricRequestAccess(this);">Request access</a>) <span></span></li>
<li>access_granted: <span class="txt" id="bm_access_granted">false</span> <span id="bm_settings" style="display:none;">(<a href="javascript:;" onclick="return DemoApp.biometricOpenSettings(this);">Open settings</a>)</span></li>
<li>token_saved: <span class="txt" id="bm_token_saved">false</span> (<a href="javascript:;" onclick="return DemoApp.biometricSetToken(this);">Set token</a>, <a href="javascript:;" onclick="return DemoApp.biometricRemoveToken(this);">Remove token</a>) <span></span></li>
<li>device_id: <span class="txt" id="bm_device_id"></span></li>
<li><a href="javascript:;" onclick="return DemoApp.biometricRequestAuth(this);">Request auth</a> <span></span></li>
</ul>
</div>
<p>Location:</p>
<div class="columns">
<ul>
<li>isInited: <span class="txt" id="loc_inited">false</span></li>
<li>available: <span class="txt" id="loc_available">false</span></li>
<li>access_requested: <span class="txt" id="loc_access_requested">false</span> (<a href="javascript:;" onclick="return DemoApp.locationGet(this);">Request location</a>) <span></span></li>
<li>access_granted: <span class="txt" id="loc_access_granted">false</span>
<span id="loc_settings" style="display:none;">(<a href="javascript:;" onclick="return DemoApp.locationOpenSettings(this);">Open settings</a>)</span>
</li>
</ul>
</div>
<pre><code id="webview_data"></code></pre>
<div class="hint">
Data passed to webview.
<span id="webview_data_status" class="status_need">Checking hash...</span>,
<span id="webview_data_sign_status">checking signature...</span>
</div>
<pre><code id="theme_data"></code></pre>
<div class="hint">
Theme params
</div>
<div class="hint">
Version: <span id="ver"></span>,
platform: <span id="platform"></span>
</div>
<div class="hint">
<span id="cur_activity"></span><span id="prev_activity"></span>
</div>
</section>
<div class="safe-area-border"></div>
<div class="tg-safe-area-border">
<div class="tg-content-safe-area-border"></div>
</div>
<div class="viewport-border"></div>
<div class="viewport-stable_border"></div>
<script type="application/javascript">
/*
* This is a demo code for Telegram WebApp for Bots
* It contains basic examples of how to use the API
* Note: all requests to backend are disabled in this demo, you should use your own backend
*/
const DemoApp = {
initData : Telegram.WebApp.initData || '',
initDataUnsafe: Telegram.WebApp.initDataUnsafe || {},
MainButton: Telegram.WebApp.MainButton,
SecondaryButton: Telegram.WebApp.SecondaryButton,
BackButton: Telegram.WebApp.BackButton,
SettingsButton: Telegram.WebApp.SettingsButton,
init: function(options) {
document.body.style.visibility = '';
Telegram.WebApp.ready();
Telegram.WebApp.MainButton.setParams({
text: 'Close Webview',
has_shine_effect: true,
is_visible: true
}).onClick(DemoApp.close);
Telegram.WebApp.SecondaryButton.setParams({
text: 'Do Something',
is_visible: true
}).onClick(DemoApp.moveSecondaryButton);
Telegram.WebApp.BackButton.onClick(function() {
DemoApp.showAlert('Back button pressed');
});
Telegram.WebApp.SettingsButton.onClick(function() {
DemoApp.showAlert('Settings opened!');
});
},
expand() {
Telegram.WebApp.expand();
},
close() {
Telegram.WebApp.close();
},
toggleMainButton(el) {
const mainButton = Telegram.WebApp.MainButton
if (mainButton.isVisible) {
mainButton.hide()
el.innerHTML = 'Show Main Button'
} else {
mainButton.show()
el.innerHTML = 'Hide Main Button'
}
},
toggleSecondaryButton(el) {
if (DemoApp.SecondaryButton.isVisible) {
DemoApp.SecondaryButton.hide()
el.innerHTML = 'Show Secondary Button'
} else {
DemoApp.SecondaryButton.show();
el.innerHTML = 'Hide Secondary Button'
}
},
toggleButtonsProgress(el) {
if (DemoApp.MainButton.isProgressVisible) {
DemoApp.MainButton.hideProgress()
DemoApp.SecondaryButton.hideProgress()
el.innerHTML = 'Show Progress'
} else {
DemoApp.MainButton.showProgress()
DemoApp.SecondaryButton.showProgress()
el.innerHTML = 'Hide Progress'
}
},
moveSecondaryButton(el) {
const sButton = DemoApp.SecondaryButton
if (sButton.position === 'left') {
sButton.position = 'top'
} else if (sButton.position === 'top') {
sButton.position = 'right'
} else if (sButton.position === 'right') {
sButton.position = 'bottom'
} else if (sButton.position === 'bottom') {
sButton.position = 'left'
}
},
toggleBackButton(el) {
if (DemoApp.BackButton.isVisible) {
DemoApp.BackButton.hide()
el.innerHTML = 'Show Back Button'
} else {
DemoApp.BackButton.show()
el.innerHTML = 'Hide Back Button'
}
},
toggleSettingsButton(el) {
if (DemoApp.SettingsButton.isVisible) {
DemoApp.SettingsButton.hide()
el.innerHTML = 'Show Settings Button'
} else {
DemoApp.SettingsButton.show()
el.innerHTML = 'Hide Settings Button'
}
},
toggleSwipeBehavior(el) {
if (Telegram.WebApp.isVerticalSwipesEnabled) {
Telegram.WebApp.disableVerticalSwipes()
el.innerHTML = 'Enable Vertical Swypes'
} else {
Telegram.WebApp.enableVerticalSwipes()
el.innerHTML = 'Disable Vertical Swypes'
}
},
toggleOrientationLock(el) {
if (Telegram.WebApp.isOrientationLocked) {
Telegram.WebApp.unlockOrientation()
el.innerHTML = 'Lock Orientation'
} else {
Telegram.WebApp.lockOrientation()
el.innerHTML = 'Unlock Orientation'
}
},
fullscreenInit() {
Telegram.WebApp.onEvent('fullscreenChanged', function() {
DemoApp.updateFullscreenButton()
})
Telegram.WebApp.onEvent('fullscreenFailed', function(params) {
DemoApp.showAlert('fullscreenFailed: ' + params.error)
})
DemoApp.updateFullscreenButton()
},
toggleFullscreen(el) {
if (Telegram.WebApp.isFullscreen) {
Telegram.WebApp.exitFullscreen()
} else {
Telegram.WebApp.requestFullscreen()
}
},
updateFullscreenButton() {
const fullscreenBtn = document.getElementById('fullscreen_btn')
if (Telegram.WebApp.isFullscreen) {
fullscreenBtn.innerHTML = 'Exit Fullscreen'
} else {
fullscreenBtn.innerHTML = 'Request Fullscreen'
}
},
// accelerometer
accelerometerInit() {
Telegram.WebApp.onEvent('accelerometerStarted', function() {
const span = document.getElementById('accelerometer_btn').nextElementSibling;
span.textContent = '';
span.className = '';
DemoApp.updateAccelerometerLink();
})
Telegram.WebApp.onEvent('accelerometerStopped', function() {
const span = document.getElementById('accelerometer_btn').nextElementSibling;
span.textContent = '';
span.className = '';
DemoApp.updateAccelerometerLink();
})
Telegram.WebApp.onEvent('accelerometerChanged', function() {
const span = document.getElementById('accelerometer_btn').nextElementSibling;
span.textContent = '(x: ' + this.Accelerometer.x + '; y: ' + this.Accelerometer.y + '; z: ' + this.Accelerometer.z + ')';
span.className = 'ok';
})
Telegram.WebApp.onEvent('accelerometerFailed', function(params) {
const span = document.getElementById('accelerometer_btn').nextElementSibling;
span.textContent = '(ERR: ' + params.error + ')';
span.className = 'err';
})
DemoApp.updateAccelerometerLink()
},
toggleAccelerometer: function(el) {
if (Telegram.WebApp.Accelerometer.isStarted) {
Telegram.WebApp.Accelerometer.stop();
} else {
Telegram.WebApp.Accelerometer.start({ refresh_rate: 100 });
}
},
updateAccelerometerLink() {
var accelerometerBtn = document.getElementById('accelerometer_btn');
if (Telegram.WebApp.Accelerometer.isStarted) {
accelerometerBtn.innerHTML = 'Stop Accelerometer';
} else {
accelerometerBtn.innerHTML = 'Start Accelerometer';
}
},
// device orientation
deviceOrientationInit() {
Telegram.WebApp.onEvent('deviceOrientationStarted', function() {
var span = document.getElementById('device_orientation_btn').nextElementSibling;
span.textContent = '';
span.className = '';
DemoApp.updateDeviceOrientationLink();
})
Telegram.WebApp.onEvent('deviceOrientationStopped', function() {
var span = document.getElementById('device_orientation_btn').nextElementSibling;
span.textContent = '';
span.className = '';
DemoApp.updateDeviceOrientationLink();
})
Telegram.WebApp.onEvent('deviceOrientationChanged', function() {
var span = document.getElementById('device_orientation_btn').nextElementSibling;
span.textContent = '(alpha: ' + this.DeviceOrientation.alpha +
'; beta: ' + this.DeviceOrientation.beta +
'; gamma: ' + this.DeviceOrientation.gamma +
'; absolute: ' + (this.DeviceOrientation.absolute ? 'true' : 'false') + ')';
span.className = 'ok';
})
Telegram.WebApp.onEvent('deviceOrientationFailed', function(params) {
var span = document.getElementById('device_orientation_btn').nextElementSibling;
span.textContent = '(ERR: ' + params.error + ')';
span.className = 'err';
})
DemoApp.updateDeviceOrientationLink()
},
toggleDeviceOrientation(el, need_absolute) {
if (Telegram.WebApp.DeviceOrientation.isStarted) {
Telegram.WebApp.DeviceOrientation.stop();
} else {
Telegram.WebApp.DeviceOrientation.start({ refresh_rate: 100, need_absolute: need_absolute });
}
},
updateDeviceOrientationLink() {
var deviceOrientationBtn = document.getElementById('device_orientation_btn');
var absItem = document.getElementById('device_orientation_abs_item');
if (Telegram.WebApp.DeviceOrientation.isStarted) {
deviceOrientationBtn.innerHTML = 'Stop DeviceOrientation';
absItem.style.display = 'none';
} else {
deviceOrientationBtn.innerHTML = 'Start DeviceOrientation(need_absolute=false)';
absItem.style.display = 'block';
}
},
// gyroscope
gyroscopeInit() {
Telegram.WebApp.onEvent('gyroscopeStarted', function() {
var span = document.getElementById('gyroscope_btn').nextElementSibling;
span.textContent = '';
span.className = '';
DemoApp.updateGyroscopeLink();
})
Telegram.WebApp.onEvent('gyroscopeStopped', function() {
var span = document.getElementById('gyroscope_btn').nextElementSibling;
span.textContent = '';
span.className = '';
DemoApp.updateGyroscopeLink();
})
Telegram.WebApp.onEvent('gyroscopeChanged', function() {
var span = document.getElementById('gyroscope_btn').nextElementSibling;
span.textContent = '(x: ' + this.Gyroscope.x + '; y: ' + this.Gyroscope.y + '; z: ' + this.Gyroscope.z + ')';
span.className = 'ok';
})
Telegram.WebApp.onEvent('gyroscopeFailed', function(params) {
var span = document.getElementById('gyroscope_btn').nextElementSibling;
span.textContent = '(ERR: ' + params.error + ')';
span.className = 'err';
})
DemoApp.updateGyroscopeLink()
},
toggleGyroscope(el) {
if (Telegram.WebApp.Gyroscope.isStarted) {
Telegram.WebApp.Gyroscope.stop();
} else {
Telegram.WebApp.Gyroscope.start({ refresh_rate: 100 });
}
},
updateGyroscopeLink() {
var gyroscopeBtn = document.getElementById('gyroscope_btn');
if (Telegram.WebApp.Gyroscope.isStarted) {
gyroscopeBtn.innerHTML = 'Stop Gyroscope';
} else {
gyroscopeBtn.innerHTML = 'Start Gyroscope';
}
},
// location
locationInit(el) {
const locationManager = Telegram.WebApp.LocationManager;
if (!DemoApp.locationInited) {
DemoApp.locationInited = true;
Telegram.WebApp.onEvent('locationManagerUpdated', function() {
document.getElementById('loc_inited').textContent = locationManager.isInited ? 'true' : 'false';
document.getElementById('loc_available').textContent = locationManager.isLocationAvailable ? 'true' : 'false';
document.getElementById('loc_access_requested').textContent = locationManager.isAccessRequested ? 'true' : 'false';
document.getElementById('loc_access_granted').textContent = locationManager.isAccessGranted ? 'true' : 'false';
document.getElementById('loc_settings').style.display = (locationManager.isLocationAvailable && locationManager.isAccessRequested && !locationManager.isAccessGranted) ? 'block' : 'none';
});
}
locationManager.init();
},
locationGet(el) {
const locationManager = Telegram.WebApp.LocationManager;
if (!locationManager.isInited) {
return DemoApp.showAlert('Location not inited yet!');
}
locationManager.getLocation(function(location_data) {
const span = el.nextElementSibling;
if (location_data) {
span.textContent = '(' + JSON.stringify(location_data) + ')';
span.className = 'ok';
} else {
span.textContent = '(Request declined)';
span.className = 'err';
}
})
},
locationOpenSettings(el) {
const locationManager = Telegram.WebApp.LocationManager;
if (!locationManager.isInited) {
return DemoApp.showAlert('Location not inited yet!');
}
if (!locationManager.isLocationAvailable || !locationManager.isAccessRequested || locationManager.isAccessGranted) {
return false;
}
locationManager.openSettings();
},
// version to string Example: '6.9'
doesntSupport(version) {
// console.log("version: " + version);
// console.log("realVersion: " + this.version());
// console.log("doesntSupport: " + this.isVersionAtLeast(version));
if (!this.isVersionAtLeast(version)) {
Telegram.WebApp.showAlert('This feature is not supported in this version of Telegram', function () {
Telegram.WebApp.close();
});
throw new Error('This feature is not supported in this version of Telegram');
}
},
// actions
sendMessage(msg_id, with_webview) {
if (!DemoApp.initDataUnsafe.query_id) {
alert('WebViewQueryId not defined');
return;
}
document.querySelectorAll('button').forEach((btn) => btn.disabled = true);
const btn = document.querySelector('#btn_status');
btn.textContent = 'Sending...';
DemoApp.apiRequest('sendMessage', {
msg_id : msg_id || '',
with_webview: !DemoApp.initDataUnsafe.receiver && with_webview ? 1 : 0
}, function (result) {
document.querySelectorAll('button').forEach((btn) => btn.disabled = false);
if (result.response) {
if (result.response.ok) {
btn.textContent = 'Message sent successfully!';
btn.className = 'ok';
btn.style.display = 'block';
} else {
btn.textContent = result.response.description;
btn.className = 'err';
btn.style.display = 'block';
alert(result.response.description);
}
} else if (result.error) {
btn.textContent = result.error;
btn.className = 'err';
btn.style.display = 'block';
alert(result.error);
} else {
btn.textContent = 'Unknown error';
btn.className = 'err';
btn.style.display = 'block';
alert('Unknown error');
}
});
},
changeMenuButton(close) {
document.querySelectorAll('button').forEach((btn) => btn.disabled = true);
const btnStatus = document.querySelector('#btn_status');
btnStatus.textContent = 'Changing button...';
DemoApp.apiRequest('changeMenuButton', {}, function (result) {
document.querySelectorAll('button').forEach((btn) => btn.disabled = false);
if (result.response) {
if (result.response.ok) {
btnStatus.textContent = 'Button changed!';
btnStatus.className = 'ok';
btnStatus.style.display = 'block';
Telegram.WebApp.close();
} else {
btnStatus.textContent = result.response.description;