Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting JSON.parse error in teamsFx internal file when the conversation is initiated from the MS Teams #12887

Open
bhaskar-012024 opened this issue Dec 10, 2024 · 8 comments
Assignees
Labels

Comments

@bhaskar-012024
Copy link

Key Components Used:

  1. Azure Bot: For creation of the Bot which is referred in the Teams app. Here the target was the Azure WebApp. Any message to the bot will go through the Azure Bot and then to the Azure WebApp
  2. Azure WebApp: This is the place where my Node.js server resides and here we are using teams toolkit(teamsFx) for developed logic related to the bot interaction. It is Linux based server.

Recently we started getting errors when the user interacts with the Bot via Teams app. Interesting thing is we haven't made any changes to the Azure Bot or WebApp or any component in the structure recently but suddenly we stated seeing below error that is refereeing to a JSON.parse statement in the @microsoft/teamsfx/dist/index.node.cjs.js internal file, which obviously we haven't directly called in any of our code. Previously it is working perfectly fine, and we don't have any issue but not sure why we are receiving this error now without any change in configuration or code.

When we test the same bot directly from the Azure portal inside Azure Bot> Settings> Test in Web Chat it is working perfectly fine but we are getting issue only when there is any conversation from the MS Teams channel.

image

I am using the TeamsFx version of 2.3.1 and i tried to update it to 2.3.2 and 2.3.3 but still facing the issue. My Azure app node version was 20 and i tried with 18 also but no luck.

Please let me know if any further information is required. Any help in resolving issue is much appreciated.

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs attention This issue needs the attention of a contributor. label Dec 10, 2024
@sayali-MSFT
Copy link

Hello @bhaskar-012024 , Thank you for your inquiry about your Teams app development issue! To assist you better, could you please provide the following details?

Reproduction Steps: Please share the steps you took to encounter the issue.

Documentation Links: Any specific documentation you followed that relates to your problem.

Teams Client Version: What version of the Teams client are you using?

Code Snippets: Relevant code snippets that illustrate the issue.

This information will help us better understand the situation and provide a more accurate response.

@tecton
Copy link
Contributor

tecton commented Dec 12, 2024

Hi @bhaskar-012024, what kind of API have you used from @microsoft/teamsfx? E.g. notification?

@adashen adashen added investigating TA:E2E Team Area: E2E needs more info Need user to provide more info and removed needs attention This issue needs the attention of a contributor. labels Dec 12, 2024
@bhaskar-012024
Copy link
Author

bhaskar-012024 commented Dec 12, 2024

Hi @tecton ,
Yes, I am importing teamsfx and using it in below style as suggested in some of the examples inorder to send the proactive message.

const { BotBuilderCloudAdapter } = require('@microsoft/teamsfx');
const ConversationBot = BotBuilderCloudAdapter.ConversationBot;

const notificationApp = new ConversationBot({
// See https://aka.ms/about-bot-adapter to learn more about adapters.
adapter,
// Enable notification
notification: {
enabled: true
}
}
);

const member1 = await notificationApp.notification.findMember(
async (m) => {
return m.parent.conversationReference.user.id === userId;
}
);

@microsoft-github-policy-service microsoft-github-policy-service bot added needs attention This issue needs the attention of a contributor. and removed needs more info Need user to provide more info labels Dec 12, 2024
@tecton
Copy link
Contributor

tecton commented Dec 12, 2024

Hi @bhaskar-012024, it might be caused by the corrupted cache file. Could you please delete/check the ".notification.localstore.json" file and try again?

@bhaskar-012024
Copy link
Author

Yes @tecton , thank you for providing the resolution. Now it is working as expected.
Is there anything I need to do in order to avoid this kind of issue or it is completely internal within the framework.

@tecton
Copy link
Contributor

tecton commented Dec 16, 2024

Hi @bhaskar-012024, this file is used as a default implementation to persist bot notification target references in the file. It's recommended to use your own store for production environment by extending interface ConversationReferenceStore. (link) We'll improve the error message for easier troubleshooting.

@adashen adashen removed the needs attention This issue needs the attention of a contributor. label Dec 16, 2024
@bhaskar-012024
Copy link
Author

Hi @tecton ,

I have gone through this documentation for ConversationReferenceStore and its methods like add, list and remove. I understand like this is used to store the conversation reference of the user interacted with the bot and use it later to only send proactive message.

Code structure where i am using notificationApp

const { BotBuilderCloudAdapter } = require('@microsoft/teamsfx');
const ConversationBot = BotBuilderCloudAdapter.ConversationBot;

const notificationApp = new ConversationBot({
// See https://aka.ms/about-bot-adapter to learn more about adapters.
adapter,
// Enable notification
notification: {
enabled: true
}
}
);

Case1 : To retrieve email
const member1 = await notificationApp.notification.findMember(
async (m) => {
return m.parent.conversationReference.user.id === userId;
}
);
const userEmail = member1.account.email;

Case 2: To identify user by email and send notification
const member = await notificationApp.notification.findMember(
async (m) => {
return m.account.email.toLowerCase() ===
}, SearchScope.Person
);

Then using member.parent.conversationReference proprty to get the conversation reference , user id, service url and sending proactive message using
await connector.conversations.sendToConversation(conversationReferenceId, proactiveMessage);

Do i need to still use ConversationReferenceStore and store the details even if I was not using then to send the proactive message?
Can you please also share any teams sample example where we use ConversationReferenceStore, that helps me to implement it?
Thanks in advance.

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs attention This issue needs the attention of a contributor. label Dec 16, 2024
@tecton
Copy link
Contributor

tecton commented Dec 17, 2024

Hi @bhaskar-012024, yes you need to use conversation reference store to find member. You can choose what properties to store when implement the interface.
Please refer to the following implementation in samples that leverage Azure storage.

  1. https://github.com/OfficeDev/teams-toolkit-samples/blob/dev/large-scale-notification/src/internal/tableStore.ts
  2. https://github.com/OfficeDev/teams-toolkit-samples/blob/dev/adaptive-card-notification/src/store/blobStore.ts

@adashen adashen removed the needs attention This issue needs the attention of a contributor. label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants