Skip to content

Commit

Permalink
feat(message): adjust after schema update
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Apr 27, 2024
1 parent 5e9deca commit d0e0d00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
17 changes: 12 additions & 5 deletions telegram/message/poll.go
Expand Up @@ -28,24 +28,24 @@ func RawPollAnswer(poll tg.PollAnswer) PollAnswerOption {
}

// PollAnswer creates new plain poll answer option.
func PollAnswer(text string) PollAnswerOption {
func PollAnswer(text string, entities ...tg.MessageEntityClass) PollAnswerOption {
return func(p *pollAnswerBuilder) {
i := len(p.input.Poll.Answers)
p.input.Poll.Answers = append(p.input.Poll.Answers, tg.PollAnswer{
Text: text,
Text: tg.TextWithEntities{Text: text, Entities: entities},
Option: []byte(strconv.Itoa(i)),
})
}
}

// CorrectPollAnswer creates new correct poll answer option.
func CorrectPollAnswer(text string) PollAnswerOption {
func CorrectPollAnswer(text string, entities ...tg.MessageEntityClass) PollAnswerOption {
return func(p *pollAnswerBuilder) {
p.input.Poll.Quiz = true
i := len(p.input.Poll.Answers)
option := []byte(strconv.Itoa(i))
p.input.Poll.Answers = append(p.input.Poll.Answers, tg.PollAnswer{
Text: text,
Text: tg.TextWithEntities{Text: text, Entities: entities},
Option: option,
})
p.input.CorrectAnswers = append(p.input.CorrectAnswers, option)
Expand Down Expand Up @@ -148,12 +148,19 @@ func (p *PollBuilder) apply(ctx context.Context, b *multiMediaBuilder) error {
return Media(&p.input).apply(ctx, b)
}

func (p *PollBuilder) QuestionEntities(entities []tg.MessageEntityClass) *PollBuilder {
p.input.Poll.Question.Entities = entities
return p
}

// Poll adds poll attachment.
//
// To set poll question entities, use [QuestionEntities](#PollBuilder.QuestionEntities).
func Poll(question string, a, b PollAnswerOption, answers ...PollAnswerOption) *PollBuilder {
return &PollBuilder{
input: tg.InputMediaPoll{
Poll: tg.Poll{
Question: question,
Question: tg.TextWithEntities{Text: question},
},
},
answers: append([]PollAnswerOption{a, b}, answers...),
Expand Down
8 changes: 6 additions & 2 deletions telegram/message/poll_test.go
Expand Up @@ -43,11 +43,15 @@ func TestPoll(t *testing.T) {
CorrectPollAnswer("A?"),
PollAnswer("Che?"),
PollAnswer("Kuda?"),
).PublicVoters(true).
).
PublicVoters(true).
StyledExplanation(
styling.Plain("See"),
styling.TextURL("https://youtu.be/PYzX7SDKhd0.", "https://youtu.be/PYzX7SDKhd0"),
)
).
QuestionEntities([]tg.MessageEntityClass{
&tg.MessageEntityEmail{Offset: 0, Length: 128},
})

_, err := sender.Self().Media(ctx, poll)
require.NoError(t, err)
Expand Down

0 comments on commit d0e0d00

Please sign in to comment.