размещения ручки
This commit is contained in:
@@ -3,7 +3,6 @@ package screens
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -1425,7 +1424,7 @@ func (s *PurchaseOptionalDetails) createPurchase(b *bot.Bot, jwt string) {
|
||||
}
|
||||
|
||||
input := backend.CreatePlacementsInput{
|
||||
CreativeID: s.CreativeID,
|
||||
CreativeID: &s.CreativeID,
|
||||
Channels: apiChannels,
|
||||
Details: placementDetails,
|
||||
}
|
||||
@@ -1439,20 +1438,24 @@ func (s *PurchaseOptionalDetails) createPurchase(b *bot.Bot, jwt string) {
|
||||
return
|
||||
}
|
||||
|
||||
creative, err := b.Backend.GetCreative(context.Background(), jwt, b.Session.WorkspaceID, s.CreativeID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get creative")
|
||||
creative = nil
|
||||
}
|
||||
|
||||
if creative != nil {
|
||||
for _, placement := range placements.Placements {
|
||||
channelName := s.formatChannelName(placement)
|
||||
header := fmt.Sprintf("<b>Канал:</b> %s", channelName)
|
||||
b.SendMessage(header, b.ChatID, &echotron.MessageOptions{ParseMode: echotron.HTML})
|
||||
|
||||
s.sendCreativeWithInviteLink(b, creative, placement.InviteLink)
|
||||
for _, placement := range placements.Placements {
|
||||
creativePreview, err := b.Backend.BuildPlacementCreative(
|
||||
context.Background(),
|
||||
jwt,
|
||||
b.Session.WorkspaceID,
|
||||
s.ProjectID,
|
||||
placement.ID,
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to build placement creative")
|
||||
continue
|
||||
}
|
||||
|
||||
channelName := s.formatChannelName(placement)
|
||||
header := fmt.Sprintf("<b>Канал:</b> %s", channelName)
|
||||
b.SendMessage(header, b.ChatID, &echotron.MessageOptions{ParseMode: echotron.HTML})
|
||||
|
||||
s.sendCreativePreview(b, creativePreview)
|
||||
}
|
||||
|
||||
b.SetState(&Placements{
|
||||
@@ -1588,15 +1591,12 @@ func (s *PurchaseOptionalDetails) formatChannelName(placement backend.PlacementO
|
||||
return "Без названия"
|
||||
}
|
||||
|
||||
func (s *PurchaseOptionalDetails) sendCreativeWithInviteLink(
|
||||
func (s *PurchaseOptionalDetails) sendCreativePreview(
|
||||
b *bot.Bot,
|
||||
creative *backend.Creative,
|
||||
inviteLink string,
|
||||
creative *backend.CreativePreviewOutput,
|
||||
) {
|
||||
log.Info().Str("invite_link", inviteLink).Msg("Sending creative with invite link")
|
||||
linkedText := s.injectInviteLink(creative.Text, inviteLink)
|
||||
editor := CreativeEditorFields{
|
||||
Text: &linkedText,
|
||||
Text: &creative.Text,
|
||||
MediaType: creative.MediaType,
|
||||
MediaFileID: creative.MediaFileID,
|
||||
}
|
||||
@@ -1604,34 +1604,12 @@ func (s *PurchaseOptionalDetails) sendCreativeWithInviteLink(
|
||||
if len(creative.Buttons) > 0 {
|
||||
editor.Buttons = make([]InlineButton, 0, len(creative.Buttons))
|
||||
for _, btn := range creative.Buttons {
|
||||
url := btn.URL
|
||||
if url == inviteLinkPlaceholder {
|
||||
url = inviteLink
|
||||
}
|
||||
editor.Buttons = append(editor.Buttons, InlineButton{
|
||||
Text: btn.Text,
|
||||
URL: url,
|
||||
URL: btn.URL,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
editor.SendCreativePreview(b)
|
||||
}
|
||||
|
||||
func (s *PurchaseOptionalDetails) injectInviteLink(text, inviteLink string) string {
|
||||
if text == "" {
|
||||
return text
|
||||
}
|
||||
re := regexp.MustCompile(`<a\s+class="tg-link">([^<]*)</a>`)
|
||||
return re.ReplaceAllStringFunc(text, func(match string) string {
|
||||
sub := re.FindStringSubmatch(match)
|
||||
if len(sub) < 2 {
|
||||
return match
|
||||
}
|
||||
inner := strings.TrimSpace(sub[1])
|
||||
if inner == "" {
|
||||
return fmt.Sprintf(`<a href="%s">%s</a>`, inviteLink, inviteLink)
|
||||
}
|
||||
return fmt.Sprintf(`<a href="%s">%s</a>`, inviteLink, sub[1])
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user