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

teamsNotifyUser does not accept messages returned from MessageFactory. #4154

Closed
eoinobrien opened this issue Mar 10, 2022 · 3 comments · Fixed by #4166
Closed

teamsNotifyUser does not accept messages returned from MessageFactory. #4154

eoinobrien opened this issue Mar 10, 2022 · 3 comments · Fixed by #4166
Assignees
Labels
bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team.
Milestone

Comments

@eoinobrien
Copy link

Github issues should be used for bugs and feature requests. Use Stack Overflow for general "how-to" questions.

Versions

What package version of the SDK are you using: 1.15.0
What nodejs version are you using: 16.11.0
What browser version are you using: n/a, this is a typescript compiler error
What os are you using: Win 11, 22H2, 22567.200

Describe the bug

When using teamsNotifyUser in a typescript application the example provided by the docs on how to notify someone does not work.
Instead, the following error is returned:

Argument of type 'Partial<Activity>' is not assignable to parameter of type 'Activity'.
  Property 'type' is optional in type 'Partial<Activity>' but required in type 'Activity'.ts(2345)

This is because MessageFactory.text('Message'); returns a Partial<Activity> while teamsNotifyUser() requires a straight Activity.

To Reproduce

  1. In Teams Toolkit, create a new app. Selecting only Bot as a capability and Typescript as the language.
  2. In bot/teamsBot.ts replace
case "welcome": {
    const card = AdaptiveCards.declareWithoutData(rawWelcomeCard).render();
    await context.sendActivity({ attachments: [CardFactory.adaptiveCard(card)] });
    break;
}

with

case "welcome": {
    let message = MessageFactory.text("You'll get a notification, if you've turned them on.");
    teamsNotifyUser(message);
    await context.sendActivity(message);
}
  1. From ./bot run npm run build
  2. See the following build error:
teamsBot.ts:39:27 - error TS2345: Argument of type 'Partial<Activity>' is not assignable to parameter of type 'Activity'.
  Property 'type' is optional in type 'Partial<Activity>' but required in type 'Activity'.

39           teamsNotifyUser(message);

Expected behavior

To be able to call teamsNotifyUser() with the value returned from the MessageFactory.

Screenshots

image

image

Additional context

I debated creating a bug against the SDK or the docs but felt it made more sense to create it here.

@eoinobrien eoinobrien added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Mar 10, 2022
@breakingram
Copy link
Contributor

Hey @eoinobrien, have you tried using type assertion to bypass the error?

example:

teamsNotifyUser(message as Activity);

Let me know if this worked. Thanks.

@mrivera-ms mrivera-ms added this to the R16 milestone Mar 15, 2022
@eoinobrien
Copy link
Author

Hi @ramfattah,

Good catch that does solve the problem thanks for suggesting.

Should I create a bug against the Docs to fix the issue here: https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/conversation-messages?tabs=typescript#notifications-to-your-message or is that something you can do?

@ceciliaavila
Copy link
Collaborator

@mrivera-ms in progress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team.
Projects
None yet
5 participants