Skip to content

Commit

Permalink
cherrypick: runtypes lock and set speak middleware fixes (#3511)
Browse files Browse the repository at this point in the history
* fix: lock runtypes to 5.1.x version range (#3509)

* port: remove lang from set speak middleware (#3510)

Fixes #3507

Co-authored-by: Steven Gum <14935595+stevengum@users.noreply.github.com>

Co-authored-by: Steven Gum <14935595+stevengum@users.noreply.github.com>
  • Loading branch information
joshgummersall and stevengum authored Apr 1, 2021
1 parent 756b85f commit f97b675
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"dependency-graph": "^0.10.0",
"runtypes": "^5.0.1"
"runtypes": "~5.1.0"
},
"devDependencies": {
"mocha": "^8.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"botbuilder-dialogs-adaptive-runtime": "4.1.6",
"botbuilder-dialogs-adaptive-runtime-core": "4.1.6",
"express": "^4.17.1",
"runtypes": "^5.0.1"
"runtypes": "~5.1.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"botbuilder-dialogs-adaptive-runtime": "4.1.6",
"botbuilder-dialogs-adaptive-runtime-core": "4.1.6",
"restify": "^8.5.1",
"runtypes": "^5.0.1"
"runtypes": "~5.1.0"
},
"scripts": {
"build": "tsc -b",
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-dialogs-adaptive-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"botframework-connector": "4.1.6",
"dependency-graph": "^0.10.0",
"nconf": "^0.11.2",
"runtypes": "^5.0.1",
"runtypes": "~5.1.0",
"yargs-parser": "^20.2.7"
},
"devDependencies": {
Expand Down
7 changes: 1 addition & 6 deletions libraries/botbuilder-dialogs-adaptive-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,13 @@ function addFeatures(services: ServiceCollection, configuration: Configuration):
['setSpeak'],
t.Record({
voiceFontName: t.String.Or(t.Undefined),
lang: t.String,
fallbackToTextForSpeechIfEmpty: t.Boolean,
})
);

if (setSpeak) {
middlewareSet.use(
new SetSpeakMiddleware(
setSpeak.voiceFontName ?? null,
setSpeak.lang,
setSpeak.fallbackToTextForSpeechIfEmpty
)
new SetSpeakMiddleware(setSpeak.voiceFontName ?? null, setSpeak.fallbackToTextForSpeechIfEmpty)
);
}

Expand Down
13 changes: 4 additions & 9 deletions libraries/botbuilder/src/setSpeakMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,9 @@ export class SetSpeakMiddleware implements Middleware {
* Initializes a new instance of the SetSpeakMiddleware class.
*
* @param voiceName The SSML voice name attribute value.
* @param lang The xml:lang value.
* @param fallbackToTextForSpeak true if an empty Activity.Speak is populated with Activity.Text.
*/
constructor(
private readonly voiceName: string | null,
private readonly lang: string,
private readonly fallbackToTextForSpeak: boolean
) {
if (!lang) throw new TypeError('`lang` must be a non-empty string');
}
constructor(private readonly voiceName: string | null, private readonly fallbackToTextForSpeak: boolean) {}

/**
* Processes an incoming activity.
Expand Down Expand Up @@ -75,7 +68,9 @@ export class SetSpeakMiddleware implements Middleware {
activity.speak = `<voice name='${this.voiceName}'>${activity.speak}</voice>`;
}

activity.speak = `<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='${this.lang}'>${activity.speak}</speak>`;
activity.speak = `<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='${
activity.locale ?? 'en-US'
}'>${activity.speak}</speak>`;
}
}
})
Expand Down
8 changes: 2 additions & 6 deletions libraries/botbuilder/tests/setSpeakMiddleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ const { MessageFactory, TestAdapter } = require('botbuilder-core');
describe('SetSpeakMiddleware', function () {
describe('constructor', function () {
it('works', function () {
new SetSpeakMiddleware('voiceName', 'lang', false);
});

it('throws for falsy lang param', function () {
assert.throws(() => new SetSpeakMiddleware('voiceName', '', false));
new SetSpeakMiddleware('voiceName', false);
});
});

Expand All @@ -25,7 +21,7 @@ describe('SetSpeakMiddleware', function () {
},
voice = 'male',
} = {}) {
return new TestAdapter(logic, { channelId }).use(new SetSpeakMiddleware(voice, 'en-us', fallback));
return new TestAdapter(logic, { channelId }).use(new SetSpeakMiddleware(voice, fallback));
}

it('no fallback does nothing to speak', async function () {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10812,10 +10812,10 @@ run-queue@^1.0.0, run-queue@^1.0.3:
dependencies:
aproba "^1.1.1"

runtypes@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/runtypes/-/runtypes-5.0.1.tgz#406d140410266f6ece17c3501a37234f91faa346"
integrity sha512-+TWVlCmFsgrG4Nd2u+ambpNFO8Yp4heAflGQi9oNj6GRkxZo8aSDBxO1Y0vlKIQCWKKFxato+8Hn67XeAqKhRA==
runtypes@~5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/runtypes/-/runtypes-5.1.0.tgz#a1f2501b5ca8fda47d51ea15b6ccca45e924a8c3"
integrity sha512-OMHkz6dxysXj4E8Fj/HCGjtdJUhapQUN7puvqzuzvjaX28pd52PZmEMqQlkIzCfKdhXdM0ghx8PpvELprEnOLQ==

safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
Expand Down

0 comments on commit f97b675

Please sign in to comment.