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

Commit

Permalink
Added functionality to create and download pregenerated zip file of m…
Browse files Browse the repository at this point in the history
…anifest
  • Loading branch information
jotrick committed Sep 20, 2017
1 parent 2d6e3cf commit 871df9e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 14 deletions.
Binary file added manifest/createdManifest/bot_blue.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions manifest/manifest.json
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://statics.teams.microsoft.com/sdk/v1.0/manifest/MicrosoftTeams.schema.json",
"manifestVersion": "1.0",
"version": "1.0",
"id": "REGISTERED_BOT_ID",
"id": "<<REGISTERED_BOT_ID>>",
"packageName": "com.Template.microsoftteams",
"developer": {
"name": "Bot Template",
Expand All @@ -25,7 +25,7 @@
"accentColor": "#0079bf",
"configurableTabs": [
{
"configurationUrl": "BASE_URI/tab/tabConfig/index.html",
"configurationUrl": "<<BASE_URI>>/tab/tabConfig/index.html",
"canUpdateConfiguration": false,
"scopes": [
"team"
Expand All @@ -34,7 +34,7 @@
],
"staticTabs": [
{
"contentUrl": "BASE_URI/loading",
"contentUrl": "<<BASE_URI>>/loading",
"entityId": "1on1test123",
"name": "Bot Info",
"scopes": [
Expand All @@ -43,15 +43,15 @@
]
},
{
"contentUrl": "BASE_URI/tab-auth/simple",
"contentUrl": "<<BASE_URI>>/tab-auth/simple",
"entityId": "simpleAuth",
"name": "Simple Auth",
"scopes": [
"personal"
]
},
{
"contentUrl": "BASE_URI/tab-auth/silent",
"contentUrl": "<<BASE_URI>>/tab-auth/silent",
"entityId": "silentAuth",
"name": "Silent Auth",
"scopes": [
Expand All @@ -61,7 +61,7 @@
],
"bots": [
{
"botId": "REGISTERED_BOT_ID",
"botId": "<<REGISTERED_BOT_ID>>",
"scopes": [
"team",
"personal"
Expand Down Expand Up @@ -158,7 +158,7 @@
],
"composeExtensions": [
{
"botId": "REGISTERED_BOT_ID",
"botId": "<<REGISTERED_BOT_ID>>",
"scopes": [
"personal",
"team"
Expand Down Expand Up @@ -186,6 +186,6 @@
"messageTeamMembers"
],
"validDomains": [
"BASE_URI_EXCLUDING_HTTPS://"
"<<BASE_URI_DOMAIN>>"
]
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
"lodash": "^4.17.4",
"moment": "^2.17.1",
"mongodb": "^2.2.24",
"node-zip": "^1.1.1",
"oauth": "^0.9.15",
"q": "^1.4.1",
"random-number-csprng": "^1.0.2",
Expand Down
2 changes: 2 additions & 0 deletions src/app.ts
Expand Up @@ -20,6 +20,7 @@ import { MongoDbBotChannelStorage } from "./storage/MongoDbBotChannelStorage";
import { AADUserValidation } from "./apis/AADUserValidation";
import { ValidateAADToken } from "./apis/ValidateAADToken";
import { ManifestCreatorStart } from "./pages/ManifestCreatorStart";
import { ManifestCreatorEnd } from "./pages/ManifestCreatorEnd";

// Configure instrumentation - tooling with Azure
// let appInsights = require("applicationinsights");
Expand Down Expand Up @@ -62,6 +63,7 @@ app.get("/tab-auth/silent-start", (req, res) => { res.render("tab-auth/silent-st
app.get("/tab-auth/silent-end", (req, res) => { res.render("tab-auth/silent-end"); });

app.get("/", ManifestCreatorStart.getRequestHandler());
app.get("/createManifest", ManifestCreatorEnd.getRequestHandler());

// Create Teams connector for the bot
let connector = new teams.TeamsChatConnector({
Expand Down
56 changes: 56 additions & 0 deletions src/pages/ManifestCreatorEnd.ts
@@ -0,0 +1,56 @@
import * as express from "express";
import * as config from "config";
import * as fs from "fs";
import * as Zip from "node-zip";

export class ManifestCreatorEnd {

public static getRequestHandler(): express.RequestHandler {
return async function (req: any, res: any, next: any): Promise<void> {
let baseUri = config.get("app.baseUri");
let appId = config.get("bot.botId");
let baseUriDomain = baseUri.replace(/^https:\/\/|^http:\/\//, "");

fs.readFile("../../manifest/manifest.json", "utf8", (err, data) => {
if (!err) {
fs.mkdir("../../manifest/createdManifest", (err2) => {
if (!err2 || (err2.code && err2.code === "EEXIST")) {
data = data.replace(/<<BASE_URI>>/g, baseUri);
data = data.replace(/<<REGISTERED_BOT_ID>>/g, appId);
data = data.replace(/<<BASE_URI_DOMAIN>>/g, baseUriDomain);
fs.writeFile("../../manifest/createdManifest/manifest.json", data, (err3) => {
if (!err3) {
fs.readFile("../../manifest/createdManifest/bot_blue.png", (err4, data2) => {
if (!err4) {
let zip = new Zip;
zip.file("manifest.json", data);
zip.file("bot_blue.png", data2);
let options = {base64: false, compression: "DEFLATE"};
let zippedData = zip.generate(options);
fs.writeFile("../../manifest/createdManifest/createdManifest.zip", zippedData, "binary", (err5) => {
if (!err5) {
res.set("Content-Type", "application/zip");
res.end(zippedData, "binary");
} else {
console.log(err5);
}
});
} else {
console.log(err4);
}
});
} else {
console.log(err3);
}
});
} else {
console.log(err2);
}
});
} else {
console.log(err);
}
});
};
}
}
4 changes: 1 addition & 3 deletions src/pages/ManifestCreatorStart.ts
Expand Up @@ -8,9 +8,7 @@ export class ManifestCreatorStart {
let baseUri = config.get("app.baseUri");
let appId = config.get("bot.botId");

// let domain = baseUri.replace(/^https:\/\/|^http:\/\//, "");

res.render("manifestCreatorStart", {
res.render("manifest-creator/manifestCreatorStart", {
baseUri: baseUri,
appId: appId,
buttonEnabled: baseUri && appId,
Expand Down
Expand Up @@ -50,16 +50,16 @@
<br>

{{#if buttonEnabled}}
<button type="button" onclick="createManifest()">Create Manifest</button>
<button type="button" onclick="createManifest()">Download Manifest</button>
{{else}}
<button type="button" disabled>Create Manifest</button>
<button type="button" disabled>Download Manifest</button>
<br>
<p>Note: In order to create a manifest, all requirements above must be met with environment variables.</p>
{{/if}}

<script type="text/javascript">
function createManifest() {
alert("This is when you would create the manifest");
window.location = window.location.protocol + '//' + window.location.host + '/createManifest'
}
</script>
</body>
Expand Down

0 comments on commit 871df9e

Please sign in to comment.