Skip to content

Commit 9cbf5c2

Browse files
committed
Flag messages coming from the console for pipeline
This can be used by pipeline consumers to respond differently when they know the consumer is the console.
1 parent a7bc3bf commit 9cbf5c2

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/WhatsApp/AzureFunctionsConsole.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public async Task<IActionResult> MessageConsole([HttpTrigger(AuthorizationLevel.
5050
// Try to deserialize the message sent by the console
5151
if (JsonSerializer.Deserialize(json, JsonContext.Default.Message) is Message message)
5252
{
53+
message.FromConsole = true;
5354
// Await all responses
5455
// No action needed, just make sure all items are processed
5556
await handler.HandleAsync([message]).ToArrayAsync();

src/WhatsApp/MessageExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ namespace Devlooped.WhatsApp;
77
/// </summary>
88
public static partial class MessageExtensions
99
{
10+
extension(IMessage message)
11+
{
12+
public bool FromConsole
13+
{
14+
get => (message.AdditionalProperties ??= []).TryGetValue("FromConsole", out var value) ? value as bool? ?? default : default;
15+
set => (message.AdditionalProperties ??= [])["FromConsole"] = value;
16+
}
17+
}
18+
1019
/// <summary>
1120
/// Creates a reaction response for the user message.
1221
/// </summary>

src/WhatsApp/WhatsApp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Description>WhatsApp agents for Azure Functions</Description>
77
<PackageId>Devlooped.WhatsApp</PackageId>
88
<PackContent>false</PackContent>
9+
<LangVersion>Preview</LangVersion>
910
</PropertyGroup>
1011

1112
<ItemGroup>

0 commit comments

Comments
 (0)