Skip to content

Commit

Permalink
Feature/ft define available languages (#2)
Browse files Browse the repository at this point in the history
* update createService method in convoworks-api.js to add new fields (default_locale and supported_locales)

* update language handling in convoworks-add-service.controller.js and convoworks-add-service.tmpl.html

* update language handling in config-service-meta-editor.directive.js and config-service-meta-editor.tmpl.html

* update externaltest.directive.js to generate the right test link for amazon based on default locale selection

* update uploadMedia in convoworks-api.js to rather hanlde map of kinds of files and files to populate the form data

* add new rule .panel-default > .panel-heading in config.scss to change color of the collapsable panels

* update onFileUpload by adding additional argument in config-amazon-editor.tmpl.html

* add new fields in config-amazon-editor.tmpl.html to edit Alexa Skill Store Preview and Privacy and Compliance

* add new fields in config-amazon-editor.directive.js to handle Alexa Skill Store Preview and Privacy and Compliance

* update image upload in config-dialogflow-editor.directive.js

* update CHANGELOG.md
  • Loading branch information
mmarcec007 authored Feb 4, 2021
1 parent 0639f82 commit 7bf487f
Show file tree
Hide file tree
Showing 11 changed files with 528 additions and 88 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* new preview rendering to accommodate overhauled process
* notifications have been redesigned
* add an indicator for ongoing propagation
* add the ability to edit the Skill Preview and Privacy Compliance of Alexa Skill Developer Console Distribution Tab

## [Releases]

Expand Down
13 changes: 7 additions & 6 deletions src/convoworks/common/convoworks-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ export default function ConvoworksApi( $log, $http, $q, CONVO_ADMIN_API_BASE_URL
});
}

function createService( serviceName, defaultLanguage, isPrivate, templateId)
function createService( serviceName, defaultLanguage, defaultLocale, supportedLocales, isPrivate, templateId)
{
return $http({
method: 'post',
url: CONVO_ADMIN_API_BASE_URL + '/services',
data: { 'service_name' : serviceName, 'default_language': defaultLanguage, 'is_private' : isPrivate, 'template_id' : templateId }
data: { 'service_name' : serviceName, 'default_language': defaultLanguage, 'default_locale': defaultLocale, 'supported_locales': supportedLocales, 'is_private' : isPrivate, 'template_id' : templateId }
}).then( function ( res) {
return res.data;
});
Expand Down Expand Up @@ -607,15 +607,16 @@ export default function ConvoworksApi( $log, $http, $q, CONVO_ADMIN_API_BASE_URL
}


function uploadMedia(serviceId, kind, file) {
function uploadMedia(serviceId, filesToUpload) {
if (!serviceId) {
throw new Error("Missing service ID");
}

$log.log('ConvoworksApi uploadMedia serviceId', serviceId, 'kind', kind, 'file', file);

var fd = new FormData();
fd.append(kind, file);
for (let [key, value] of filesToUpload) {
$log.log('ConvoworksApi uploadMedia serviceId', serviceId, 'kind', key, 'file', value);
fd.append(key, value);
}

return $http
.post(
Expand Down
169 changes: 137 additions & 32 deletions src/convoworks/editor/config/config-amazon-editor.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,8 @@ export default function configAmazonEditor($log, $q, $rootScope, $window, Convow
});

ConvoworksApi.getServiceMeta($scope.service.service_id).then( function (serviceMeta) {
serviceLanguage = serviceMeta['default_language'];
$scope.service_language = serviceLanguage;

if (serviceLanguage === 'en') {
serviceLanguage = "en_US"
} else if (serviceLanguage === 'de') {
serviceLanguage = "de_DE"
} else {
serviceLanguage = serviceLanguage.replace("-", "_")
}
const serviceLanguage = serviceMeta['default_locale'];
$scope.service_language = serviceLanguage.replace("-", "_");
});

$scope.config = {
Expand All @@ -39,14 +31,37 @@ export default function configAmazonEditor($log, $q, $rootScope, $window, Convow
interaction_model_sensitivity: 'LOW',
endpoint_ssl_certificate_type: 'Wildcard',
self_signed_certificate: null,
auto_display: false
auto_display: false,
skill_preview_in_store: {
public_name: _invocationToName($scope.service.name),
one_sentence_description: _invocationToName($scope.service.name),
detailed_description: _invocationToName($scope.service.name),
whats_new: '',
example_phrases: "Alexa, open " + $scope.service.name,
small_skill_icon: '',
large_skill_icon: '',
category: "ALARMS_AND_CLOCKS",
keywords: '',
privacy_policy_url: '',
terms_of_use_url: ''
},
privacy_and_compliance: {
allows_purchases: "false",
uses_personal_info: "false",
is_child_directed: "false",
contains_ads: "false",
is_export_compliant: true,
testing_instructions: "N/A",
}
};

var configBak = angular.copy( $scope.config);
var is_new = true;
var is_error = false;
var preparedUpload = null;
var previousMediaItemId = null;
var preparedUpload = new Map();
var previousMediaItemId = new Map();
var fileBytesSmallIcon = '';
var fileBytesLargeIcon = '';
var logline = '';

_load();
Expand All @@ -63,19 +78,64 @@ export default function configAmazonEditor($log, $q, $rootScope, $window, Convow
return is_new;
}

$scope.onFileUpload = function (file) {
$scope.onFileUpload = function (file, type) {
$log.log('ConfigurationsEditor onFileUpload file', file);
previousMediaItemId.set('certificate', $scope.config.self_signed_certificate);
previousMediaItemId.set('small_skill_icon', $scope.config.skill_preview_in_store.small_skill_icon);
previousMediaItemId.set('large_skill_icon', $scope.config.skill_preview_in_store.large_skill_icon);

if (file) {
preparedUpload = {
file: file
};
if (!file.name.includes('.pem')) {
throw new Error(`Invalid file extension in ${file.name}.`)
var image = new Image();
if (type === 'certificate') {
if (!file.name.includes('.pem')) {
AlertService.addDanger(`Invalid file extension in ${file.name}. It must be .pem!`);
}
preparedUpload.set('amazon.self_signed_certificate', file);
$scope.config.self_signed_certificate = 'tmp_certificate_upload_ready';
} else if (type === 'small_skill_icon') {
if (!file.name.includes('.png')) {
AlertService.addDanger(`Invalid file extension in ${file.name}. It must be .png!`);
}
preparedUpload.set('amazon.small_skill_icon', file);
$scope.config.skill_preview_in_store.small_skill_icon = 'tmp_small_skill_icon_upload_ready';

fileBytesSmallIcon = URL.createObjectURL(file);
image.src = fileBytesSmallIcon;
} else if (type === 'large_skill_icon') {
if (!file.name.includes('.png')) {
AlertService.addDanger(`Invalid file extension in ${file.name}. It must be .png!`);
}
preparedUpload.set('amazon.large_skill_icon', file);
$scope.config.skill_preview_in_store.large_skill_icon = 'tmp_large_skill_icon_upload_ready';

fileBytesLargeIcon = URL.createObjectURL(file);
image.src = fileBytesLargeIcon;
}

previousMediaItemId = $scope.config.self_signed_certificate;
$scope.config.self_signed_certificate = 'tmp_upload_ready';
if (image.src !== '') {
image.onload = () => {
let errorReport = "";
if (type === 'small_skill_icon') {
if (image.height !== 108 && image.width !== 108) {
preparedUpload.delete('amazon.small_skill_icon');
errorReport = `Invalid image size of ${file.name}. Actual image size is ${image.width} X ${image.width}. It should be 108 X 108.`;
$scope.config.skill_preview_in_store.small_skill_icon = '';
$scope.$apply();
}
} else if (type === 'large_skill_icon') {
if (image.height !== 512 && image.width !== 512) {
preparedUpload.delete('amazon.large_skill_icon');
errorReport = `Invalid image size of ${file.name}. Actual image size is ${image.width} X ${image.width}. It should be 512 X 512.`;
$scope.config.skill_preview_in_store.large_skill_icon = '';
$scope.$apply();
}
}
if (errorReport !== '') {
AlertService.addDanger(`Invalid image size of ${file.name}. Actual image size is ${image.width} X ${image.width}. It should be 512 X 512.`);
}
URL.revokeObjectURL(file);
}
}
}
}

Expand All @@ -87,38 +147,73 @@ export default function configAmazonEditor($log, $q, $rootScope, $window, Convow
}

if (mediaItemId === 'tmp_upload_ready') {
mediaItemId = previousMediaItemId;
mediaItemId = previousMediaItemId.get("certificate");
}

// $log.log('ConfigurationsEditor getMedia(', type, ') mediaItemId', mediaItemId);

return mediaItemId;
}

$scope.getSkillIcon = function(type) {
var mediaItemId = $scope.config.skill_preview_in_store[type];


if (!mediaItemId) {
return '';
}

if (mediaItemId === previousMediaItemId.get('small_skill_icon') && type === 'small_skill_icon') {
mediaItemId = previousMediaItemId.get('small_skill_icon');
} else if (mediaItemId === previousMediaItemId.get('large_skill_icon') && type === 'large_skill_icon') {
mediaItemId = previousMediaItemId.get('large_skill_icon');
}

if (mediaItemId === 'tmp_small_skill_icon_upload_ready' && type === 'small_skill_icon') {
return fileBytesSmallIcon;
} else if (mediaItemId === 'tmp_large_skill_icon_upload_ready' && type === 'large_skill_icon') {
return fileBytesLargeIcon;
} else {
return ConvoworksApi.downloadMedia($scope.service.service_id, mediaItemId);
}
}

$scope.updateConfig = function (isValid) {
if (!isValid) {
throw new Error(`Invalid form data.`)
}
$log.debug('configAmazonEditor update() $scope.config', $scope.config);
_updateSelectedInterfaces();

var maybeUpload = preparedUpload ?
var maybeUpload = preparedUpload.size > 0 ?
ConvoworksApi.uploadMedia(
$scope.service.service_id,
'dialogflow.self_signed_certificate',
preparedUpload.file) :
preparedUpload.entries()) :
null;

$q.when(maybeUpload).then(function (res) {
if (res && res.mediaItemId) {
$scope.config.self_signed_certificate = res.mediaItemId;
preparedUpload = null;
if (res && res.length > 0) {

for(var i = 0; i < res.length; i++) {
const width = res[i].imageWidth;
const height = res[i].imageHeight;

if (width === 108 && height === 108) {
$scope.config.skill_preview_in_store.small_skill_icon = res[i].mediaItemId;
} else if (width === 512 && height === 512) {
$scope.config.skill_preview_in_store.large_skill_icon = res[i].mediaItemId;
} else if (width === null && height === null ) {
$scope.config.self_signed_certificate = res[i].mediaItemId;
}
}

preparedUpload.clear();
}

if ( is_new) {
ConvoworksApi.createServicePlatformConfig( $scope.service.service_id, 'amazon', $scope.config).then(function (data) {
return ConvoworksApi.createServicePlatformConfig( $scope.service.service_id, 'amazon', $scope.config).then(function (data) {
configBak = angular.copy( $scope.config);
is_new = false;
is_error = false;
$scope.config.app_id = data.app_id;
AlertService.addSucess(`Service ${$scope.service.service_id} was linked successfully with Alexa.`);
$rootScope.$broadcast('ServiceConfigUpdated', $scope.config);
}, function ( response) {
Expand All @@ -127,7 +222,7 @@ export default function configAmazonEditor($log, $q, $rootScope, $window, Convow
throw new Error("Can't create config for Amazon. " + response.data.message)
});
} else {
ConvoworksApi.updateServicePlatformConfig( $scope.service.service_id, 'amazon', $scope.config).then(function (data) {
return ConvoworksApi.updateServicePlatformConfig( $scope.service.service_id, 'amazon', $scope.config).then(function (data) {
configBak = angular.copy( $scope.config);
is_error = false;
$rootScope.$broadcast('ServiceConfigUpdated', $scope.config);
Expand All @@ -150,6 +245,9 @@ export default function configAmazonEditor($log, $q, $rootScope, $window, Convow

$scope.revertConfig = function () {
$scope.config = angular.copy(configBak);
if (preparedUpload.size > 0) {
preparedUpload.clear();
}
}


Expand Down Expand Up @@ -216,6 +314,7 @@ export default function configAmazonEditor($log, $q, $rootScope, $window, Convow
$scope.languages = config_options['CONVO_AMAZON_LANGUAGES'];
$scope.sensitivities = config_options['CONVO_AMAZON_INTERACTION_MODEL_SENSITIVITIES'];
$scope.endpointCertificateTypes = config_options['CONVO_AMAZON_SKILL_ENDPOINT_SSL_CERTIFICATE'];
$scope.categories = config_options['CONVO_AMAZON_SKILL_CATEGORIES'];
$scope.interfaces = config_options['CONVO_ALEXA_INTERFACES'];

$scope.$watch('config.auto_display', function(newVal) {
Expand All @@ -226,6 +325,7 @@ export default function configAmazonEditor($log, $q, $rootScope, $window, Convow
}
});


$scope.$watch('config.interaction_model_sensitivity', function(newInteractionModelSensitivity) {
if (newInteractionModelSensitivity !== undefined) {
$scope.config.interaction_model_sensitivity = newInteractionModelSensitivity;
Expand Down Expand Up @@ -256,6 +356,11 @@ export default function configAmazonEditor($log, $q, $rootScope, $window, Convow
})
}

function _invocationToName(str) {
return (str + '').replace(/^(.)|\s+(.)/g, function ($1) {
return $1.toUpperCase()
})
}

}
}
Expand Down
Loading

0 comments on commit 7bf487f

Please sign in to comment.