Skip to content

Commit 028eee9

Browse files
committed
Add --Id parameter for bot identification
Updated README.md to include the new required `--Id` parameter for the `g4-bot-monitor` CLI usage and modified the HTTP listener endpoint to incorporate the bot ID. Introduced a `botId` variable in Program.cs, updated the argument dictionary, and refactored the `AddMetadata` method. Enhanced the `FormatArguments` method to describe the new `Id` parameter. Updated launchSettings.json to include the `--Id` parameter in the project profile.
1 parent bdc4773 commit 028eee9

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99
## ⚙️ CLI Usage
1010

1111
```bash
12-
g4-bot-monitor --HubUri=<hub-url> --Name=<bot-name> --Type=<bot-type> --ListenerUri=<listener-url>
12+
g4-bot-monitor --HubUri=<hub-url> --Name=<bot-name> --Type=<bot-type> --ListenerUri=<listener-url> --Id=<bot-id>
1313
```
1414

1515
All parameters are **required**:
1616

17-
| Parameter | Description |
18-
|------------------|-----------------------------------------------------------------------------|
19-
| `--HubUri` | SignalR hub URL (e.g., `http://localhost:9944`) |
20-
| `--Name` | Human-readable bot name (e.g., `"InvoiceBot"`) |
21-
| `--Type` | Bot type/category (e.g., `"Static Bot"`, `"File Listener"`) |
22-
| `--ListenerUri` | Base URI where the monitor listens (e.g., `http://localhost:8080`) |
17+
| Parameter | Description |
18+
|------------------|-----------------------------------------------------------------------------------|
19+
| `--HubUri` | SignalR hub URL (e.g., `http://localhost:9944`) |
20+
| `--Name` | Human-readable bot name (e.g., `"InvoiceBot"`) |
21+
| `--Type` | Bot type/category (e.g., `"Static Bot"`, `"File Listener"`) |
22+
| `--ListenerUri` | Base URI where the monitor listens (e.g., `http://localhost:8080`) |
23+
| `--Id` | The unique identifier of the bot instance used for hub registration and tracking. |
2324

2425
---
2526

@@ -28,7 +29,7 @@ All parameters are **required**:
2829
After startup, the monitor begins listening at:
2930

3031
```
31-
<ListenerUri>/monitor/
32+
<ListenerUri>/monitor/<Id>/
3233
```
3334

3435
### ✅ 1. `GET /monitor/ping`
@@ -89,7 +90,8 @@ curl -X POST http://localhost:8080/monitor/update \
8990
--HubUri=http://localhost:9944 \
9091
--Name=Bot42 \
9192
--Type="Static Bot" \
92-
--ListenerUri=http://localhost:8080
93+
--ListenerUri=http://localhost:8080 \
94+
--Id=1234567890
9395
```
9496

9597
---

src/G4.Bots.Monitor/G4.Bots.Monitor.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
<TrimUnusedDependencies>true</TrimUnusedDependencies>
99
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
1010
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
11+
<!--
1112
<DebugType>none</DebugType>
1213
<DebugSymbols>false</DebugSymbols>
14+
-->
1315
</PropertyGroup>
1416

1517
<ItemGroup>

src/G4.Bots.Monitor/Program.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,20 @@
4343
var arguments = FormatArguments(args);
4444
var hubUri = string.Empty;
4545
var listenerUri = string.Empty;
46+
var botId = string.Empty;
4647

4748
// Confirm and validate the required parameters
4849
try
4950
{
5051
// Confirm and clean the URI and port input values
5152
hubUri = ConfirmUri($"{arguments["HubUri"]}");
5253
listenerUri = $"{arguments["ListenerUri"]}";
54+
botId = $"{arguments["Id"]}";
5355

5456
// Update the argument dictionary with normalized values
5557
arguments["HubUri"] = hubUri;
5658
arguments["ListenerUri"] = listenerUri;
59+
arguments["Id"] = botId;
5760
}
5861
catch (Exception ex)
5962
{
@@ -89,7 +92,7 @@
8992
};
9093

9194
// Enrich the argument dictionary with runtime metadata (e.g., machine, OS, container flag)
92-
AddMetadata(connection, arguments);
95+
AddMetadata(arguments);
9396

9497
// Attempt to connect to the hub (with retry logic)
9598
await Connect(connection);
@@ -98,7 +101,7 @@
98101
await Register(connection, arguments);
99102

100103
StartBotHttpListener(
101-
prefix: $"{listenerUri.TrimEnd('/')}/monitor/",
104+
prefix: $"{listenerUri.TrimEnd('/')}/monitor/{botId}/",
102105
updateHandler: (message) => connection.InvokeAsync("UpdateBot", message, cancellationTokenSource.Token),
103106
cancellationToken: cancellationTokenSource.Token);
104107

@@ -156,11 +159,8 @@
156159

157160
// Adds runtime metadata to the bot's registration argument dictionary.
158161
// Includes connection ID, environment info, and container status flag.
159-
static void AddMetadata(HubConnection connection, Dictionary<string, object> arguments)
162+
static void AddMetadata(Dictionary<string, object> arguments)
160163
{
161-
// Assign the SignalR connection ID
162-
arguments["Id"] = connection.ConnectionId;
163-
164164
// Add machine hostname
165165
arguments["Machine"] = Environment.MachineName;
166166

@@ -204,7 +204,8 @@ static Dictionary<string, object> FormatArguments(string[] args)
204204
{ "HubUri", "The SignalR hub URI (e.g., http://localhost:9944/hub/v4/g4/bots)." },
205205
{ "Name", "The human-readable name of the bot." },
206206
{ "Type", "The type or category of the bot (e.g., File Listener Bot, Static Bot)." },
207-
{ "ListenerUri", "The full endpoint URI where the listener receives status update requests." }
207+
{ "ListenerUri", "The full endpoint URI where the listener receives status update requests." },
208+
{ "Id", "The unique identifier of the bot instance used for hub registration and tracking." }
208209
};
209210

210211
// Show help if the --help flag is passed

src/G4.Bots.Monitor/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"G4.Bots.Monitor": {
44
"commandName": "Project",
5-
"commandLineArgs": "--HubUri=http://localhost:9944 --Name=g4-static-bot --Type=static-bot --ListenerUri=http://localhost:8080/bot/v1/g4-static-bot"
5+
"commandLineArgs": "--HubUri=http://localhost:9944 --Name=g4-static-bot --Type=static-bot --ListenerUri=http://localhost:8080/bot/v1/g4-static-bot --Id=1234567890"
66
},
77
"Container (Dockerfile)": {
88
"commandName": "Docker"

0 commit comments

Comments
 (0)