Skip to content

Commit

Permalink
try to make it respond to the thread if in a forum
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed May 13, 2024
1 parent adcc17f commit 82cc9bb
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update,
return;

long chatId = message.Chat.Id;

Console.WriteLine($"Received a '{messageText}' message in chat {chatId}.");

// check for command
Expand All @@ -107,10 +106,7 @@ static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update,
string[] msgSegments = messageText.Split(' ');
if (msgSegments.Length < 2)
{
await botClient.SendTextMessageAsync(
chatId: chatId,
text: "You need to supply a repository link with a branch.",
cancellationToken: cancellationToken);
await SendResponse("You need to supply a repository link with a branch.");
Console.WriteLine("No repo link supplied");
return;

Expand All @@ -126,31 +122,33 @@ await botClient.SendTextMessageAsync(
string branch = match.Groups[2].Value;
if (await TriggerGitHubWorkflow(_gitHubToken, repo, branch))
{
await botClient.SendTextMessageAsync(
chatId: chatId,
text: "Your build was triggered.",
cancellationToken: cancellationToken);
await SendResponse("Your build was triggered.");
Console.WriteLine($"Build triggered for {repo} - {branch}");
}
else
{
await botClient.SendTextMessageAsync(
chatId: chatId,
text: "Sorry. Was unable to trigger your build. Likely the repository is not supported.",
cancellationToken: cancellationToken);
await SendResponse("Sorry. Was unable to trigger your build. Likely the repository is not supported.");
Console.WriteLine("Unable to trigger build.");
}

}
else
{
await botClient.SendTextMessageAsync(
chatId: chatId,
text: "Sorry. Was unable to get the repository and branch from the URL. Check your URL and try again.",
cancellationToken: cancellationToken);
await SendResponse("Sorry. Was unable to get the repository and branch from the URL. Check your URL and try again.");
Console.WriteLine("Unable to parse repo");
}
}

async Task SendResponse(string msg)
{
bool isTopic = message.IsTopicMessage ?? false;
await botClient.SendTextMessageAsync(
chatId: chatId,
text: msg,
messageThreadId: isTopic ? message.MessageThreadId : null,
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
}
}

private static async Task<bool> TriggerGitHubWorkflow(string gitHubToken, string? repo, string branch)
Expand Down

0 comments on commit 82cc9bb

Please sign in to comment.