Skip to content

Commit

Permalink
Added more setters & utility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mymmrac committed Feb 2, 2022
1 parent fef2396 commit 4facbed
Show file tree
Hide file tree
Showing 6 changed files with 546 additions and 22 deletions.
14 changes: 6 additions & 8 deletions examples/inline_query_bot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@ func main() {
tu.ResultArticle(
"hello",
"Hello",
&telego.InputTextMessageContent{ // Hello message with inline query
ParseMode: telego.ModeMarkdownV2,
MessageText: fmt.Sprintf("Hello %s\n\nYour query:\n```%#+v```", name, iq),
},
tu.TextMessage( // Hello message with inline query
fmt.Sprintf("Hello %s\n\nYour query:\n```%#+v```", name, iq),
).WithParseMode(telego.ModeMarkdownV2),
).WithDescription(fmt.Sprintf("Query: %q", iq.Query)),

tu.ResultArticle(
"bey",
"Bye",
&telego.InputTextMessageContent{ // Bye message with inline query
ParseMode: telego.ModeMarkdownV2,
MessageText: fmt.Sprintf("Bye %s\n\nYour query:\n```%#+v```", name, iq),
},
tu.TextMessage( // Bye message with inline query
fmt.Sprintf("Bye %s\n\nYour query:\n```%#+v```", name, iq),
).WithParseMode(telego.ModeMarkdownV2),
).WithDescription(fmt.Sprintf("Query: %q", iq.Query)),
).WithIsPersonal())
}
Expand Down
18 changes: 5 additions & 13 deletions examples/sending_files/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,15 @@ func main() {
// =========================================== //

// Media group parameters
// TODO: Update this example
mediaGroup := tu.MediaGroup(
tu.ID(1234567),

// Specify slice of telego.InputMedia with media you want to send as a group
&telego.InputMediaPhoto{
Type: telego.MediaTypePhoto,
Media: tu.FileByURL("https://example.com/my_photo.png"),
},
&telego.InputMediaPhoto{
Type: telego.MediaTypePhoto,
Media: tu.File(mustOpen("my_photo.png")),
},
&telego.InputMediaPhoto{
Type: telego.MediaTypePhoto,
Media: tu.FileByID("<file ID of your photo>"),
},
tu.MediaPhoto(tu.File(mustOpen("my_photo.png"))),

tu.MediaPhoto(tu.FileByID("<file ID of your photo>")),

tu.MediaPhoto(tu.FileByURL("https://example.com/my_photo.png")),
)

// Sending media group
Expand Down
12 changes: 12 additions & 0 deletions internal/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ var typeStructsSetters = []string{
"InlineQueryResultVenue",
"InlineQueryResultVideo",
"InlineQueryResultVoice",

"InputMediaAnimation",
"InputMediaDocument",
"InputMediaAudio",
"InputMediaPhoto",
"InputMediaVideo",

"InputTextMessageContent",
"InputLocationMessageContent",
"InputVenueMessageContent",
"InputContactMessageContent",
"InputInvoiceMessageContent",
}

var typeStructsNoPointerSetters = []string{
Expand Down
4 changes: 3 additions & 1 deletion internal/generator/setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func generateSetters(typesData string, desiredStructs []string) tgSetters {
fieldType: fieldsGroup[2],
}

if strings.HasPrefix(setter.structType, "InlineQueryResult") && setter.fieldName == "Type" {
if (strings.HasPrefix(setter.structType, "InlineQueryResult") ||
strings.HasPrefix(setter.structType, "InputMedia")) &&
setter.fieldName == "Type" {
continue
}

Expand Down
86 changes: 86 additions & 0 deletions telegoutil/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,89 @@ func ResultVoice(id, voiceURL, title string) *telego.InlineQueryResultVoice {
Title: title,
}
}

// TextMessage creates telego.InputTextMessageContent with required fields
func TextMessage(messageText string) *telego.InputTextMessageContent {
return &telego.InputTextMessageContent{
MessageText: messageText,
}
}

// LocationMessage creates telego.InputLocationMessageContent with required fields
func LocationMessage(latitude, longitude float64) *telego.InputLocationMessageContent {
return &telego.InputLocationMessageContent{
Latitude: latitude,
Longitude: longitude,
}
}

// VenueMessage creates telego.InputVenueMessageContent with required fields
func VenueMessage(latitude, longitude float64, title, address string) *telego.InputVenueMessageContent {
return &telego.InputVenueMessageContent{
Latitude: latitude,
Longitude: longitude,
Title: title,
Address: address,
}
}

// ContactMessage creates telego.InputContactMessageContent with required fields
func ContactMessage(phoneNumber, firstName string) *telego.InputContactMessageContent {
return &telego.InputContactMessageContent{
PhoneNumber: phoneNumber,
FirstName: firstName,
}
}

// InvoiceMessage creates telego.InputInvoiceMessageContent with required fields
func InvoiceMessage(title, description, payload, providerToken, currency string, prices ...telego.LabeledPrice,
) *telego.InputInvoiceMessageContent {
return &telego.InputInvoiceMessageContent{
Title: title,
Description: description,
Payload: payload,
ProviderToken: providerToken,
Currency: currency,
Prices: prices,
}
}

// MediaAnimation creates telego.InputMediaAnimation with required fields
func MediaAnimation(media telego.InputFile) *telego.InputMediaAnimation {
return &telego.InputMediaAnimation{
Type: telego.MediaTypeAnimation,
Media: media,
}
}

// MediaDocument creates telego.InputMediaDocument with required fields
func MediaDocument(media telego.InputFile) *telego.InputMediaDocument {
return &telego.InputMediaDocument{
Type: telego.MediaTypeDocument,
Media: media,
}
}

// MediaAudio creates telego.InputMediaAudio with required fields
func MediaAudio(media telego.InputFile) *telego.InputMediaAudio {
return &telego.InputMediaAudio{
Type: telego.MediaTypeAudio,
Media: media,
}
}

// MediaPhoto creates telego.InputMediaPhoto with required fields
func MediaPhoto(media telego.InputFile) *telego.InputMediaPhoto {
return &telego.InputMediaPhoto{
Type: telego.MediaTypePhoto,
Media: media,
}
}

// MediaVideo creates telego.InputMediaVideo with required fields
func MediaVideo(media telego.InputFile) *telego.InputMediaVideo {
return &telego.InputMediaVideo{
Type: telego.MediaTypeVideo,
Media: media,
}
}
Loading

0 comments on commit 4facbed

Please sign in to comment.