Skip to content

Commit

Permalink
added env varialbes
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurnford committed Sep 10, 2019
1 parent feb08e0 commit 955ad6c
Show file tree
Hide file tree
Showing 33 changed files with 229 additions and 159 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PUBLIC_URL=https://tdurnford.github.io/BotFramework-Offline-MockBot/
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"copy-webpack-plugin": "^5.0.3",
"core-js": "^3.1.4",
"css-loader": "^3.0.0",
"dotenv": "^8.1.0",
"eslint": "^6.0.1",
"eslint-config-standard": "^13.0.1",
"eslint-plugin-import": "^2.18.0",
Expand Down
11 changes: 5 additions & 6 deletions src/Adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Observable from 'core-js/features/observable';

import MockBot from '../MockBot';

export const USER_PROFILE = { id: 'user', name: 'user', role: 'user' };
export const USER_PROFILE = { id: 'user', role: 'user' };
export const BOT_PROFILE = { id: 'bot', name: 'bot', role: 'bot' };

/**
Expand Down Expand Up @@ -37,7 +37,6 @@ export default class WebChatAdapter extends BotAdapter {
id,
conversation: { id: 'bot' },
channelId: 'webchat',
from: USER_PROFILE,
recipient: BOT_PROFILE,
timestamp
};
Expand Down Expand Up @@ -114,13 +113,13 @@ export default class WebChatAdapter extends BotAdapter {
}

export const createDirectLine = ({ processor } = {}) => {
const memory = new MemoryStorage();
const conversationState = new ConversationState(memory);
const userState = new UserState(memory);

const mockBotAdapter = new WebChatAdapter();

if (!processor) {
const memory = new MemoryStorage();
const conversationState = new ConversationState(memory);
const userState = new UserState(memory);

const mockBot = new MockBot({ conversationState, userState });

mockBotAdapter.processActivity(async (context) => {
Expand Down
2 changes: 1 addition & 1 deletion src/MockBot/commands/Accessibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function processor(context: TurnContext) {
await DocumentWord.processor(context);
await Image.processor(context);
await ImageSVG.processor(context);
await Layout.processor(context);
await Layout.processor(context, { args: '' });
await Layout.processor(context, { args: 'single' });
await Layout.processor(context, { args: 'single carousel' });
await Layout.processor(context, { args: 'double' });
Expand Down
2 changes: 1 addition & 1 deletion src/MockBot/commands/AdaptiveCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const processor = async (context: TurnContext, { args }: { args: string }) => {
const contents = names.filter(name => name).map(name => getCardJSON(name));

if (contents && contents.length) {
let text = `Showing ${ names.filter(name => name).join(', ') }`;
let text = `Showing ${ names.filter(name => name).join(', ') }`;

await context.sendActivity({
type: 'message',
Expand Down
3 changes: 2 additions & 1 deletion src/MockBot/commands/AnimationCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const help = () => ({
});

const processor = async (context: TurnContext) => {
const { PUBLIC_URL } = process.env;

await context.sendActivity({
type: 'message',
Expand All @@ -16,7 +17,7 @@ const processor = async (context: TurnContext) => {
text: 'No buttons, No Image, Autoloop, Autostart, Sharable',
media: [{
profile: 'animation',
url: `./assets/surface_anim.gif`,
url: `${PUBLIC_URL}assets/surface_anim.gif`,
}],
autoloop: true,
autostart: true
Expand Down
4 changes: 2 additions & 2 deletions src/MockBot/commands/Audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const help = () => ({
});

const processor = async (context: TurnContext) => {

const { PUBLIC_URL } = process.env;

await context.sendActivity({
type: 'message',
text: '',
attachments: [{
contentType: 'audio/mpeg',
contentUrl: `./assets/bftest.mp3`,
contentUrl: `${PUBLIC_URL}assets/bftest.mp3`,
name: 'BotFramework Test'
}]
});
Expand Down
3 changes: 2 additions & 1 deletion src/MockBot/commands/Cards/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export default () => ({
"value": "3"
}
],
"id": "CompactSelectVal"
"id": "CompactSelectVal",
"style": "expanded"
},
{
"type": "TextBlock",
Expand Down
9 changes: 5 additions & 4 deletions src/MockBot/commands/Carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const help = () => ({
});

const processor = async (context: TurnContext) => {
const { PUBLIC_URL } = process.env;

await context.sendActivity({
type: 'message',
Expand All @@ -17,7 +18,7 @@ const processor = async (context: TurnContext) => {
subtitle: 'This is the subtitle',
text: 'Price: $XXX.XX USD',
images: [{
url: `./assets/surface1.jpg`
url: `${PUBLIC_URL}assets/surface1.jpg`
}],
buttons: [{
type: 'imBack',
Expand All @@ -36,7 +37,7 @@ const processor = async (context: TurnContext) => {
subtitle: 'This is the subtitle',
text: 'Price: $XXX.XX USD',
images: [{
url: `./assets/surface2.jpg`
url: `${PUBLIC_URL}assets/surface2.jpg`
}],
buttons: [{
type: 'imBack',
Expand All @@ -55,7 +56,7 @@ const processor = async (context: TurnContext) => {
subtitle: 'This is the subtitle',
text: 'Price: $XXX.XX USD',
images: [{
url: `./assets/surface3.jpg`
url: `${PUBLIC_URL}assets/surface3.jpg`
}],
buttons: [{
type: 'imBack',
Expand All @@ -74,7 +75,7 @@ const processor = async (context: TurnContext) => {
subtitle: 'This is the subtitle',
text: 'Price: $XXX.XX USD',
images: [{
url: `./assets/surface4.jpg`
url: `${PUBLIC_URL}assets/surface4.jpg`
}],
buttons: [{
type: 'imBack',
Expand Down
5 changes: 3 additions & 2 deletions src/MockBot/commands/Default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { TurnContext } from 'botbuilder-core';

const processor = async (context: TurnContext) => {
const { activity: { text }} = context;
const unknown = text.replace(/\.$/, '');
await context.sendActivity({
speak: `Unknown command: I don't know ${ text }. You can say "help" to learn more.`,
text: `Unknown command: \`${ text }\`.\r\n\r\nType \`help\` to learn more.`,
speak: `Unknown command: I don't know ${ unknown }. You can say "help" to learn more.`,
text: `Unknown command: \`${ unknown }\`.\r\n\r\nType \`help\` to learn more.`,
});
};

Expand Down
3 changes: 2 additions & 1 deletion src/MockBot/commands/DocumentPlain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ const help = () => ({
});

async function processor(context: TurnContext) {
const { PUBLIC_URL } = process.env;

await context.sendActivity({
type: 'message',
attachments: [{
contentType: 'text/plain',
contentUrl: `./assets/test.txt`,
contentUrl: `${PUBLIC_URL}assets/test.txt`,
name: 'test.txt'
}]
});
Expand Down
3 changes: 2 additions & 1 deletion src/MockBot/commands/DocumentWord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ const help = () => ({
});

async function processor(context: TurnContext) {
const { PUBLIC_URL } = process.env;

await context.sendActivity({
type: 'message',
attachments: [{
contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
contentUrl: `./assets/test.docx`,
contentUrl: `${PUBLIC_URL}assets/test.docx`,
name: 'test.docx'
}]
});
Expand Down
6 changes: 3 additions & 3 deletions src/MockBot/commands/Echo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const help = () => ({
'echo "Hello\nWorld!"': 'Parse the message as JSON and echo back'
});

const processor = async (context: TurnContext, { args }) => {
const processor = async (context: TurnContext, { text }) => {

const text = args[0] === '"' ? onErrorResumeNext(() => JSON.parse(args)) || '[Error while parsing the JSON]' : args;
const echo = text[0] === '"' ? onErrorResumeNext(() => JSON.parse(text)) || '[Error while parsing the JSON]' : text;

await context.sendActivity('Echoing back in a separate activity.');
await context.sendActivity(text);
await context.sendActivity(echo);
}

export default {
Expand Down
5 changes: 3 additions & 2 deletions src/MockBot/commands/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ const help = () => ({
});

async function processor(context: TurnContext) {
const { PUBLIC_URL } = process.env;

await context.sendActivity({
type: 'message',
text: 'The reports are ready, see attached.',
attachments: [{
contentType: 'application/octet-stream',
contentUrl: `./assets/test.txt`,
contentUrl: `${PUBLIC_URL}assets/test.txt`,
name: 'Plain text'
}, {
contentType: 'application/octet-stream',
contentUrl: `./assets/test.docx`,
contentUrl: `${PUBLIC_URL}assets/test.docx`,
name: 'Word document'
}]
});
Expand Down
26 changes: 25 additions & 1 deletion src/MockBot/commands/HeroCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const help = () => ({
});

const processor = async (context: TurnContext, { args }) => {
const { PUBLIC_URL } = process.env;

const heroCard = {
contentType: 'application/vnd.microsoft.card.hero',
Expand All @@ -22,7 +23,7 @@ const processor = async (context: TurnContext, { args }) => {
title: 'Tapped it!',
value: `https://webchat-mockbot.azurewebsites.net/public/testurl1.html`
},
url: `./assets/surface1.jpg`,
url: `${PUBLIC_URL}assets/surface1.jpg`,
}],
tap: {
type: 'openUrl',
Expand All @@ -39,6 +40,29 @@ const processor = async (context: TurnContext, { args }) => {
heroCard.content.title = 'This is a HeroCard with a really, really long title that is intended to test the richCardsWrapTitle style option.';
} else {
heroCard.content.text = '**Price: $XXX.XX USD**\r\n------\n Additional details\r\n1. List item 1 \n2. List item 2 \n3. List item 3';
heroCard.content.buttons = [
{
title: 'imBack Action',
type: 'imBack',
value: 'imBack Button'
},
{
title: 'postBack Action',
type: 'postBack',
value: 'postBack Button'
},
{
displayText: 'Send messageBack with display text',
title: 'messageBack Action with displayText',
type: 'messageBack',
value: 'messageBack Button'
},
{
title: 'messageBack Action with no display text',
type: 'messageBack',
value: 'messageBack Button'
},
];
}

await context.sendActivity({ attachments: [heroCard] });
Expand Down
3 changes: 2 additions & 1 deletion src/MockBot/commands/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const help = () => ({
});

const processor = async (context: TurnContext) => {
const { PUBLIC_URL } = process.env;

await context.sendActivity({
attachments: [{
contentType: 'image/jpeg',
contentUrl: `./assets/surface1.jpg`,
contentUrl: `${PUBLIC_URL}assets/surface1.jpg`,
name: 'Microsoft Surface'
}]
});
Expand Down
3 changes: 2 additions & 1 deletion src/MockBot/commands/ImageSVG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ const help = () => ({
});

async function processor(context: TurnContext) {
const { PUBLIC_URL } = process.env;

await context.sendActivity({
type: 'message',
attachments: [{
contentType: 'image/svg+xml',
contentUrl: `./assets/bf_square.svg`,
contentUrl: `${PUBLIC_URL}assets/bf_square.svg`,
name: 'Microsoft Bot Framework'
}]
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ async function processor(context: TurnContext, { args }: { args: string; }) {
export default {
help,
name: 'Input hint',
pattern: /^hint(\s+[\d\w]+)?(\s+[\d\w]+)?/i,
pattern: /^input[\-\s]hint(\s+[\d\w]+)?(\s+[\d\w]+)?|^hint(\s+[\d\w]+)?(\s+[\d\w]+)?/i,
processor
}
15 changes: 8 additions & 7 deletions src/MockBot/commands/Layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const help = () => ({
'layout': 'Show 4 attachments in stacked layout'
});

async function processor(context: TurnContext, { args }) {
async function processor(context: TurnContext, { args } = {}) {
const { PUBLIC_URL } = process.env;

switch (args) {
case 'single':
Expand All @@ -17,7 +18,7 @@ async function processor(context: TurnContext, { args }) {
text: 'This command show single attachment in **default (stacked)** layout',
attachments: [{
contentType: 'image/jpg',
contentUrl: `./assets/surface1.jpg`,
contentUrl: `${PUBLIC_URL}assets/surface1.jpg`,
name: 'Microsoft Surface'
}]
});
Expand All @@ -32,7 +33,7 @@ async function processor(context: TurnContext, { args }) {
attachmentLayout: 'carousel',
attachments: [{
contentType: 'image/jpg',
contentUrl: `./assets/surface1.jpg`,
contentUrl: `${PUBLIC_URL}assets/surface1.jpg`,
name: 'Microsoft Surface'
}]
});
Expand All @@ -46,11 +47,11 @@ async function processor(context: TurnContext, { args }) {
attachmentLayout: 'carousel',
attachments: [{
contentType: 'image/jpg',
contentUrl: `./assets/surface1.jpg`,
contentUrl: `${PUBLIC_URL}assets/surface1.jpg`,
name: 'Microsoft Surface'
}, {
contentType: 'image/jpg',
contentUrl: `./assets/surface2.jpg`,
contentUrl: `${PUBLIC_URL}assets/surface2.jpg`,
name: 'Microsoft Surface'
}]
});
Expand All @@ -64,7 +65,7 @@ async function processor(context: TurnContext, { args }) {
attachmentLayout: 'carousel',
attachments: [{
contentType: 'image/jpg',
contentUrl: `./assets/surface1.jpg`,
contentUrl: `${PUBLIC_URL}assets/surface1.jpg`,
name: 'Microsoft Surface'
}, {
contentType: 'text/plain',
Expand All @@ -86,7 +87,7 @@ async function processor(context: TurnContext, { args }) {
text: 'This command show 4 attachments in **default (stacked)** layout',
attachments: [{
contentType: 'image/jpg',
contentUrl: `./assets/surface1.jpg`,
contentUrl: `${PUBLIC_URL}assets/surface1.jpg`,
name: 'Microsoft Surface'
}, {
contentType: 'text/plain',
Expand Down
Loading

0 comments on commit 955ad6c

Please sign in to comment.