Skip to content

Commit

Permalink
3.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
karamem0 committed Oct 15, 2024
1 parent 7700056 commit 29c5cef
Show file tree
Hide file tree
Showing 13 changed files with 442 additions and 198 deletions.
28 changes: 8 additions & 20 deletions source/server/Karamem0.Commistant.Bot/Bots/ActivityBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,15 @@ protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivi
{
if (dc.ActiveDialog is null)
{
var result = await new Func<Task<DialogTurnResult?>>(async () =>
var arguments = await this.openAIService.GetArgumentsAsync(command, cancellationToken: cancellationToken);
var result = arguments?.Type switch
{
var message = await this.openAIService.ChatCompletionAsync(command, cancellationToken: cancellationToken);
if (message.FinishReason == ChatFinishReason.ToolCalls)
{
var arguments = message.ToolCalls.Select(item => item.FunctionArguments).First();
var content = JsonSerializer.Deserialize<ConversationPropertyArguments>(arguments?.ToString());
return content?.Type switch
{
"会議開始後" => await dc.BeginDialogAsync(nameof(StartMeetingDialog), content, cancellationToken: cancellationToken),
"会議終了前" => await dc.BeginDialogAsync(nameof(EndMeetingDialog), content, cancellationToken: cancellationToken),
"会議中" => await dc.BeginDialogAsync(nameof(InMeetingDialog), content, cancellationToken: cancellationToken),
"初期化" => await dc.BeginDialogAsync(nameof(ResetDialog), cancellationToken: cancellationToken),
_ => null,
};
}
else
{
return null;
}
})();
"会議開始後" => await dc.BeginDialogAsync(nameof(StartMeetingDialog), arguments, cancellationToken: cancellationToken),
"会議終了前" => await dc.BeginDialogAsync(nameof(EndMeetingDialog), arguments, cancellationToken: cancellationToken),
"会議中" => await dc.BeginDialogAsync(nameof(InMeetingDialog), arguments, cancellationToken: cancellationToken),
"初期化" => await dc.BeginDialogAsync(nameof(ResetDialog), cancellationToken: cancellationToken),
_ => null,
};
if (result is null)
{
_ = await turnContext.SendActivityAsync(
Expand Down
126 changes: 94 additions & 32 deletions source/server/Karamem0.Commistant.Bot/Dialogs/EndMeetingDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private async Task<DialogTurnResult> BeforeConfirmAsync(WaterfallStepContext ste
new AdaptiveTextInput()
{
Id = "Message",
IsMultiline = true,
Label = "メッセージ",
Placeholder = "会議後に表示されるメッセージ",
Style = AdaptiveTextInputStyle.Text,
Expand Down Expand Up @@ -172,76 +173,137 @@ private async Task<DialogTurnResult> AfterConrifmAsync(WaterfallStepContext step
property.EndMeetingMessage = value.Value<string>("Message", null);
property.EndMeetingUrl = value.Value<string>("Url", null);
this.logger.SettingsUpdated(stepContext.Context.Activity);
_ = await stepContext.Context.SendActivityAsync(
"設定を変更しました。",
cancellationToken: cancellationToken
);
_ = await stepContext.Context.SendSettingsUpdatedAsync(cancellationToken);
}
if (value.Value<string>("Button") == "Cancel")
{
this.logger.SettingsCancelled(stepContext.Context.Activity);
_ = await stepContext.Context.SendActivityAsync(
"キャンセルしました。設定は変更されていません。",
cancellationToken: cancellationToken
);
_ = await stepContext.Context.SendSettingsCancelledAsync(cancellationToken);
}
if (stepContext.Context.Activity.ReplyToId is not null)
{
var card = new AdaptiveCard("1.3")
{
Body =
[
new AdaptiveFactSet()
new AdaptiveColumnSet()
{
Facts =
Columns =
[
new()
new AdaptiveColumn()
{
Title = "スケジュール",
Value = new Func<string>(() =>
property.EndMeetingSchedule switch
Items =
[
new AdaptiveTextBlock()
{
-1 => "なし",
0 => "予定時刻",
_ => $"{property.EndMeetingSchedule} 分後"
Text = "スケジュール",
Weight = AdaptiveTextWeight.Bolder
}
)()
],
Width = "90px"
},
new()
new AdaptiveColumn()
{
Title = "メッセージ",
Value = $"{property.EndMeetingMessage}"
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()
new AdaptiveColumn()
{
Title = "URL",
Value = $"{property.EndMeetingUrl}"
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"
}
]
}
]
};
if (property.EndMeetingUrl is not null)
if (Uri.TryCreate(property.EndMeetingUrl, UriKind.Absolute, out var url))
{
var bytes = await this.qrCodeService.CreateAsync(property.EndMeetingUrl, cancellationToken);
var bytes = await this.qrCodeService.CreateAsync(url.ToString(), cancellationToken);
var base64 = Convert.ToBase64String(bytes);
card.Body.Add(new AdaptiveImage()
{
AltText = property.EndMeetingUrl,
Size = AdaptiveImageSize.Stretch,
AltText = url.ToString(),
Size = AdaptiveImageSize.Large,
Url = new Uri($"data:image/png;base64,{base64}")
});
card.Actions.Add(new AdaptiveOpenUrlAction()
{
Title = "URL を開く",
Url = url,
});
}
var activity = MessageFactory.Attachment(new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = JsonConvert.DeserializeObject(card.ToJson())
});
activity.Id = stepContext.Context.Activity.ReplyToId;
_ = await stepContext.Context.UpdateActivityAsync(
activity,
cancellationToken: cancellationToken
);
_ = await stepContext.Context.UpdateActivityAsync(activity, cancellationToken);
}
return await stepContext.EndDialogAsync(cancellationToken: cancellationToken);
}
Expand Down
125 changes: 98 additions & 27 deletions source/server/Karamem0.Commistant.Bot/Dialogs/InMeetingDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private async Task<DialogTurnResult> BeforeConfirmAsync(WaterfallStepContext ste
new AdaptiveTextInput()
{
Id = "Message",
IsMultiline = true,
Label = "メッセージ",
Placeholder = "会議中に表示されるメッセージ",
Style = AdaptiveTextInputStyle.Text,
Expand Down Expand Up @@ -177,67 +178,137 @@ private async Task<DialogTurnResult> AfterConrifmAsync(WaterfallStepContext step
property.InMeetingMessage = value.Value<string>("Message", null);
property.InMeetingUrl = value.Value<string>("Url", null);
this.logger.SettingsUpdated(stepContext.Context.Activity);
_ = await stepContext.Context.SendActivityAsync(
"設定を変更しました。",
cancellationToken: cancellationToken
);
_ = await stepContext.Context.SendSettingsUpdatedAsync(cancellationToken);
}
if (value.Value<string>("Button") == "Cancel")
{
this.logger.SettingsCancelled(stepContext.Context.Activity);
_ = await stepContext.Context.SendSettingsCancelledAsync(cancellationToken);
}
if (stepContext.Context.Activity.ReplyToId is not null)
{
var card = new AdaptiveCard("1.3")
{
Body =
[
new AdaptiveFactSet()
new AdaptiveColumnSet()
{
Facts =
Columns =
[
new()
new AdaptiveColumn()
{
Title = "スケジュール",
Value = new Func<string>(() =>
property.InMeetingSchedule switch
Items =
[
new AdaptiveTextBlock()
{
-1 => "なし",
_ => $"{property.InMeetingSchedule}"
Text = "スケジュール",
Weight = AdaptiveTextWeight.Bolder
}
)()
],
Width = "90px"
},
new()
new AdaptiveColumn()
{
Title = "メッセージ",
Value = $"{property.InMeetingMessage}"
Items =
[
new AdaptiveTextBlock()
{
Text = property.InMeetingSchedule switch
{
-1 => "なし",
0 => "予定時刻",
_ => $"{property.InMeetingSchedule} 分ごと"
}
}
],
Width = "stretch"
}
],
},
new AdaptiveColumnSet()
{
Columns =
[
new AdaptiveColumn()
{
Items =
[
new AdaptiveTextBlock()
{
Text = "メッセージ",
Weight = AdaptiveTextWeight.Bolder
}
],
Width = "90px"
},
new()
new AdaptiveColumn()
{
Title = "URL",
Value = $"{property.InMeetingUrl}"
Items =
[
new AdaptiveTextBlock()
{
Text = $"{property.InMeetingMessage}",
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.InMeetingUrl}"
}
],
Width = "stretch"
}
]
}
]
};
if (property.InMeetingUrl is not null)
if (Uri.TryCreate(property.InMeetingUrl, UriKind.Absolute, out var url))
{
var bytes = await this.qrCodeService.CreateAsync(property.InMeetingUrl, cancellationToken);
var bytes = await this.qrCodeService.CreateAsync(url.ToString(), cancellationToken);
var base64 = Convert.ToBase64String(bytes);
card.Body.Add(new AdaptiveImage()
{
AltText = property.InMeetingUrl,
Size = AdaptiveImageSize.Stretch,
AltText = url.ToString(),
Size = AdaptiveImageSize.Large,
Url = new Uri($"data:image/png;base64,{base64}")
});
card.Actions.Add(new AdaptiveOpenUrlAction()
{
Title = "URL を開く",
Url = url,
});
}
var activity = MessageFactory.Attachment(new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = JsonConvert.DeserializeObject(card.ToJson())
});
activity.Id = stepContext.Context.Activity.ReplyToId;
_ = await stepContext.Context.UpdateActivityAsync(
activity,
cancellationToken: cancellationToken
);
_ = await stepContext.Context.UpdateActivityAsync(activity, cancellationToken);
}
return await stepContext.EndDialogAsync(cancellationToken: cancellationToken);
}
Expand Down
Loading

0 comments on commit 29c5cef

Please sign in to comment.