question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting error: Cannot read property 'connectionStatus$' of undefined

See original GitHub issue

We are trying to integrate voicebot using SPFX with react in SharePoint.

We are referring Directline speech sample.

We are using below version of SPFX and botframework-webchat. SPFX version: 1.10 “botframework-webchat”: “4.10.0”

image

Please Find Code Snippet

import * as React from "react";
import {ApplicationCustomizerContext} from '@microsoft/sp-application-base';
import { DirectLine } from "botframework-directlinejs";
import ReactWebChat, { createCognitiveServicesSpeechServicesPonyfillFactory, createDirectLine, createDirectLineSpeechAdapters, createStore } from "botframework-webchat";
import { AadTokenProvider } from '@microsoft/sp-http';
import updateIn from 'simple-update-in';
import { environment } from "../../environment/environment";
import { Logger, LogLevel } from "@pnp/logging";
import { AdaptiveCard, IAdaptiveCardActionResult} from "../../AdaptiveCard";



export interface IReactFooterProps {
  upn: string;
  aadToken: string;
  userTimeZoneName: string;
  dContext: ApplicationCustomizerContext;
    
}
let notificationParams: any;
let savedActivity: any=null;
export default class ReactFooter extends React.Component<IReactFooterProps,{adapters:{}}> {
  
    private directLine: DirectLine;
    private token: string;
    private store: null;
    public adaptersObj:any;
    private templateJson: string;
    private user:any;
    
     
    constructor(props: IReactFooterProps) {
      super(props);
      this.state={adapters:{}};
      this.user={ id:props.upn, name: props.dContext.pageContext.user.displayName };

//OTHER CODE
      }
    public async componentDidMount() {
     
      
      const fetchCredentials = async () => {
        var myHeaders = new Headers();
        myHeaders.append("Ocp-Apim-Subscription-Key", "<subscription key>");
        myHeaders.append("Ocp-Apim-Subscription-Region", "westeurope");


        const res = await fetch('https://westeurope.api.cognitive.microsoft.com/sts/v1.0/issueToken',  {
          method: 'POST',
          headers:myHeaders,redirect: 'follow'
        });

        if (!res.ok) {
          throw new Error('Failed to fetch authorization token and region.');
        }

        const authorizationToken  = await res.text();

        return { authorizationToken, region:'westeurope' };
      };
        this.adaptersObj=await createDirectLineSpeechAdapters({
        fetchCredentials
      })
      this.setState({ adapters: this.adaptersObj });
      
      }
      
    public render() : JSX.Element{
        return (
            <ReactWebChat  {...this.state.adapters}  store={this.store} userID={this.user.id} username={this.user.name}
            styleOptions={{
            bubbleBackground: '#0184D7',
            bubbleTextColor:'#FFFFFF',
            bubbleBorderRadius:'5',            
            bubbleFromUserBackground: '#e8e8e8',            
            bubbleFromUserBorderRadius:'5',            
            botAvatarImage:BeeahImg,
            userAvatarImage: EmployeeImg,
            sendBoxBackground:"#E8E8E8 0% 0% no-repeat padding-box",
            hideUploadButton:true}}/>
        );
    }
}


Error We are Getting: image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
compulimcommented, Jun 3, 2021

Discussed offline, tl;dr the web page was not passing the chat adapter (DLSpeech in this case) when rendering Web Chat initially. Thus, Web Chat went into a stopped state and console-logging connectionStatus$ is undefined.

Technically:

  • The page render Web Chat without the chat adapter in initial pass
  • Web Chat stopped because lacking of chat adapter
    • Since they are using 4.7, it only show “javascripterror” on the topic of the page
    • In newer version of Web Chat, we have a better error message (a.k.a. red line of text)
  • On subsequent rendering pass, the web page passed the chat adapter to Web Chat
  • Since Web Chat already stopped, even the adapter was passed, Web Chat is already in a stopped state

The web page should pass the chat adapter to Web Chat as outlined in sample 03.a. If the chat adapter is not available, they should use loader/spinner before rendering Web Chat.

0reactions
jayaraucommented, May 28, 2021

Hi @dmvtech , any update on this, are you able to reproduce issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'renderWebChat ...
Uncaught TypeError : Cannot read property 'renderWebChat' of undefined ... applied on chat bubble and on page load I am getting this error:....
Read more >
Azure bot suddenly stopped working - Error Log:"Cannot read ...
I am facing this error while tyring to chat with Azure Bot ... Cannot read properties of undefined (reading 'requestedDataType')
Read more >
uncaught typeerror: cannot set properties of undefined (setting ...
When getting an element with getElementById you do not have to acces the first element with [0] since it can only return one...
Read more >
Cannot read property 'meetingProp' of undefined when ...
I've deployed a running server of bigbluebutton with greenlight and now I would to apply some changes to the file "bigbluebutton-html5".
Read more >
Cannot read properties of undefined' - JavaScript Debugging
JavaScript Tutorial. How To Fix 'Uncaught TypeError : Cannot read properties of undefined ' - JavaScript Debugging. 26K views 6 months ago.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found