window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory (...). тогда не является функцией - PullRequest
0 голосов
/ 18 февраля 2020

Я использую webchat-es5. js и ошибку его выбрасывания, такую ​​как window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory (...). Тогда это не функция. Нужна поддержка IE также с использованием es5. js.

window.fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST' })
    .then(function (res) {
      return res.json();    
    })
  .then(function (json) {
  const token = json.token;

  window.fetch('https://webchat-mockbot.azurewebsites.net/speechservices/token', { method: 'POST' })
    .then(function (res) {
    return res.json();
  })
    .then(function (json) {
    const region = json.region;
    const authorizationToken = json.token;

    window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({ authorizationToken: authorizationToken , region: region })
      .then(function (webSpeechPonyfillFactory) {
      window.WebChat.renderWebChat({
        directLine: window.WebChat.createDirectLine({ token: token }),
        webSpeechPonyfillFactory: webSpeechPonyfillFactory
      }, document.getElementById('webchat'));

      document.querySelector('#webchat > *').focus();
    });
  });
});

Заранее спасибо.

1 Ответ

0 голосов
/ 20 февраля 2020

Это настройка, которая работает для меня. Я запускаю сервер локально, чтобы получить текущие токены. Таким образом, мне не нужно включать какие-либо секреты в клиент.

window.fetch( 'http://localhost:3500/directline/token', { method: 'POST' } )
    .then( function ( res ) {
      return res.json();
    } )
    .then( function ( res ) {
      let token = res.token;
      window.fetch( 'http://localhost:3500/speechservices/token', { method: 'POST' } )
        .then( function ( res ) {
          return res.json();
        } )
        .then( function ( res ) {
          let authorizationToken = res.authorizationToken;
          window.WebChat.renderWebChat( {
            directLine: window.WebChat.createDirectLine( {
              token: token,
              webSocket: true
            } ),
            webSpeechPonyfillFactory: window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory( {
              region: 'westus2',
              authorizationToken: authorizationToken
            } )
          }, document.getElementById( 'webchat' ) );
        });
    } );

Надеюсь на помощь!

...