Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Comments

PopUpSignIn Feature in NodeJs#39

Open
vamagra wants to merge 4 commits intomasterfrom
BotTemplateNodeJs
Open

PopUpSignIn Feature in NodeJs#39
vamagra wants to merge 4 commits intomasterfrom
BotTemplateNodeJs

Conversation

@vamagra
Copy link
Contributor

@vamagra vamagra commented Jan 4, 2018

@msftdherron @jotrick @goelashish7 @jialic @aosolis @MattSFT

Added Sample for PopUpSignIn in NodeJs App.

import { HelloDialog } from "./examples/basic/HelloDialog";
import { HelpDialog } from "./examples/basic/HelpDialog";
import { HeroCardDialog } from "./examples/basic/HeroCardDialog";
import { PopupSignInDailog } from "./examples/basic/PopupSignInDailog";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here Dailog->Dialog


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> {

Choose a reason for hiding this comment

The 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"?

<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 -->
Copy link
Contributor

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."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (session) {
session.clearDialogStack();
session.send("Authentication Successful!!");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blank line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/Bot.ts Outdated
}

private SigninHandler(bot: builder.UniversalBot): (event: builder.IEvent, query: teams.ISigninStateVerificationQuery, callback: (err: Error, body: any, status?: number) => void) => void {
return async function (
Copy link
Contributor

Choose a reason for hiding this comment

The 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:
this._connector.onSigninStateVerification((event, query, callback) => { this.verifySigninState(event, query, callback); });
and put your logic in the private member function verifySigninState().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* main purpose of this class is to Display the PopUp SignIn Card
*/

// let input = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scrub for random commented out code like this, and delete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

let buttons = new Array<builder.CardAction>();
/**
* This is PopUp SignIn Dialog Class.
* main purpose of this class is to Display the PopUp SignIn Card
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Should this be here, or up on line 6, as a comment to the class itself?
  2. I'd say something like this instead "Demonstrates using a signin action to show a login page in a popup"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


buttons.push(new builder.CardAction(session)
.type("signin")
.title("Sign In")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jotrick is there a principle we follow in this project for when a string goes in index.json vs. inline in the ts file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jotrick has used index.json for string constant, I have used the same now.

cards.push(newCard);

session.send(new builder.Message(session)
.attachments(cards));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for a single attachment you can use addAttachment, and avoid constructing the "cards" array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


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> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: TS convention is lowercase method names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

.value(popUpUrl),
);

let newCard = new builder.HeroCard(session)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"newCard" feels too generic, "signinCard" might be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


let newCard = new builder.HeroCard(session)
.title("Please click below for Popup Sign-In experience")
.buttons(buttons);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can inline this array, like
.buttons([
new builder.CardAction(session)...
]);

unless you intentionally did it this way to be extra-clear?
Not sure if this project has conventions one way or another @jotrick.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// 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> {
Copy link
Contributor

@jotrick jotrick Jan 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Change name of function to sendPopupSigninCard

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

microsoftTeams.initialize();
function submit()
{
microsoftTeams.authentication.notifySuccess('PopUpSignInAuthenticationSuccess');
Copy link
Contributor

@jotrick jotrick Jan 29, 2018

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.

src/Bot.ts Outdated
if (session)
{
session.clearDialogStack();
session.send(Strings.popupsignin_successful);
Copy link
Contributor

@jotrick jotrick Jan 29, 2018

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 - so here, the handler should grab the passed in value and send that out in the message.

"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",
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

HelloDialogMatch2: /hi/i,
HelpDialogMatch: /help/i,
HeroCardDialogMatch: /hero card/i,
PopUpSignInDialogMatch: /sign in/i,
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

{
elem.value = Math.floor((Math.random() * 10000) + 1);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blank line

{
magicNumber = document.getElementById('txtMagicNumber').value;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants