From 0df6803979f1112819902ad42aa68095164c411d Mon Sep 17 00:00:00 2001 From: Lee Parrish <30470292+LeeParrishMSFT@users.noreply.github.com> Date: Thu, 1 Apr 2021 09:19:01 -0500 Subject: [PATCH] Updates to SetSpeakMiddleware --- .../bot/builder/SetSpeakMiddleware.java | 14 ++++---------- .../bot/builder/SetSpeakMiddlewareTests.java | 18 ++++++------------ .../com/microsoft/bot/connector/Channels.java | 5 +++++ 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/SetSpeakMiddleware.java b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/SetSpeakMiddleware.java index 23576df5b..8fe2d1894 100644 --- a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/SetSpeakMiddleware.java +++ b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/SetSpeakMiddleware.java @@ -25,24 +25,17 @@ public class SetSpeakMiddleware implements Middleware { private final String voiceName; private final boolean fallbackToTextForSpeak; - private final String lang; /** * Initializes a new instance of the {@link SetSpeakMiddleware} class. * * @param voiceName The SSML voice name attribute value. - * @param lang The xml:lang value. * @param fallbackToTextForSpeak true if an empt Activity.Speak is populated * with Activity.getText(). */ - public SetSpeakMiddleware(String voiceName, String lang, boolean fallbackToTextForSpeak) { + public SetSpeakMiddleware(String voiceName, boolean fallbackToTextForSpeak) { this.voiceName = voiceName; this.fallbackToTextForSpeak = fallbackToTextForSpeak; - if (lang == null) { - throw new IllegalArgumentException("lang cannot be null."); - } else { - this.lang = lang; - } } /** @@ -73,10 +66,11 @@ public CompletableFuture onTurn(TurnContext turnContext, NextDelegate next activity.setSpeak( String.format("%s", voiceName, activity.getSpeak())); } - activity.setSpeak(String .format("%s", lang, activity.getSpeak())); + + "xml:lang='%s'>%s", + activity.getLocale() != null ? activity.getLocale() : "en-US", + activity.getSpeak())); } } } diff --git a/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/SetSpeakMiddlewareTests.java b/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/SetSpeakMiddlewareTests.java index 19ebf79f0..a079aacc5 100644 --- a/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/SetSpeakMiddlewareTests.java +++ b/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/SetSpeakMiddlewareTests.java @@ -16,16 +16,10 @@ public class SetSpeakMiddlewareTests { - @Test - public void ConstructorValidation() { - // no 'lang' - Assert.assertThrows(IllegalArgumentException.class, () -> new SetSpeakMiddleware("voice", null, false)); - } - @Test public void NoFallback() { TestAdapter adapter = new TestAdapter(createConversation("NoFallback")) - .use(new SetSpeakMiddleware("male", "en-us", false)); + .use(new SetSpeakMiddleware("male", false)); new TestFlow(adapter, turnContext -> { Activity activity = MessageFactory.text("OK"); @@ -43,7 +37,7 @@ public void NoFallback() { @Test public void FallbackNullSpeak() { TestAdapter adapter = new TestAdapter(createConversation("NoFallback")) - .use(new SetSpeakMiddleware("male", "en-us", true)); + .use(new SetSpeakMiddleware("male", true)); new TestFlow(adapter, turnContext -> { Activity activity = MessageFactory.text("OK"); @@ -61,7 +55,7 @@ public void FallbackNullSpeak() { @Test public void FallbackWithSpeak() { TestAdapter adapter = new TestAdapter(createConversation("Fallback")) - .use(new SetSpeakMiddleware("male", "en-us", true)); + .use(new SetSpeakMiddleware("male", true)); new TestFlow(adapter, turnContext -> { Activity activity = MessageFactory.text("OK"); @@ -93,7 +87,7 @@ public void AddVoiceTelephony() { // Voice instanceof added to Speak property. public void AddVoice(String channelId) { TestAdapter adapter = new TestAdapter(createConversation("Fallback", channelId)) - .use(new SetSpeakMiddleware("male", "en-us", true)); + .use(new SetSpeakMiddleware("male", true)); new TestFlow(adapter, turnContext -> { Activity activity = MessageFactory.text("OK"); @@ -119,14 +113,14 @@ public void AddNoVoiceDirectlineSpeech() { @Test public void AddNoVoiceTelephony() { - AddNoVoice("telephony"); + AddNoVoice(Channels.TELEPHONY); } // With no 'voice' specified, the Speak property instanceof unchanged. public void AddNoVoice(String channelId) { TestAdapter adapter = new TestAdapter(createConversation("Fallback", channelId)) - .use(new SetSpeakMiddleware(null, "en-us", true)); + .use(new SetSpeakMiddleware(null, true)); new TestFlow(adapter, turnContext -> { Activity activity = MessageFactory.text("OK"); diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Channels.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Channels.java index b2bae63ee..8a505f06a 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Channels.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Channels.java @@ -100,4 +100,9 @@ private Channels() { * Test channel. */ public static final String TEST = "test"; + + /** + * Telephony channel. + */ + public static final String TELEPHONY = "telephony"; }