microsoft/BotFramework-DirectLineJS

subscribe not working when using react-query

iamhaaamed opened this issue · 4 comments

I want to use BotFramework in a react-native project that using react-query for fetching data, but if I call any queries with the react-query, the subscribe method of BotFramework stopped working and when I remove the queries it is working:

import axios from 'axios';
import {DirectLine} from 'botframework-directlinejs';
import React, {useEffect} from 'react';
import {Button, View} from 'react-native';
import {useQuery} from 'react-query';

export const Login = () => {
  const directLine = new DirectLine({
    secret: 'yv4oJpBHBMk.Px5NDYymTr02dCEiBT6exb2PztOjZQVGO9i_XXXXXX,
  });

  useEffect(() => {
    directLine.activity$
      .filter(activity => activity.type === 'message')
      .subscribe(activity => {
        console.log('received activity ', JSON.stringify(activity));
      });
  }, []);

  const {isLoading, data} = useQuery('repoData', () =>
    axios
      .get('https://api.github.com/repos/tannerlinsley/react-query')
      .then(res => console.log(res.data))
      .catch(e => {
        console.log(1, e);
      }),
  );

  return (
    <View>
      <Button
        title="Send"
        onPress={() => {
          directLine
            .postActivity({
              type: 'message',
              from: {id: '7'},
              text: 'text3',
            })
            .subscribe(
              id => console.log('Posted activity, assigned ID ', id),
              error => console.log('Error posting activity', error),
            );
        }}
      />
    </View>
  );
};

@iamhaaamed, can you verify that the react-query call using Axios functions correctly. Is it possible that the call is successful but the data being returned is not?

Also, which subscribe is failing? The one in the useEffect() or the one in the Button?

stevkan
I have checked the axios call and it has no issue.
The subscribe in the useEffect() is failing.
This is my example:
https://snack.expo.dev/@iamhaamed/ashamed-truffles

@iamhaaamed, I am having a bit of difficulty setting up the above project. I created an account and cloned/copied it. But, the project doesn't move beyond installing/loading. I've tried solving but I'm unfamiliar with Expo. Do you have any thoughts or recommendations so I can properly attempt a repro?

Closing due to lack of response.