mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
UTM for links on posts
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Web;
|
||||||
|
using Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
||||||
@@ -28,8 +30,15 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
|||||||
|
|
||||||
protected override string ViewableUrl
|
protected override string ViewableUrl
|
||||||
{
|
{
|
||||||
get => Url;
|
get => UtmUtility.ApplyParameters(Url, new UtmParameters()
|
||||||
|
{
|
||||||
|
Source = "telegram",
|
||||||
|
Type = "rss_post",
|
||||||
|
Campaign = "subscriber",
|
||||||
|
Content = PostId.ToString()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("feed_subscriptions")]
|
[Command("rss_subscriptions")]
|
||||||
public async Task Subscriptions()
|
public async Task Subscriptions()
|
||||||
{
|
{
|
||||||
if (!(await GenerateMenu(":sub")))
|
if (!(await GenerateMenu(":sub")))
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule
|
||||||
|
{
|
||||||
|
public struct UtmParameters
|
||||||
|
{
|
||||||
|
public string Source;
|
||||||
|
public string Type;
|
||||||
|
public string Campaign;
|
||||||
|
public string Term;
|
||||||
|
public string Content;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Web;
|
||||||
|
using Microsoft.EntityFrameworkCore.Internal;
|
||||||
|
|
||||||
|
namespace Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule
|
||||||
|
{
|
||||||
|
public class UtmUtility
|
||||||
|
{
|
||||||
|
public static string ApplyParameters(string url, UtmParameters parameters)
|
||||||
|
{
|
||||||
|
var uri = new Uri(url);
|
||||||
|
var query = HttpUtility.ParseQueryString(uri.Query);
|
||||||
|
|
||||||
|
SetIfNotNull(query, "utm_source", parameters.Source);
|
||||||
|
SetIfNotNull(query, "utm_medium", parameters.Type);
|
||||||
|
SetIfNotNull(query, "utm_campaign", parameters.Campaign);
|
||||||
|
SetIfNotNull(query, "utm_term", parameters.Term);
|
||||||
|
SetIfNotNull(query, "utm_content", parameters.Content);
|
||||||
|
|
||||||
|
var uriBuilder = new UriBuilder(uri);
|
||||||
|
uriBuilder.Query = BuildQueryString(query);
|
||||||
|
return uriBuilder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static string BuildQueryString(NameValueCollection query)
|
||||||
|
{
|
||||||
|
var queryParameters = new List<string>();
|
||||||
|
|
||||||
|
foreach (var keyName in query.AllKeys)
|
||||||
|
{
|
||||||
|
var value = query[keyName];
|
||||||
|
queryParameters.Add($"{HttpUtility.UrlEncode(keyName)}={HttpUtility.UrlEncode(value)}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.Join('&', queryParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void SetIfNotNull(NameValueCollection queryParameteters, string key, string value)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
queryParameteters.Set(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,10 +24,8 @@ namespace Kruzya.TelegramBot.UrlLimitations
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TextMessage(InChat.Public)]
|
[TextMessage(InChat.Public)]
|
||||||
public async Task OnMessageReceived()
|
public void OnMessageReceived()
|
||||||
{
|
{
|
||||||
Logger.LogDebug($"Message received from {From.Id} in {Chat.Id}");
|
|
||||||
|
|
||||||
UInt16 messageCount;
|
UInt16 messageCount;
|
||||||
var chatMember = ChatMember.From(Chat.Id, From.Id);
|
var chatMember = ChatMember.From(Chat.Id, From.Id);
|
||||||
if (!ChatMembersCache.TryGetValue(chatMember, out messageCount))
|
if (!ChatMembersCache.TryGetValue(chatMember, out messageCount))
|
||||||
@@ -48,10 +46,12 @@ namespace Kruzya.TelegramBot.UrlLimitations
|
|||||||
0)
|
0)
|
||||||
{
|
{
|
||||||
var targetChat = new ChatId(Chat.Id);
|
var targetChat = new ChatId(Chat.Id);
|
||||||
await Bot.KickChatMemberAsync(new ChatId(Chat.Id), From.Id, DateTime.Now.AddDays(1));
|
Task.WaitAll(new Task[] {
|
||||||
await Bot.DeleteMessageAsync(targetChat, message.MessageId);
|
Bot.KickChatMemberAsync(new ChatId(Chat.Id), From.Id, DateTime.Now.AddDays(1)),
|
||||||
await Bot.SendTextMessageAsync(targetChat,
|
Bot.DeleteMessageAsync(targetChat, message.MessageId),
|
||||||
$"Member {From.ToHtml()} has been banned.\n<b>Reason</b>: <pre>Spam suspicion</pre>", ParseMode.Html);
|
Bot.SendTextMessageAsync(targetChat,
|
||||||
|
$"Member {From.ToHtml()} has been banned.\n<b>Reason</b>: <pre>Spam suspicion</pre>", ParseMode.Html)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user