I’m having some major issues optimizing a notification bot made with Teams Toolkit.
My main problem is that:
const member = await notificationApp.notification.findMember( async (m) => m.account.email === email );
It takes too long. With barely 50 members, it takes 1 minute to execute that, which means that to send 50 single messages it’s taking almost one hour.
So I hosted a Redis service on Azure, and I wanted to save the user inside Redis, reducing the time to read the user. The problem is that I cannot build the Member from the info I’m saving on Redis. Considering that I can just save JSON on Redis, I saved what I could and I’m trying to build Member class from its constructor. This is more or less what I have done:
let memberFromRedis = await getMemberFromRedis(email); const account = memberFromRedis["account"] as TeamsChannelAccount;
const conversationReference = memberFromRedis["parent"]["conversationReference"];
const teamsBotInstallation = await notificationApp.notification.buildTeamsBotInstallation(conversationReference);
// @ts-ignore const user = new Member(teamsBotInstallation , account);
I’m using ts-ignore because I’m getting this weird type of
error :
translated it’s:
Argument type ‘TeamsBotInstallation_2’ it is not assignable to
parameeter type ‘TeamsBotInstallation’. Types of property ‘adapter’
are not compatible. In the type ‘CloudAdapter’ are missing the
following properties of the type ‘BotFrameworkAdapter’:
TokenApiClientCredentialKey, credentials, credentialsProvider,
settings and other 41.
but inside the types I can see:
TeamsBotInstallation_2 as TeamsBotInstallation,
so they should be the same type right?
anyway, debugging this code seems the user is the same but when I come to
await user.sendMessage("test");
I’m getting this
error :
{ "code": "Internal", "message": "Error:CloudAdapterBase.continueConversationis deprecated, please useCloudAdapterBase.continueConversationAsync" }
for some reason, the type coming back from findMember (Member_2)
looks slightly different from the Member
class, even tho in this case as well I can see from types export Member_2
as Member
, so I expect them to be the same.
With some breakpoints, I can notice just a small:
difference
the functions (not just this one but sendAdaptiveCard and the others
as well) seem to point to different locations, the type of the object
seems different..
is this normal or is this the problem? anyway, how can I solve that?
I tried creating the Member from its constructor, parsing with JSON, parsing with ‘as Member’, and tried everything, but no way to get this work.
2
Answers
Issue Summary:
You are facing issues with the
Member
class and thesendMessage
method in your notification bot built with Teams Toolkit, encountering type incompatibility and deprecation warnings.Understanding the Issue:
CloudAdapterBase.continueConversation
is deprecated; useCloudAdapterBase.continueConversationAsync
instead.Solution Steps:
const user = new Member(teamsBotInstallation as TeamsBotInstallation, account);
.continueConversationAsync
as recommended.Member
object returned by thefindMember
method directly to avoid compatibility issues.Code Adjustment:
By directly using the
Member
object fromfindMember
, you avoid type compatibility issues and deprecated methods.Additional Resources:
Following the steps and ensuring correct usage of types and methods should resolve your notification bot issues in Teams Toolkit.
There’re two
Member
types in TeamsFx SDK:The first one is actually deprecated as one of its property (conversation) TeamsBotInstallation is deprecated and it’s recommend to use the new type with the same name (conversationWithCloudAdapter) TeamsBotInstallation
There’s type error from your code is, type of (conversationWithCloudAdapter) TeamsBotInstallation is retuned by
buildTeamsBotInstallation
, while the constructor of (conversation) Member requires type of (conversation) TeamsBotInstallationFor your issue, you may take a look at the sample app of Large Scale Notification Bot if you have performance concerns about sending notifications.