Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setupMultiUserAddressTest(bot);
const askForUser1Name = new Message()
.text('What is my name?')
.address(defaultAddress)
.toMessage();
const address = {
user: {
id: user2Address.user.id
}
} as IAddress;
// partial addresses work as well (i.e. if you only want to check one field such as userId)
const expectedPartialAddress = new Message()
.address(address)
.toMessage();
return t.throws(new BotTester(bot, getTestOptions(t))
.sendMessageToBot(askForUser1Name, expectedPartialAddress)
.runTest()
);
});
switch (session.message.value.action)
{
case "signout":
session.userData.aadTokens = {};
session.send("Ok, I've cleared your tokens.");
break;
case "getProfile":
// See if we have an AAD token
const graphResource = "https://graph.microsoft.com";
let aadTokens = session.userData.aadTokens || {};
let graphToken = aadTokens[graphResource] as TokenResponse;
if (!graphToken) {
// We don't have a Graph token for the user, ask them to sign in
session.send(new builder.Message(session)
.addAttachment(new builder.HeroCard(session)
.text("You're not yet signed in. Please click on the Sign In button to log in.")
.buttons([
new builder.CardAction(session)
.type("signin")
.title("Sign In")
.value(config.get("app.baseUri") + "/bot-auth/simple-start?width=5000&height=5000"),
])));
} else {
// Use the Graph token to get the basic profile
try {
let requestHelper = new AADRequestAPI();
let response = await requestHelper.getAsync("https://graph.microsoft.com/v1.0/me/", { Authorization: "Bearer " + graphToken.access_token }, null);
let info = JSON.parse(response);
session.send(info.displayName + "<br>" + info.mail + "<br>" + info.officeLocation);
.displayText(Strings.messageBack_button_display_text)
.title(Strings.update_card_button)
.text("update card message"); // This must be a string that routes to UpdateCardMsgDialog, which handles card updates
let card = new builder.HeroCard(session)
.title(Strings.default_title)
.subtitle(Strings.default_subtitle)
.text(Strings.default_text)
.images([
new builder.CardImage(session)
.url(config.get("app.baseUri") + "/assets/computer_person.jpg")
.alt(session.gettext(Strings.img_default)),
])
.buttons([messageBackButton]);
let msg = new builder.Message(session)
.addAttachment(card);
session.endDialog(msg);
}
function canvasToMessage(session, canvas, player) {
return new builder.Message(session)
.text((player != 0) ? ((player > 0) ? "You moved 🔴" : "Computer moved 🔵") : "Waiting for your move")
.attachments([{
contentType: "image/png",
contentUrl: canvas.toDataURL()
}]);
}
private convertToIMessage(msg: string | IMessage): IMessage {
if (typeof(msg) === 'string') {
return new Message()
.text(msg as string)
.address(this.config.defaultAddress)
.toMessage();
}
return msg;
}
protected async showUserProfile(session: builder.Session): Promise {
let azureADApi = this.authProvider as AzureADv1Provider;
let userToken = this.getUserToken(session);
if (userToken) {
let profile = await azureADApi.getProfileAsync(userToken.accessToken);
let profileCard = new builder.ThumbnailCard()
.title(profile.displayName)
.subtitle(profile.userPrincipalName)
.text(`<b>E-mail</b>: ${profile.mail}<br>
<b>Title</b>: ${profile.jobTitle}<br>
<b>Office location</b>: ${profile.officeLocation}`);
session.send(new builder.Message().addAttachment(profileCard));
} else {
session.send("Please sign in to AzureAD so I can access your profile.");
}
await this.promptForAction(session);
}
}
bot.dialog('HelpDialog', function (session) {
var card = new builder.HeroCard(session)
.title('help_title')
.buttons([
builder.CardAction.imBack(session, 'roll some dice', 'Roll Dice'),
builder.CardAction.imBack(session, 'play craps', 'Play Craps')
]);
var msg = new builder.Message(session)
.speak(speak(session, 'help_ssml'))
.addAttachment(card)
.inputHint(builder.InputHint.acceptingInput);
session.send(msg).endDialog();
}).triggerAction({ matches: /help/i });
function sendProactiveMessage(addr) {
var msg = new builder.Message().address(addr);
msg.text('Hello, this is a notification');
msg.textLocale('en-US');
bot.send(msg);
}
processMessage(message) {
if (this.onEventHandler) {
var msg = new botbuilder.Message()
.address({
channelId: 'console',
user: {id: 'user', name: 'User1'},
bot: {id: 'bot', name: 'Bot'},
conversation: {id: 'Convo1'}
})
.timestamp()
.text(message);
this.onEventHandler([msg.toMessage()]);
}
return this;
}
function sendLocationPrompt(session: Session, prompt: string): Session {
var message = new Message(session).text(prompt).sourceEvent({
facebook: {
quick_replies: [
{
content_type: "location"
}
]
}
});
return session.send(message);
}