Skip to content

Commit

Permalink
3.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
karamem0 committed Dec 6, 2024
1 parent f8a5001 commit abeab72
Show file tree
Hide file tree
Showing 30 changed files with 388 additions and 282 deletions.
16 changes: 9 additions & 7 deletions source/server/Karamem0.Commistant.Bot/ConfigureServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Karamem0.Commistant;
Expand All @@ -33,7 +34,7 @@ public static class ConfigureServices

public static IServiceCollection AddBots(this IServiceCollection services, IConfiguration configuration)
{
var blobContainerUrl = configuration.GetValue<string>("AzureBotStatesStorageUrl") ?? throw new InvalidOperationException();
var blobContainerUrl = configuration["AzureBotStatesStorageUrl"] ?? throw new InvalidOperationException();
_ = services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFrameworkAuthentication>();
_ = services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
_ = services.AddSingleton<IStorage>(new BlobsStorage(
Expand Down Expand Up @@ -64,18 +65,19 @@ public static IServiceCollection AddDialogs(this IServiceCollection services)

public static IServiceCollection AddServices(this IServiceCollection services, IConfiguration configuration)
{
var openAIEndpointUrl = configuration.GetValue<string>("AzureOpenAIEndpointUrl") ?? throw new InvalidOperationException();
var openAIModelName = configuration.GetValue<string>("AzureOpenAIModelName") ?? throw new InvalidOperationException();
var openAIEndpointUrl = configuration["AzureOpenAIEndpointUrl"] ?? throw new InvalidOperationException();
var openAIModelName = configuration["AzureOpenAIModelName"] ?? throw new InvalidOperationException();
_ = services.AddScoped(provider => new AzureOpenAIClient(
new Uri(openAIEndpointUrl),
new DefaultAzureCredential()
));
_ = services.AddScoped(provider => new OpenAIService(
provider.GetRequiredService<AzureOpenAIClient>() ?? throw new InvalidOperationException(),
_ = services.AddScoped<QRCodeGenerator>();
_ = services.AddScoped<IAdaptiveCardService, AdaptiveCardService>();
_ = services.AddScoped<IOpenAIService>(provider => new OpenAIService(
provider.GetRequiredService<AzureOpenAIClient>(),
openAIModelName
));
_ = services.AddScoped<QRCodeGenerator>();
_ = services.AddScoped<QrCodeService>();
_ = services.AddScoped<IQRCodeService, QRCodeService>();
return services;
}

Expand Down
208 changes: 19 additions & 189 deletions source/server/Karamem0.Commistant.Bot/Dialogs/EndMeetingDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

using AdaptiveCards;
using AdaptiveCards.Templating;
using AutoMapper;
using Karamem0.Commistant.Extensions;
using Karamem0.Commistant.Logging;
Expand All @@ -30,15 +31,18 @@ namespace Karamem0.Commistant.Dialogs;

public class EndMeetingDialog(
ConversationState conversationState,
QrCodeService qrCodeService,
IAdaptiveCardService adaptiveCardService,
IQRCodeService qrCodeService,
IMapper mapper,
ILogger<EndMeetingDialog> logger
) : ComponentDialog
{

private readonly ConversationState conversationState = conversationState;

private readonly QrCodeService qrCodeService = qrCodeService;
private readonly IAdaptiveCardService adaptiveCardService = adaptiveCardService;

private readonly IQRCodeService qrCodeService = qrCodeService;

private readonly IMapper mapper = mapper;

Expand All @@ -63,89 +67,17 @@ private async Task<DialogTurnResult> BeforeConfirmAsync(WaterfallStepContext ste
var property = await accessor.GetAsync(stepContext.Context, () => new(), cancellationToken);
var options = (ConversationPropertyArguments?)stepContext.Options;
var value = this.mapper.Map(options, property.Clone());
var card = new AdaptiveCard("1.3")
var arguments = new AdaptiveCardTemplateArguments()
{
Body =
[
new AdaptiveChoiceSetInput()
{
Id = "Schedule",
Label = "スケジュール",
Placeholder = "通知を表示する時間",
Choices =
[
new()
{
Title = "なし",
Value = "-1"
},
new()
{
Title = "予定時刻",
Value = "0"
},
new()
{
Title = "5 分前",
Value = "5"
},
new()
{
Title = "10 分前",
Value = "10"
},
new()
{
Title = "15 分前",
Value = "15"
},
],
Value = value.EndMeetingSchedule.ToString()
},
new AdaptiveTextInput()
{
Id = "Message",
IsMultiline = true,
Label = "メッセージ",
Placeholder = "会議後に表示されるメッセージ",
Style = AdaptiveTextInputStyle.Text,
Value = value.EndMeetingMessage
},
new AdaptiveTextInput()
{
Id = "Url",
Label = "URL",
Placeholder = "会議後に表示されるリンクの URL",
Style = AdaptiveTextInputStyle.Url,
Value = value.EndMeetingUrl
}
],
Actions =
[
new AdaptiveSubmitAction()
{
Id = "Submit",
Title = "保存",
Data = new
{
Button = "Submit"
}
},
new AdaptiveSubmitAction()
{
Id = "Cancel",
Title = "キャンセル",
Data = new
{
Button = "Cancel"
}
}
]
Schedule = value.EndMeetingSchedule,
Message = value.EndMeetingMessage,
Url = value.EndMeetingUrl,
};
var card = this.adaptiveCardService.GetCardAsync(AdaptiveCardTemplates.EndMeetingBefore, arguments);
var activity = MessageFactory.Attachment(new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = JsonConvert.DeserializeObject(card.ToJson())
Content = card
});
this.logger.SettingsUpdating(stepContext.Context.Activity);
return await stepContext.PromptAsync(
Expand Down Expand Up @@ -182,125 +114,23 @@ private async Task<DialogTurnResult> AfterConrifmAsync(WaterfallStepContext step
}
if (stepContext.Context.Activity.ReplyToId is not null)
{
var card = new AdaptiveCard("1.3")
var arguments = new AdaptiveCardTemplateArguments()
{
Body =
[
new AdaptiveColumnSet()
{
Columns =
[
new AdaptiveColumn()
{
Items =
[
new AdaptiveTextBlock()
{
Text = "スケジュール",
Weight = AdaptiveTextWeight.Bolder
}
],
Width = "90px"
},
new AdaptiveColumn()
{
Items =
[
new AdaptiveTextBlock()
{
Text = property.EndMeetingSchedule switch
{
-1 => "なし",
0 => "予定時刻",
_ => $"{property.EndMeetingSchedule} 分前"
}
}
],
Width = "stretch"
}
],
},
new AdaptiveColumnSet()
{
Columns =
[
new AdaptiveColumn()
{
Items =
[
new AdaptiveTextBlock()
{
Text = "メッセージ",
Weight = AdaptiveTextWeight.Bolder
}
],
Width = "90px"
},
new AdaptiveColumn()
{
Items =
[
new AdaptiveTextBlock()
{
Text = $"{property.EndMeetingMessage}",
Wrap = true
}
],
Width = "stretch"
}
]
},
new AdaptiveColumnSet()
{
Columns =
[
new AdaptiveColumn()
{
Items =
[
new AdaptiveTextBlock()
{
Text = "URL",
Weight = AdaptiveTextWeight.Bolder
}
],
Width = "90px"
},
new AdaptiveColumn()
{
Items =
[
new AdaptiveTextBlock()
{
Text = $"{property.EndMeetingUrl}"
}
],
Width = "stretch"
}
]
}
]
Schedule = property.EndMeetingSchedule,
Message = property.EndMeetingMessage
};
if (Uri.TryCreate(property.EndMeetingUrl, UriKind.Absolute, out var url))
{
var bytes = await this.qrCodeService.CreateAsync(url.ToString(), cancellationToken);
var base64 = Convert.ToBase64String(bytes);
card.Body.Add(new AdaptiveImage()
{
AltText = url.ToString(),
Size = AdaptiveImageSize.Large,
Url = new Uri($"data:image/png;base64,{base64}")
});
card.Actions.Add(new AdaptiveOpenUrlAction()
{
Title = "URL を開く",
Url = url,
});
arguments.Url = url.ToString();
arguments.QRCode = $"data:image/png;base64,{base64}";
}
var card = this.adaptiveCardService.GetCardAsync(AdaptiveCardTemplates.EndMeetingBefore, arguments);
var activity = MessageFactory.Attachment(new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = JsonConvert.DeserializeObject(card.ToJson())
Content = card
});
activity.Id = stepContext.Context.Activity.ReplyToId;
_ = await stepContext.Context.UpdateActivityAsync(activity, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ namespace Karamem0.Commistant.Dialogs;

public class InMeetingDialog(
ConversationState conversationState,
QrCodeService qrCodeService,
IQRCodeService qrCodeService,
IMapper mapper,
ILogger<InMeetingDialog> logger
) : ComponentDialog
{

private readonly ConversationState conversationState = conversationState;

private readonly QrCodeService qrCodeService = qrCodeService;
private readonly IQRCodeService qrCodeService = qrCodeService;

private readonly IMapper mapper = mapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ namespace Karamem0.Commistant.Dialogs;

public class StartMeetingDialog(
ConversationState conversationState,
QrCodeService qrCodeService,
IQRCodeService qrCodeService,
IMapper mapper,
ILogger<StartMeetingDialog> logger
) : ComponentDialog
{

private readonly ConversationState conversationState = conversationState;

private readonly QrCodeService qrCodeService = qrCodeService;
private readonly IQRCodeService qrCodeService = qrCodeService;

private readonly IMapper mapper = mapper;

Expand Down
2 changes: 2 additions & 0 deletions source/server/Karamem0.Commistant.Bot/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"LogLevel": {
"Default": "Information"
},
"EnableAdaptiveSampling": false,
"EnableLiveMetrics": false,
"EnableDependencyTrackingTelemetryModule": false,
"EnablePerformanceCounterCollectionModule": false
}
Expand Down
Loading

0 comments on commit abeab72

Please sign in to comment.