in lib.php [201:349]
function local_o365_create_manifest_file() {
global $CFG;
require_once($CFG->libdir . '/filestorage/zip_archive.php');
$error = '';
$zipfilename = '';
// Task 1: check if bot settings are consistent.
$botappid = get_config('local_o365', 'bot_app_id');
$botfeatureenabled = get_config('local_o365', 'bot_feature_enabled');
if ($botfeatureenabled) {
if (!$botappid || $botappid == '00000000-0000-0000-0000-000000000000') {
// Bot id not configured, cannot create manifest file.
$error = get_string('error_missing_app_id', 'local_o365');
return [$error, $zipfilename];
}
$botapppassword = get_config('local_o365', 'bot_app_password');
$botwebhookendpoint = get_config('local_o365', 'bot_webhook_endpoint');
if (!$botapppassword || !$botwebhookendpoint) {
$error = get_string('error_missing_bot_settings', 'local_o365');
return [$error, $zipfilename];
}
}
// Task 2: prepare manifest folder.
$pathtomanifestfolder = $CFG->dataroot . '/temp/ms_teams_manifest';
if (file_exists($pathtomanifestfolder)) {
local_o365_rmdir($pathtomanifestfolder);
}
mkdir($pathtomanifestfolder, 0777, true);
// Task 2.1: prepare manifest params.
$teamsmoodleappexternalid = get_config('local_o365', 'teams_moodle_app_external_id');
if (!$teamsmoodleappexternalid) {
$teamsmoodleappexternalid = TEAMS_MOODLE_APP_EXTERNAL_ID;
}
$teamsmoodleappnameshortname = get_config('local_o365', 'teams_moodle_app_short_name');
if (!$teamsmoodleappnameshortname) {
$teamsmoodleappnameshortname = 'Moodle';
}
// Task 3: prepare manifest file.
$manifest = array(
'$schema' => 'https://developer.microsoft.com/en-us/json-schemas/teams/v1.7/MicrosoftTeams.schema.json',
'manifestVersion' => '1.7',
'version' => '1.3',
'id' => $teamsmoodleappexternalid,
'packageName' => 'ie.enovation.microsoft.o365',
'developer' => array(
'name' => 'Enovation Solutions',
'websiteUrl' => 'https://enovation.ie',
'privacyUrl' => 'https://enovation.ie/moodleteamsapp-privacy',
'termsOfUseUrl' => 'https://enovation.ie/moodleteamsapp-termsofuse',
'mpnId' => '1718735',
),
'icons' => array(
'color' => 'color.png',
'outline' => 'outline.png',
),
'name' => array(
'short' => $teamsmoodleappnameshortname,
'full' => 'Moodle integration with Microsoft Teams for ' . $CFG->wwwroot,
),
'description' => array(
'short' => 'Access your Moodle courses and ask questions to your Moodle Assistant in Teams.',
'full' => 'The Moodle app for Microsoft Teams allows you to easily access and collaborate around your Moodle ' .
'courses from within your teams through tabs. You can also get regular notifications from Moodle and ask ' .
'questions about your courses, assignments, grades and students using the Moodle Assistant bot.',
),
'accentColor' => '#FF7A00',
'configurableTabs' => array(
array(
'configurationUrl' => $CFG->wwwroot . '/local/o365/teams_tab_configuration.php',
'canUpdateConfiguration' => false,
'scopes' => array(
'team',
),
),
),
'permissions' => array(
'identity',
'messageTeamMembers',
),
'validDomains' => array(
parse_url($CFG->wwwroot, PHP_URL_HOST),
'token.botframework.com',
),
'webApplicationInfo' => array(
'id' => get_config('auth_oidc', 'clientid'),
'resource' => 'api://' . preg_replace("(^https?://)", "", $CFG->wwwroot) . '/' . get_config('auth_oidc', 'clientid'),
)
);
// Task 4: add bot part to manifest if enabled.
if ($botfeatureenabled) {
$manifest['bots'] = array(
array(
'botId' => $botappid,
'needsChannelSelector' => false,
'isNotificationOnly' => false,
'scopes' => array(
'team',
'personal',
),
'commandLists' => array(
array(
'scopes' => array(
'team',
'personal',
),
'commands' => array(
array(
'title' => 'Help',
'description' => 'Displays help dialog'
),
array(
'title' => 'Feedback',
'description' => 'Displays feedback dialog'
),
),
),
),
),
);
}
$file = $pathtomanifestfolder . '/manifest.json';
file_put_contents($file, json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
// Task 5: prepare icons.
copy($CFG->dirroot . '/local/o365/pix/color.png', $pathtomanifestfolder . '/color.png');
copy($CFG->dirroot . '/local/o365/pix/outline.png', $pathtomanifestfolder . '/outline.png');
// Task 6: compress the folder.
$ziparchive = new zip_archive();
$zipfilename = $pathtomanifestfolder . '/manifest.zip';
$ziparchive->open($zipfilename);
$filenames = array('manifest.json', 'color.png', 'outline.png');
foreach ($filenames as $filename) {
$ziparchive->add_file_from_pathname($filename, $pathtomanifestfolder . '/' . $filename);
}
$ziparchive->close();
return [$error, $zipfilename];
}