Skip to content

Commit 60e75e3

Browse files
konardclaude
andcommitted
Implement welcome message for new users
- Add WelcomeMessageTrigger that welcomes first-time issue creators - Add user tracking methods to FileStorage (IsNewUser and MarkUserAsWelcomed) - Include invitations to set languages list, GitHub link, and help command - Integrate WelcomeMessageTrigger into IssueTracker initialization 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 788319c commit 60e75e3

File tree

3 files changed

+133
-1
lines changed

3 files changed

+133
-1
lines changed

csharp/Platform.Bot/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private static async Task<int> Main(string[] args)
9595
var dbContext = new FileStorage(databaseFilePath?.FullName ?? new TemporaryFile().Filename);
9696
Console.WriteLine($"Bot has been started. {Environment.NewLine}Press CTRL+C to close");
9797
var githubStorage = new GitHubStorage(githubUserName, githubApiToken, githubApplicationName);
98-
var issueTracker = new IssueTracker(githubStorage, new HelloWorldTrigger(githubStorage, dbContext, fileSetName), new OrganizationLastMonthActivityTrigger(githubStorage), new LastCommitActivityTrigger(githubStorage), new AdminAuthorIssueTriggerDecorator(new ProtectDefaultBranchTrigger(githubStorage), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationRepositoriesDefaultBranchTrigger(githubStorage, dbContext), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationPullRequestsBaseBranchTrigger(githubStorage, dbContext), githubStorage));
98+
var issueTracker = new IssueTracker(githubStorage, new WelcomeMessageTrigger(githubStorage, dbContext), new HelloWorldTrigger(githubStorage, dbContext, fileSetName), new OrganizationLastMonthActivityTrigger(githubStorage), new LastCommitActivityTrigger(githubStorage), new AdminAuthorIssueTriggerDecorator(new ProtectDefaultBranchTrigger(githubStorage), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationRepositoriesDefaultBranchTrigger(githubStorage, dbContext), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationPullRequestsBaseBranchTrigger(githubStorage, dbContext), githubStorage));
9999
var pullRequenstTracker = new PullRequestTracker(githubStorage, new MergeDependabotBumpsTrigger(githubStorage));
100100
var timestampTracker = new DateTimeTracker(githubStorage, new CreateAndSaveOrganizationRepositoriesMigrationTrigger(githubStorage, dbContext, Path.Combine(Directory.GetCurrentDirectory(), "/github-migrations")));
101101
var cancellation = new CancellationTokenSource();
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System.Threading.Tasks;
2+
using Interfaces;
3+
using Octokit;
4+
using Storage.Local;
5+
using Storage.Remote.GitHub;
6+
7+
namespace Platform.Bot.Triggers
8+
{
9+
using TContext = Issue;
10+
/// <summary>
11+
/// <para>
12+
/// Represents the welcome message trigger for new users.
13+
/// </para>
14+
/// <para></para>
15+
/// </summary>
16+
/// <seealso cref="ITrigger{TContext}"/>
17+
internal class WelcomeMessageTrigger : ITrigger<TContext>
18+
{
19+
private readonly GitHubStorage _storage;
20+
private readonly FileStorage _fileStorage;
21+
22+
/// <summary>
23+
/// <para>
24+
/// Initializes a new <see cref="WelcomeMessageTrigger"/> instance.
25+
/// </para>
26+
/// <para></para>
27+
/// </summary>
28+
/// <param name="storage">
29+
/// <para>A GitHub storage.</para>
30+
/// <para></para>
31+
/// </param>
32+
/// <param name="fileStorage">
33+
/// <para>A file storage.</para>
34+
/// <para></para>
35+
/// </param>
36+
public WelcomeMessageTrigger(GitHubStorage storage, FileStorage fileStorage)
37+
{
38+
this._storage = storage;
39+
this._fileStorage = fileStorage;
40+
}
41+
42+
/// <summary>
43+
/// <para>
44+
/// Actions the context.
45+
/// </para>
46+
/// <para></para>
47+
/// </summary>
48+
/// <param name="context">
49+
/// <para>The context.</para>
50+
/// <para></para>
51+
/// </param>
52+
public async Task Action(TContext context)
53+
{
54+
var welcomeMessage = @"👋 Welcome to the platform!
55+
56+
Thank you for creating your first issue. Here are some things you can do to get started:
57+
58+
🌐 **Set up your languages list**: Let us know which programming languages you're interested in by mentioning them in your issues or profile.
59+
60+
🔗 **Set up your GitHub link**: Make sure your GitHub profile is properly linked and accessible.
61+
62+
❓ **Need help?**: Use the `help` command or create an issue with ""help"" in the title to get assistance with available commands and features.
63+
64+
We're glad to have you here! Feel free to explore and don't hesitate to ask questions.";
65+
66+
await _storage.CreateIssueComment(context.Repository.Id, context.Number, welcomeMessage);
67+
68+
// Mark user as welcomed
69+
_fileStorage.MarkUserAsWelcomed(context.User.Login);
70+
}
71+
72+
/// <summary>
73+
/// <para>
74+
/// Determines whether this instance condition.
75+
/// </para>
76+
/// <para></para>
77+
/// </summary>
78+
/// <param name="context">
79+
/// <para>The context.</para>
80+
/// <para></para>
81+
/// </param>
82+
/// <returns>
83+
/// <para>The bool</para>
84+
/// <para></para>
85+
/// </returns>
86+
public async Task<bool> Condition(TContext context) => _fileStorage.IsNewUser(context.User.Login);
87+
}
88+
}

csharp/Storage/LocalStorage/FileStorage.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,50 @@ public List<File> GetFilesFromSet(string set)
329329

330330
// public void SetLastGithubMigrationTimeStamp()
331331

332+
/// <summary>
333+
/// <para>
334+
/// Checks if a user has been welcomed before.
335+
/// </para>
336+
/// <para></para>
337+
/// </summary>
338+
/// <param name="username">
339+
/// <para>The username to check.</para>
340+
/// <para></para>
341+
/// </param>
342+
/// <returns>
343+
/// <para>True if user is new (not welcomed), false if already welcomed</para>
344+
/// <para></para>
345+
/// </returns>
346+
public bool IsNewUser(string username)
347+
{
348+
var userMarker = CreateString($"welcomed_user:{username}");
349+
try
350+
{
351+
var existingUser = _synchronizedLinks.SearchOrDefault(userMarker, _synchronizedLinks.Constants.Itself);
352+
return existingUser == _synchronizedLinks.Constants.Null;
353+
}
354+
catch
355+
{
356+
return true; // Assume new user if there's any error
357+
}
358+
}
359+
360+
/// <summary>
361+
/// <para>
362+
/// Marks a user as welcomed.
363+
/// </para>
364+
/// <para></para>
365+
/// </summary>
366+
/// <param name="username">
367+
/// <para>The username to mark as welcomed.</para>
368+
/// <para></para>
369+
/// </param>
370+
public void MarkUserAsWelcomed(string username)
371+
{
372+
var userMarker = CreateString($"welcomed_user:{username}");
373+
_synchronizedLinks.GetOrCreate(userMarker, _synchronizedLinks.Constants.Itself);
374+
}
375+
332376
protected override void Dispose(bool manual, bool wasDisposed)
333377
{
334378
_disposableLinks.Dispose();

0 commit comments

Comments
 (0)