-
Notifications
You must be signed in to change notification settings - Fork 66
PopUpSignIn Feature in NodeJs #39
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| </head> | ||
| <!-- This simulates a login page to show what happens when the user clicks on a button with the signin action. | ||
| When the user clicks on the Login button, it calls notifySuccess() to fake a successful login and trigger a new message to the bot --> | ||
| <body> | ||
| <div> | ||
| User Name : <input type="text" /> | ||
| </div> | ||
| <br /> | ||
| <div> | ||
| Password : <input type="password" /> | ||
| </div> | ||
|
|
||
| <button onClick="submit()">Login</button> | ||
|
|
||
| <script src="https://statics.teams.microsoft.com/sdk/v1.0/js/MicrosoftTeams.min.js"></script> | ||
|
|
||
| <script> | ||
| microsoftTeams.initialize(); | ||
| function submit() | ||
| { | ||
| microsoftTeams.authentication.notifySuccess('PopUpSignInAuthenticationSuccess'); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,13 +43,16 @@ export class Bot extends builder.UniversalBot { | |
|
|
||
| // setup invoke payload handler | ||
| this._connector.onInvoke(this.getInvokeHandler(this)); | ||
|
|
||
| // setup O365ConnectorCard action handler | ||
| this._connector.onO365ConnectorCardAction(this.getO365ConnectorCardActionHandler(this)); | ||
|
|
||
| // setup conversation update handler for things such as a memberAdded event | ||
| this.on("conversationUpdate", this.getConversationUpdateHandler(this)); | ||
|
|
||
| this._connector.onSigninStateVerification((event, query, callback) => | ||
| { | ||
| this.verifySigninState(event, query, callback); | ||
| }); | ||
|
|
||
| // setup compose extension handlers | ||
| // onQuery is for events that come through the compose extension itself including | ||
| // config and auth responses from popups that were started in the compose extension | ||
|
|
@@ -74,7 +77,6 @@ export class Bot extends builder.UniversalBot { | |
| // Clear the stack on invoke, as many builtin dialogs don't play well with invoke | ||
| // Invoke messages should carry the necessary information to perform their action | ||
| session.clearDialogStack(); | ||
|
|
||
| let payload = (event as any).value; | ||
|
|
||
| // Invokes don't participate in middleware | ||
|
|
@@ -91,11 +93,24 @@ export class Bot extends builder.UniversalBot { | |
| }; | ||
| } | ||
|
|
||
| private async verifySigninState( | ||
| event: builder.IEvent, | ||
| query: teams.ISigninStateVerificationQuery, | ||
| callback: (err: Error, body: any, status?: number) => void): Promise<void> | ||
| { | ||
| let session = await loadSessionAsync(this, event); | ||
| if (session) | ||
| { | ||
| session.clearDialogStack(); | ||
| session.send(Strings.popupsignin_successful); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this example, let's pass the user's input username through the notifySuccess call so that the verifyState handler in the bot can present that field in the outgoing message - so here, the handler should grab the passed in value and send that out in the message. |
||
| } | ||
| callback(null, "", 200); | ||
| } | ||
|
|
||
| // set incoming event to any because membersAdded is not a field in builder.IEvent | ||
| private getConversationUpdateHandler(bot: builder.UniversalBot): (event: any) => void { | ||
| return async function(event: any): Promise<void> { | ||
| let session = await loadSessionAsync(bot, event); | ||
|
|
||
| if (event.membersAdded && event.membersAdded[0].id && event.membersAdded[0].id.endsWith(config.get("bot.botId"))) { | ||
| session.send(Strings.bot_introduction); // probably only works in Teams | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import * as builder from "botbuilder"; | ||
| import { TriggerActionDialog } from "../../../utils/TriggerActionDialog"; | ||
| import { DialogIds } from "../../../utils/DialogIds"; | ||
| import { DialogMatches } from "../../../utils/DialogMatches"; | ||
| import { Strings } from "../../../locale/locale"; | ||
| import * as config from "config"; | ||
|
|
||
| // Demonstrates using a signin action to show a login page in a popup | ||
| export class PopupSignInDialog extends TriggerActionDialog { | ||
|
|
||
| private static async popupsignin(session: builder.Session, args?: any | builder.IDialogResult<any>, next?: (args?: builder.IDialogResult<any>) => void): Promise<void> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Change name of function to sendPopupSigninCard
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| let popUpUrl = config.get("app.baseUri") + "/botViews/popUpSignin.html"; | ||
|
|
||
| session.send( | ||
| new builder.Message(session).addAttachment( | ||
| new builder.HeroCard(session) | ||
| .title(Strings.popupsignin_card_title) | ||
| .buttons([ | ||
| new builder.CardAction(session) | ||
| .type("signin") | ||
| .title(Strings.popupsignin_button_title) | ||
| .value(popUpUrl)]))); | ||
| session.endDialog(); | ||
| } | ||
|
|
||
| constructor( | ||
| bot: builder.UniversalBot, | ||
| ) { | ||
| super(bot, | ||
| DialogIds.PopupSignInDialogId, | ||
| DialogMatches.PopUpSignInDialogMatch, | ||
| PopupSignInDialog.popupsignin, | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,5 +119,8 @@ | |
| "open_uri": "Open Uri", | ||
| "message_summary": "A sample O365 actionable card", | ||
| "o365connectorcard_action_response": "<h2>Thanks, %s!</h2><br/><h3>Your input action ID:</h3><br/><pre>%s</pre><br/><h3>Your input body:</h3><br/><pre>%s</pre>", | ||
| "end_of_example_string_responses": "******************************* EVERYTHING ABOVE HERE IS FOR A TEMPLATE EXAMPLE DIALOG *******************************" | ||
| "end_of_example_string_responses": "******************************* EVERYTHING ABOVE HERE IS FOR A TEMPLATE EXAMPLE DIALOG *******************************", | ||
| "popupsignin_card_title":"Please click below for Popup Sign-In experience", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move these three strings above the "****************" line so that the user knows they are strings used by examples.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| "popupsignin_button_title":"Sign In", | ||
| "popupsignin_successful":"Authentication Successful!!" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ export const DialogIds = { | |
| HelloDialogId: "HelloDialog", | ||
| HelpDialogId: "HelpDialog", | ||
| HeroCardDialogId: "HeroCardDialog", | ||
| PopupSignInDialogId: "PopupSignInDailog", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: PopupSignInDialog (not Dailog)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vamagra - Need to fix the other 'Dailog' in this line.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| MessageBackReceiverDialogId: "MessageBackReceiverDialog", | ||
| MultiDialogId: "MultiDialog", | ||
| MultiDialog2Id: "MultiDialog2", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ export const DialogMatches = { | |
| HelloDialogMatch2: /hi/i, | ||
| HelpDialogMatch: /help/i, | ||
| HeroCardDialogMatch: /hero card/i, | ||
| PopUpSignInDialogMatch: /sign in/i, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make the space in the regex optional so if I typed "sign in" or "signin", it would trigger the dialog.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| MessageBackReceiverDialogMatch: /incoming message from messageBack button/i, | ||
| MultiDialogMatch: /multi dialog 1/i, | ||
| MultiDialog2Match: /multi dialog 2/i, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this example, let's pass the user's input username through the notifySuccess call so that the verifyState handler in the bot can present that field in the outgoing message.