This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
forked from Arman92/go-tdlib
/
richText.go
958 lines (797 loc) · 25.3 KB
/
richText.go
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
package tdlib
import (
"encoding/json"
"fmt"
)
// RichText Describes a text object inside an instant-view web page
type RichText interface {
GetRichTextEnum() RichTextEnum
}
// RichTextEnum Alias for abstract RichText 'Sub-Classes', used as constant-enum here
type RichTextEnum string
// RichText enums
const (
RichTextPlainType RichTextEnum = "richTextPlain"
RichTextBoldType RichTextEnum = "richTextBold"
RichTextItalicType RichTextEnum = "richTextItalic"
RichTextUnderlineType RichTextEnum = "richTextUnderline"
RichTextStrikethroughType RichTextEnum = "richTextStrikethrough"
RichTextFixedType RichTextEnum = "richTextFixed"
RichTextUrlType RichTextEnum = "richTextUrl"
RichTextEmailAddressType RichTextEnum = "richTextEmailAddress"
RichTextSubscriptType RichTextEnum = "richTextSubscript"
RichTextSuperscriptType RichTextEnum = "richTextSuperscript"
RichTextMarkedType RichTextEnum = "richTextMarked"
RichTextPhoneNumberType RichTextEnum = "richTextPhoneNumber"
RichTextIconType RichTextEnum = "richTextIcon"
RichTextReferenceType RichTextEnum = "richTextReference"
RichTextAnchorType RichTextEnum = "richTextAnchor"
RichTextAnchorLinkType RichTextEnum = "richTextAnchorLink"
RichTextsType RichTextEnum = "richTexts"
)
func unmarshalRichText(rawMsg *json.RawMessage) (RichText, error) {
if rawMsg == nil {
return nil, nil
}
var objMap map[string]interface{}
err := json.Unmarshal(*rawMsg, &objMap)
if err != nil {
return nil, err
}
switch RichTextEnum(objMap["@type"].(string)) {
case RichTextPlainType:
var richTextPlain RichTextPlain
err := json.Unmarshal(*rawMsg, &richTextPlain)
return &richTextPlain, err
case RichTextBoldType:
var richTextBold RichTextBold
err := json.Unmarshal(*rawMsg, &richTextBold)
return &richTextBold, err
case RichTextItalicType:
var richTextItalic RichTextItalic
err := json.Unmarshal(*rawMsg, &richTextItalic)
return &richTextItalic, err
case RichTextUnderlineType:
var richTextUnderline RichTextUnderline
err := json.Unmarshal(*rawMsg, &richTextUnderline)
return &richTextUnderline, err
case RichTextStrikethroughType:
var richTextStrikethrough RichTextStrikethrough
err := json.Unmarshal(*rawMsg, &richTextStrikethrough)
return &richTextStrikethrough, err
case RichTextFixedType:
var richTextFixed RichTextFixed
err := json.Unmarshal(*rawMsg, &richTextFixed)
return &richTextFixed, err
case RichTextUrlType:
var richTextUrl RichTextUrl
err := json.Unmarshal(*rawMsg, &richTextUrl)
return &richTextUrl, err
case RichTextEmailAddressType:
var richTextEmailAddress RichTextEmailAddress
err := json.Unmarshal(*rawMsg, &richTextEmailAddress)
return &richTextEmailAddress, err
case RichTextSubscriptType:
var richTextSubscript RichTextSubscript
err := json.Unmarshal(*rawMsg, &richTextSubscript)
return &richTextSubscript, err
case RichTextSuperscriptType:
var richTextSuperscript RichTextSuperscript
err := json.Unmarshal(*rawMsg, &richTextSuperscript)
return &richTextSuperscript, err
case RichTextMarkedType:
var richTextMarked RichTextMarked
err := json.Unmarshal(*rawMsg, &richTextMarked)
return &richTextMarked, err
case RichTextPhoneNumberType:
var richTextPhoneNumber RichTextPhoneNumber
err := json.Unmarshal(*rawMsg, &richTextPhoneNumber)
return &richTextPhoneNumber, err
case RichTextIconType:
var richTextIcon RichTextIcon
err := json.Unmarshal(*rawMsg, &richTextIcon)
return &richTextIcon, err
case RichTextReferenceType:
var richTextReference RichTextReference
err := json.Unmarshal(*rawMsg, &richTextReference)
return &richTextReference, err
case RichTextAnchorType:
var richTextAnchor RichTextAnchor
err := json.Unmarshal(*rawMsg, &richTextAnchor)
return &richTextAnchor, err
case RichTextAnchorLinkType:
var richTextAnchorLink RichTextAnchorLink
err := json.Unmarshal(*rawMsg, &richTextAnchorLink)
return &richTextAnchorLink, err
case RichTextsType:
var richTexts RichTexts
err := json.Unmarshal(*rawMsg, &richTexts)
return &richTexts, err
default:
return nil, fmt.Errorf("Error UnMarshaling, unknown type:" + objMap["@type"].(string))
}
}
// RichTextPlain A plain text
type RichTextPlain struct {
tdCommon
Text string `json:"text"` // Text
}
// MessageType return the string telegram-type of RichTextPlain
func (richTextPlain *RichTextPlain) MessageType() string {
return "richTextPlain"
}
// NewRichTextPlain creates a new RichTextPlain
//
// @param text Text
func NewRichTextPlain(text string) *RichTextPlain {
richTextPlainTemp := RichTextPlain{
tdCommon: tdCommon{Type: "richTextPlain"},
Text: text,
}
return &richTextPlainTemp
}
// GetRichTextEnum return the enum type of this object
func (richTextPlain *RichTextPlain) GetRichTextEnum() RichTextEnum {
return RichTextPlainType
}
// RichTextBold A bold rich text
type RichTextBold struct {
tdCommon
Text RichText `json:"text"` // Text
}
// MessageType return the string telegram-type of RichTextBold
func (richTextBold *RichTextBold) MessageType() string {
return "richTextBold"
}
// NewRichTextBold creates a new RichTextBold
//
// @param text Text
func NewRichTextBold(text RichText) *RichTextBold {
richTextBoldTemp := RichTextBold{
tdCommon: tdCommon{Type: "richTextBold"},
Text: text,
}
return &richTextBoldTemp
}
// UnmarshalJSON unmarshal to json
func (richTextBold *RichTextBold) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextBold.tdCommon = tempObj.tdCommon
fieldText, _ := unmarshalRichText(objMap["text"])
richTextBold.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextBold *RichTextBold) GetRichTextEnum() RichTextEnum {
return RichTextBoldType
}
// RichTextItalic An italicized rich text
type RichTextItalic struct {
tdCommon
Text RichText `json:"text"` // Text
}
// MessageType return the string telegram-type of RichTextItalic
func (richTextItalic *RichTextItalic) MessageType() string {
return "richTextItalic"
}
// NewRichTextItalic creates a new RichTextItalic
//
// @param text Text
func NewRichTextItalic(text RichText) *RichTextItalic {
richTextItalicTemp := RichTextItalic{
tdCommon: tdCommon{Type: "richTextItalic"},
Text: text,
}
return &richTextItalicTemp
}
// UnmarshalJSON unmarshal to json
func (richTextItalic *RichTextItalic) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextItalic.tdCommon = tempObj.tdCommon
fieldText, _ := unmarshalRichText(objMap["text"])
richTextItalic.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextItalic *RichTextItalic) GetRichTextEnum() RichTextEnum {
return RichTextItalicType
}
// RichTextUnderline An underlined rich text
type RichTextUnderline struct {
tdCommon
Text RichText `json:"text"` // Text
}
// MessageType return the string telegram-type of RichTextUnderline
func (richTextUnderline *RichTextUnderline) MessageType() string {
return "richTextUnderline"
}
// NewRichTextUnderline creates a new RichTextUnderline
//
// @param text Text
func NewRichTextUnderline(text RichText) *RichTextUnderline {
richTextUnderlineTemp := RichTextUnderline{
tdCommon: tdCommon{Type: "richTextUnderline"},
Text: text,
}
return &richTextUnderlineTemp
}
// UnmarshalJSON unmarshal to json
func (richTextUnderline *RichTextUnderline) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextUnderline.tdCommon = tempObj.tdCommon
fieldText, _ := unmarshalRichText(objMap["text"])
richTextUnderline.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextUnderline *RichTextUnderline) GetRichTextEnum() RichTextEnum {
return RichTextUnderlineType
}
// RichTextStrikethrough A strikethrough rich text
type RichTextStrikethrough struct {
tdCommon
Text RichText `json:"text"` // Text
}
// MessageType return the string telegram-type of RichTextStrikethrough
func (richTextStrikethrough *RichTextStrikethrough) MessageType() string {
return "richTextStrikethrough"
}
// NewRichTextStrikethrough creates a new RichTextStrikethrough
//
// @param text Text
func NewRichTextStrikethrough(text RichText) *RichTextStrikethrough {
richTextStrikethroughTemp := RichTextStrikethrough{
tdCommon: tdCommon{Type: "richTextStrikethrough"},
Text: text,
}
return &richTextStrikethroughTemp
}
// UnmarshalJSON unmarshal to json
func (richTextStrikethrough *RichTextStrikethrough) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextStrikethrough.tdCommon = tempObj.tdCommon
fieldText, _ := unmarshalRichText(objMap["text"])
richTextStrikethrough.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextStrikethrough *RichTextStrikethrough) GetRichTextEnum() RichTextEnum {
return RichTextStrikethroughType
}
// RichTextFixed A fixed-width rich text
type RichTextFixed struct {
tdCommon
Text RichText `json:"text"` // Text
}
// MessageType return the string telegram-type of RichTextFixed
func (richTextFixed *RichTextFixed) MessageType() string {
return "richTextFixed"
}
// NewRichTextFixed creates a new RichTextFixed
//
// @param text Text
func NewRichTextFixed(text RichText) *RichTextFixed {
richTextFixedTemp := RichTextFixed{
tdCommon: tdCommon{Type: "richTextFixed"},
Text: text,
}
return &richTextFixedTemp
}
// UnmarshalJSON unmarshal to json
func (richTextFixed *RichTextFixed) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextFixed.tdCommon = tempObj.tdCommon
fieldText, _ := unmarshalRichText(objMap["text"])
richTextFixed.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextFixed *RichTextFixed) GetRichTextEnum() RichTextEnum {
return RichTextFixedType
}
// RichTextUrl A rich text URL link
type RichTextUrl struct {
tdCommon
Text RichText `json:"text"` // Text
Url string `json:"url"` // URL
IsCached bool `json:"is_cached"` // True, if the URL has cached instant view server-side
}
// MessageType return the string telegram-type of RichTextUrl
func (richTextUrl *RichTextUrl) MessageType() string {
return "richTextUrl"
}
// NewRichTextUrl creates a new RichTextUrl
//
// @param text Text
// @param url URL
// @param isCached True, if the URL has cached instant view server-side
func NewRichTextUrl(text RichText, url string, isCached bool) *RichTextUrl {
richTextUrlTemp := RichTextUrl{
tdCommon: tdCommon{Type: "richTextUrl"},
Text: text,
Url: url,
IsCached: isCached,
}
return &richTextUrlTemp
}
// UnmarshalJSON unmarshal to json
func (richTextUrl *RichTextUrl) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
Url string `json:"url"` // URL
IsCached bool `json:"is_cached"` // True, if the URL has cached instant view server-side
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextUrl.tdCommon = tempObj.tdCommon
richTextUrl.Url = tempObj.Url
richTextUrl.IsCached = tempObj.IsCached
fieldText, _ := unmarshalRichText(objMap["text"])
richTextUrl.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextUrl *RichTextUrl) GetRichTextEnum() RichTextEnum {
return RichTextUrlType
}
// RichTextEmailAddress A rich text email link
type RichTextEmailAddress struct {
tdCommon
Text RichText `json:"text"` // Text
EmailAddress string `json:"email_address"` // Email address
}
// MessageType return the string telegram-type of RichTextEmailAddress
func (richTextEmailAddress *RichTextEmailAddress) MessageType() string {
return "richTextEmailAddress"
}
// NewRichTextEmailAddress creates a new RichTextEmailAddress
//
// @param text Text
// @param emailAddress Email address
func NewRichTextEmailAddress(text RichText, emailAddress string) *RichTextEmailAddress {
richTextEmailAddressTemp := RichTextEmailAddress{
tdCommon: tdCommon{Type: "richTextEmailAddress"},
Text: text,
EmailAddress: emailAddress,
}
return &richTextEmailAddressTemp
}
// UnmarshalJSON unmarshal to json
func (richTextEmailAddress *RichTextEmailAddress) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
EmailAddress string `json:"email_address"` // Email address
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextEmailAddress.tdCommon = tempObj.tdCommon
richTextEmailAddress.EmailAddress = tempObj.EmailAddress
fieldText, _ := unmarshalRichText(objMap["text"])
richTextEmailAddress.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextEmailAddress *RichTextEmailAddress) GetRichTextEnum() RichTextEnum {
return RichTextEmailAddressType
}
// RichTextSubscript A subscript rich text
type RichTextSubscript struct {
tdCommon
Text RichText `json:"text"` // Text
}
// MessageType return the string telegram-type of RichTextSubscript
func (richTextSubscript *RichTextSubscript) MessageType() string {
return "richTextSubscript"
}
// NewRichTextSubscript creates a new RichTextSubscript
//
// @param text Text
func NewRichTextSubscript(text RichText) *RichTextSubscript {
richTextSubscriptTemp := RichTextSubscript{
tdCommon: tdCommon{Type: "richTextSubscript"},
Text: text,
}
return &richTextSubscriptTemp
}
// UnmarshalJSON unmarshal to json
func (richTextSubscript *RichTextSubscript) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextSubscript.tdCommon = tempObj.tdCommon
fieldText, _ := unmarshalRichText(objMap["text"])
richTextSubscript.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextSubscript *RichTextSubscript) GetRichTextEnum() RichTextEnum {
return RichTextSubscriptType
}
// RichTextSuperscript A superscript rich text
type RichTextSuperscript struct {
tdCommon
Text RichText `json:"text"` // Text
}
// MessageType return the string telegram-type of RichTextSuperscript
func (richTextSuperscript *RichTextSuperscript) MessageType() string {
return "richTextSuperscript"
}
// NewRichTextSuperscript creates a new RichTextSuperscript
//
// @param text Text
func NewRichTextSuperscript(text RichText) *RichTextSuperscript {
richTextSuperscriptTemp := RichTextSuperscript{
tdCommon: tdCommon{Type: "richTextSuperscript"},
Text: text,
}
return &richTextSuperscriptTemp
}
// UnmarshalJSON unmarshal to json
func (richTextSuperscript *RichTextSuperscript) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextSuperscript.tdCommon = tempObj.tdCommon
fieldText, _ := unmarshalRichText(objMap["text"])
richTextSuperscript.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextSuperscript *RichTextSuperscript) GetRichTextEnum() RichTextEnum {
return RichTextSuperscriptType
}
// RichTextMarked A marked rich text
type RichTextMarked struct {
tdCommon
Text RichText `json:"text"` // Text
}
// MessageType return the string telegram-type of RichTextMarked
func (richTextMarked *RichTextMarked) MessageType() string {
return "richTextMarked"
}
// NewRichTextMarked creates a new RichTextMarked
//
// @param text Text
func NewRichTextMarked(text RichText) *RichTextMarked {
richTextMarkedTemp := RichTextMarked{
tdCommon: tdCommon{Type: "richTextMarked"},
Text: text,
}
return &richTextMarkedTemp
}
// UnmarshalJSON unmarshal to json
func (richTextMarked *RichTextMarked) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextMarked.tdCommon = tempObj.tdCommon
fieldText, _ := unmarshalRichText(objMap["text"])
richTextMarked.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextMarked *RichTextMarked) GetRichTextEnum() RichTextEnum {
return RichTextMarkedType
}
// RichTextPhoneNumber A rich text phone number
type RichTextPhoneNumber struct {
tdCommon
Text RichText `json:"text"` // Text
PhoneNumber string `json:"phone_number"` // Phone number
}
// MessageType return the string telegram-type of RichTextPhoneNumber
func (richTextPhoneNumber *RichTextPhoneNumber) MessageType() string {
return "richTextPhoneNumber"
}
// NewRichTextPhoneNumber creates a new RichTextPhoneNumber
//
// @param text Text
// @param phoneNumber Phone number
func NewRichTextPhoneNumber(text RichText, phoneNumber string) *RichTextPhoneNumber {
richTextPhoneNumberTemp := RichTextPhoneNumber{
tdCommon: tdCommon{Type: "richTextPhoneNumber"},
Text: text,
PhoneNumber: phoneNumber,
}
return &richTextPhoneNumberTemp
}
// UnmarshalJSON unmarshal to json
func (richTextPhoneNumber *RichTextPhoneNumber) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
PhoneNumber string `json:"phone_number"` // Phone number
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextPhoneNumber.tdCommon = tempObj.tdCommon
richTextPhoneNumber.PhoneNumber = tempObj.PhoneNumber
fieldText, _ := unmarshalRichText(objMap["text"])
richTextPhoneNumber.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextPhoneNumber *RichTextPhoneNumber) GetRichTextEnum() RichTextEnum {
return RichTextPhoneNumberType
}
// RichTextIcon A small image inside the text
type RichTextIcon struct {
tdCommon
Document *Document `json:"document"` // The image represented as a document. The image can be in GIF, JPEG or PNG format
Width int32 `json:"width"` // Width of a bounding box in which the image must be shown; 0 if unknown
Height int32 `json:"height"` // Height of a bounding box in which the image must be shown; 0 if unknown
}
// MessageType return the string telegram-type of RichTextIcon
func (richTextIcon *RichTextIcon) MessageType() string {
return "richTextIcon"
}
// NewRichTextIcon creates a new RichTextIcon
//
// @param document The image represented as a document. The image can be in GIF, JPEG or PNG format
// @param width Width of a bounding box in which the image must be shown; 0 if unknown
// @param height Height of a bounding box in which the image must be shown; 0 if unknown
func NewRichTextIcon(document *Document, width int32, height int32) *RichTextIcon {
richTextIconTemp := RichTextIcon{
tdCommon: tdCommon{Type: "richTextIcon"},
Document: document,
Width: width,
Height: height,
}
return &richTextIconTemp
}
// GetRichTextEnum return the enum type of this object
func (richTextIcon *RichTextIcon) GetRichTextEnum() RichTextEnum {
return RichTextIconType
}
// RichTextReference A reference to a richTexts object on the same web page
type RichTextReference struct {
tdCommon
Text RichText `json:"text"` // The text
AnchorName string `json:"anchor_name"` // The name of a richTextAnchor object, which is the first element of the target richTexts object
Url string `json:"url"` // An HTTP URL, opening the reference
}
// MessageType return the string telegram-type of RichTextReference
func (richTextReference *RichTextReference) MessageType() string {
return "richTextReference"
}
// NewRichTextReference creates a new RichTextReference
//
// @param text The text
// @param anchorName The name of a richTextAnchor object, which is the first element of the target richTexts object
// @param url An HTTP URL, opening the reference
func NewRichTextReference(text RichText, anchorName string, url string) *RichTextReference {
richTextReferenceTemp := RichTextReference{
tdCommon: tdCommon{Type: "richTextReference"},
Text: text,
AnchorName: anchorName,
Url: url,
}
return &richTextReferenceTemp
}
// UnmarshalJSON unmarshal to json
func (richTextReference *RichTextReference) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
AnchorName string `json:"anchor_name"` // The name of a richTextAnchor object, which is the first element of the target richTexts object
Url string `json:"url"` // An HTTP URL, opening the reference
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextReference.tdCommon = tempObj.tdCommon
richTextReference.AnchorName = tempObj.AnchorName
richTextReference.Url = tempObj.Url
fieldText, _ := unmarshalRichText(objMap["text"])
richTextReference.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextReference *RichTextReference) GetRichTextEnum() RichTextEnum {
return RichTextReferenceType
}
// RichTextAnchor An anchor
type RichTextAnchor struct {
tdCommon
Name string `json:"name"` // Anchor name
}
// MessageType return the string telegram-type of RichTextAnchor
func (richTextAnchor *RichTextAnchor) MessageType() string {
return "richTextAnchor"
}
// NewRichTextAnchor creates a new RichTextAnchor
//
// @param name Anchor name
func NewRichTextAnchor(name string) *RichTextAnchor {
richTextAnchorTemp := RichTextAnchor{
tdCommon: tdCommon{Type: "richTextAnchor"},
Name: name,
}
return &richTextAnchorTemp
}
// GetRichTextEnum return the enum type of this object
func (richTextAnchor *RichTextAnchor) GetRichTextEnum() RichTextEnum {
return RichTextAnchorType
}
// RichTextAnchorLink A link to an anchor on the same web page
type RichTextAnchorLink struct {
tdCommon
Text RichText `json:"text"` // The link text
AnchorName string `json:"anchor_name"` // The anchor name. If the name is empty, the link must bring back to top
Url string `json:"url"` // An HTTP URL, opening the anchor
}
// MessageType return the string telegram-type of RichTextAnchorLink
func (richTextAnchorLink *RichTextAnchorLink) MessageType() string {
return "richTextAnchorLink"
}
// NewRichTextAnchorLink creates a new RichTextAnchorLink
//
// @param text The link text
// @param anchorName The anchor name. If the name is empty, the link must bring back to top
// @param url An HTTP URL, opening the anchor
func NewRichTextAnchorLink(text RichText, anchorName string, url string) *RichTextAnchorLink {
richTextAnchorLinkTemp := RichTextAnchorLink{
tdCommon: tdCommon{Type: "richTextAnchorLink"},
Text: text,
AnchorName: anchorName,
Url: url,
}
return &richTextAnchorLinkTemp
}
// UnmarshalJSON unmarshal to json
func (richTextAnchorLink *RichTextAnchorLink) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
AnchorName string `json:"anchor_name"` // The anchor name. If the name is empty, the link must bring back to top
Url string `json:"url"` // An HTTP URL, opening the anchor
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
richTextAnchorLink.tdCommon = tempObj.tdCommon
richTextAnchorLink.AnchorName = tempObj.AnchorName
richTextAnchorLink.Url = tempObj.Url
fieldText, _ := unmarshalRichText(objMap["text"])
richTextAnchorLink.Text = fieldText
return nil
}
// GetRichTextEnum return the enum type of this object
func (richTextAnchorLink *RichTextAnchorLink) GetRichTextEnum() RichTextEnum {
return RichTextAnchorLinkType
}
// RichTexts A concatenation of rich texts
type RichTexts struct {
tdCommon
Texts []RichText `json:"texts"` // Texts
}
// MessageType return the string telegram-type of RichTexts
func (richTexts *RichTexts) MessageType() string {
return "richTexts"
}
// NewRichTexts creates a new RichTexts
//
// @param texts Texts
func NewRichTexts(texts []RichText) *RichTexts {
richTextsTemp := RichTexts{
tdCommon: tdCommon{Type: "richTexts"},
Texts: texts,
}
return &richTextsTemp
}
// GetRichTextEnum return the enum type of this object
func (richTexts *RichTexts) GetRichTextEnum() RichTextEnum {
return RichTextsType
}