-
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 1 commit
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> | ||
| <!--Purpose of this login html page is to show fake authentication when user clicks on SignIn Action --> | ||
| <!--This login page will do nothing, except when user will click on Login page it will post back to Main controller --> | ||
| <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'); | ||
|
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. |
||
| } | ||
| </script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,12 +43,11 @@ 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(this.SigninHandler(this)); | ||
|
|
||
| // setup compose extension handlers | ||
| // onQuery is for events that come through the compose extension itself including | ||
|
|
@@ -91,6 +90,23 @@ export class Bot extends builder.UniversalBot { | |
| }; | ||
| } | ||
|
|
||
| private SigninHandler(bot: builder.UniversalBot): (event: builder.IEvent, query: teams.ISigninStateVerificationQuery, callback: (err: Error, body: any, status?: number) => void) => void { | ||
| return async function ( | ||
|
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. We should change this getXXXHandler() pattern as it's not clear how to access private members in the handler (this confused Shoeb who was working on the Trello CE). Better to do something like this:
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. |
||
| event: builder.IEvent, | ||
| query: teams.ISigninStateVerificationQuery, | ||
| callback: (err: Error, body: any, status?: number) => void, | ||
| ): Promise<void> | ||
| { | ||
| let session = await loadSessionAsync(bot, event); | ||
| if (session) { | ||
| session.clearDialogStack(); | ||
| session.send("Authentication 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. Remove blank 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. |
||
| } | ||
| 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> { | ||
|
|
@@ -119,4 +135,5 @@ export class Bot extends builder.UniversalBot { | |
| callback(null, null, 200); | ||
| }; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import { GetLastDialogUsedDialog } from "./examples/basic/GetLastDialogUsedDialo | |
| import { HelloDialog } from "./examples/basic/HelloDialog"; | ||
| import { HelpDialog } from "./examples/basic/HelpDialog"; | ||
| import { HeroCardDialog } from "./examples/basic/HeroCardDialog"; | ||
| import { PopupSignInDailog } from "./examples/basic/PopupSignInDailog"; | ||
|
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 here Dailog->Dialog |
||
| import { MessageBackReceiverDialog } from "./examples/basic/MessageBackReceiverDialog"; | ||
| import { MultiDialog } from "./examples/basic/MultiDialog"; | ||
| import { O365ConnectorCardActionsDialog } from "./examples/basic/O365ConnectorCardActionsDialog"; | ||
|
|
@@ -72,6 +73,7 @@ export class RootDialog extends builder.IntentDialog { | |
| new HelloDialog(bot); | ||
| new HelpDialog(bot); | ||
| new HeroCardDialog(bot); | ||
| new PopupSignInDailog(bot); | ||
| new MessageBackReceiverDialog(bot); | ||
| new MultiDialog(bot); | ||
| new O365ConnectorCardActionsDialog(bot); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import * as builder from "botbuilder"; | ||
| import { TriggerActionDialog } from "../../../utils/TriggerActionDialog"; | ||
| import { DialogIds } from "../../../utils/DialogIds"; | ||
| import { DialogMatches } from "../../../utils/DialogMatches"; | ||
| import * as config from "config"; | ||
|
|
||
| export class PopupSignInDailog extends TriggerActionDialog { | ||
|
|
||
| private static async step1(session: builder.Session, args?: any | builder.IDialogResult<any>, next?: (args?: builder.IDialogResult<any>) => void): Promise<void> { | ||
|
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. there IS only one step, right? so maybe a more descriptive name than "step1"? |
||
| let cards = new Array<builder.HeroCard>(); | ||
|
|
||
| let buttons = new Array<builder.CardAction>(); | ||
| /** | ||
| * This is PopUp SignIn Dialog Class. | ||
| * main purpose of this class is to Display the PopUp SignIn Card | ||
| */ | ||
|
|
||
| // let input = ""; | ||
| // if (args.response) { | ||
| // input = args.response; | ||
| // } | ||
|
|
||
| let popUpUrl = config.get("app.baseUri") + "/botViews/popUpSignin.html"; | ||
|
|
||
| buttons.push(new builder.CardAction(session) | ||
| .type("signin") | ||
| .title("Sign In") | ||
| .value(popUpUrl), | ||
| ); | ||
|
|
||
| let newCard = new builder.HeroCard(session) | ||
| .title("Please click below for Popup Sign-In experience") | ||
| .buttons(buttons); | ||
|
|
||
| cards.push(newCard); | ||
|
|
||
| session.send(new builder.Message(session) | ||
| .attachments(cards)); | ||
| session.endDialog(); | ||
| } | ||
|
|
||
| constructor( | ||
| bot: builder.UniversalBot, | ||
| ) { | ||
| super(bot, | ||
| DialogIds.PopupSignInDialogId, | ||
| DialogMatches.PopUpSignInDialogMatch, | ||
| PopupSignInDailog.step1, | ||
| ); | ||
| } | ||
| } | ||
| 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, | ||
|
|
||
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.
"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."
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.
Done.