Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added invalid nickname error for conversations #615

Merged
merged 6 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/sdk/Contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ export class Contracts {
}
}

public static throwIfNullOrTooLong(param: string, name: string, maxLength: number): void {
Contracts.throwIfNullOrUndefined(param, name);

if (("" + param).length > maxLength) {
throw new Error("throwIfNullOrTooLong:" + name + " (more than " + maxLength.toString() + " characters)");
}
}


public static throwIfNullOrTooShort(param: string, name: string, minLength: number): void {
Contracts.throwIfNullOrUndefined(param, name);

if (("" + param).length < minLength) {
throw new Error("throwIfNullOrTooShort:" + name + " (less than " + minLength.toString() + " characters)");
}
}

public static throwIfDisposed(isDisposed: boolean): void {
if (isDisposed) {
throw new Error("the object is already disposed");
Expand Down
4 changes: 3 additions & 1 deletion src/sdk/Transcription/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ export class ConversationImpl extends Conversation implements IDisposable {
// TODO: specify the regex required. Nicknames must be unique or get the duplicate nickname error
// TODO: check what the max length is and if a truncation is required or if the service handles it without an error
let hostNickname: string = speechConfig.getProperty(PropertyId[PropertyId.ConversationTranslator_Name]);
if (hostNickname === undefined || hostNickname === null || hostNickname.length <= 1 || hostNickname.length > 50) {
if (hostNickname === undefined || hostNickname === null) {
hostNickname = "Host";
}
Contracts.throwIfNullOrTooLong(hostNickname, "nickname", 50);
Contracts.throwIfNullOrTooShort(hostNickname, "nickname", 2);
speechConfig.setProperty(PropertyId[PropertyId.ConversationTranslator_Name], hostNickname);

} else {
Expand Down