I'm not able deploy alexa skill using alexa-cli tool (https://www.npmjs.com/package/ask-cli) when I try to deploy my skill with a https server
As an error I get:
◞ Creating new skill...Call create-skill error.
Error code: 400
{
"message": "Skill manifest is not valid.",
"violations": [
{
"message": "No default regionalized endpoint is defined."
}
]
}
Im using an example skill.json from:
https://github.com/alexa/skill-sample-nodejs-hello-world/blob/master/skill.json
A problem is how to add custom uri endpoint. I dont want to host my skill in AWS lambda function.
I tried to follow documentation:
https://developer.amazon.com/de/docs/smapi/ask-cli-command-reference.html
but I dont know what Im doing wrong...
Could sombody please take a look at my json and alexa-cli documentation? Why Im getting a such weird message?
"No default regionalized endpoint is defined."
?
{
"manifest": {
"publishingInformation": {
"locales": {
"en-US": {
"summary": "Sample Short Description",
"examplePhrases": [
"Alexa open hello world",
"Alexa tell hello world my name is bill",
"Alexa tell hello world I want to play"
],
"name": "trivia",
"description": "Sample Full Description"
}
},
"isAvailableWorldwide": true,
"testingInstructions": "Sample Testing Instructions.",
"category": "KNOWLEDGE_AND_TRIVIA",
"distributionCountries": []
},
"apis": {
"custom": {
"endpoint": {
"sourceDir": "./lambda/custom",
"uri": "https://customapi.sampleskill.com",
" sslCertificateType": "Wildcard"
},
"regions": {
"EU": {
"endpoint": {
"uri": "https://customapi.sampleskill.com",
"sslCertificateType": "Trusted"
}
}
}
}
},
"manifestVersion": "1.0"
}
}
Ok for those who faced that problem in the future ;) Important is that in your skill root directory you have that file:
.ask/config
It should look like:
{
"deploy_settings": {
"default": {
"skill_id": "put here your skill id or leave it blank",
"was_cloned": false,
"merge": {
"manifest": {
"apis": {
"custom": {
"endpoint": {
"uri": "https://yourhttps.de",
"sslCertificateType": "Wildcard"
}
}
}
}
}
}
}
}
after that you can use ask-cli with the https server as an endpoint :)
Try this:
"apis": {
"custom": {
"endpoint": {
"uri": "https://customapi.sampleskill.com",
"sslCertificateType": "Wildcard"
},
"regions": {
"EU": {
"endpoint": {
"uri": "https://customapi.sampleskill.com",
"sslCertificateType": "Trusted"
}
}
}
}
}
In the default config you had set sourceDir which doesn't make much sense for endpoints outside AWS Lambda. Second your config contained whitespace around sslCertificateType, which also might cause the problem.
Related
I'm working on a TypeScript Azure Function that has an Azure Service bus topic as its output. I can send messages with it without any problem, but I cannot set any metadata as custom property on the message.
I've tried using an object with the same interface as the ServiceBusMessage from the Service Bus Javascript SDK, like this:
import { AzureFunction, Context, HttpRequest } from "#azure/functions";
const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest
): Promise<void> {
const message = {
body: "my message content",
applicationProperties: { key: "value" },
};
context.bindings.myTopic = message;
};
export default httpTrigger;
But the message is sent as-is, and the applicationProperties is not taken into account. I cannot see them on the Azure Portal in the Service Bus Explorer. The content of the message will be the JSON version of the message object.
I've tried with the extension bundles 3 and 4, without success.
I'm using this function.json file:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["get", "post"]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "myTopic",
"type": "serviceBus",
"queueName": "myTopic",
"connection": "SERVICE_BUS_CONNECTION_STRING",
"direction": "out"
}
],
"scriptFile": "../dist/servicebus-writer/index.js"
}
And this host.json file:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.3.0, 4.0.0)"
}
}
How can I set those custom properties?
As of today, there is no way to set metadata using bindings in non-C# languages. The workaround would be to use the Service Bus SDK directly to send out messages.
There is this feature request that you could up vote to gain more traction.
I'm following triggering guidelines in Unsplash documentation. So the endpoint is:
GET /photos/:id/download
This is the photo's example response:
{
"id": "LBI7cgq3pbM",
"width": 5245,
"height": 3497,
"color": "#60544D",
"urls": { ... },
"user": { ... },
"links": {
"self": "https://api.unsplash.com/photos/LBI7cgq3pbM",
"html": "https://unsplash.com/photos/LBI7cgq3pbM",
"download": "https://unsplash.com/photos/LBI7cgq3pbM/download", // don't use this property
"download_location": "https://api.unsplash.com/photos/LBI7cgq3pbM/download?ixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM" // use this one ;)
}
}
"Be sure to include any query parameters included in the URL (like the ixid)."
So my question is what is value od ixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM and how to get it?
Try the following
const ixid = new URLSearchParams(
new URL("https://api.unsplash.com/photos/LBI7cgq3pbM/download?ixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM").search
).get("ixid");
console.log(ixid);
When I try to parse this JSON (Discord webhook):
{
"content": "this `supports` __a__ **subset** *of* ~~markdown~~ 😃 ```js\nfunction foo(bar) {\n console.log(bar);\n}\n\nfoo(1);```",
"embed": {
"title": "title ~~(did you know you can have markdown here too?)~~",
"description": "this supports [named links](https://discordapp.com) on top of the previously shown subset of markdown. ```\nyes, even code blocks```",
"url": "https://discordapp.com",
"color": 16324973,
"timestamp": "2018-12-18T09:22:12.841Z",
"footer": {
"icon_url": "https://cdn.discordapp.com/embed/avatars/0.png",
"text": "footer text"
},
"thumbnail": {
"url": "https://cdn.discordapp.com/embed/avatars/0.png"
},
"image": {
"url": "https://cdn.discordapp.com/embed/avatars/0.png"
},
"author": {
"name": "author name",
"url": "https://discordapp.com",
"icon_url": "https://cdn.discordapp.com/embed/avatars/0.png"
},
"fields": [
{
"name": "🤔",
"value": "some of these properties have certain limits..."
},
{
"name": "😱",
"value": "try exceeding some of them!"
},
{
"name": "🙄",
"value": "an informative error should show up, and this view will remain as-is until all issues are fixed"
},
{
"name": "<:thonkang:219069250692841473>",
"value": "these last two",
"inline": true
},
{
"name": "<:thonkang:219069250692841473>",
"value": "are inline fields",
"inline": true
}
]
}
}
Using this code:
var parsed = JSON.parse(req.body)
I get this error:
SyntaxError: Unexpected token o in JSON at position 1
But if I use a website such as
https://jsonformatter.curiousconcept.com
To validate the JSON, it says the JSON is valid.
What is wrong here?
UPDATE
I'm using an express server to simulate discord server, so it sends web hooks to the express server instead, I get the JSON using req.body.
This happens because JSON is a global object (it's the same object where you read the method parse!), so when you invoke JSON.parse(JSON) javascript thinks you want to parse it.
The same thing doesn't happen when you pass the variable to the validator, because it will be assigned to a local variable:
let JSON = "{}";
validate(JSON);
function(x) {
JSON.parse(x); // here JSON is again your global object!
}
EDIT
According to your updated question, maybe it happens because you already use bodyParser.json() as middleware, and when you use it, req.body is already an object and you don't need to parse it again.
Trying to parsing an already parsed object will throw an error.
It would be something like without using JSONStream:
http.request(options, function(res) {
var buffers = []
res
.on('data', function(chunk) {
buffers.push(chunk)
})
.on('end', function() {
JSON.parse(Buffer.concat(buffers).toString())
})
})
For using it with JSONStream, it would be something like:
http.request(options, function(res) {
var stream = JSONStream.parse('*')
res.pipe(stream)
stream.on('data', console.log.bind(console, 'an item'))
})
(OR)
Here is the Some Steps for this issue..
You Can use lodash for resolving this.
import the lodash and call unescape().
const _ = require('lodash');
let htmlDecoder = function(encodedStr){
return _.unescape(encodedStr);
}
htmlDecoder(JSON);
I created a model named member inherited from the built in model User,
But how can I change the format of the login return. ie,
currently the invalid login is returning like
{
"error": {
"statusCode": 401,
"name": "Error",
"message": "login failed",
"code": "LOGIN_FAILED",
"stack": "Error: login failed\n ..."
}
}
I want to change like,
{
"code": 401,
"name": "Error",
"message": "login failed",
"code": "LOGIN_FAILED",
"stack": "Error: login failed\n ..."
}
Also, the success case as well,
ie current return is
{
"id": "P1jAavmCRbiYB1gYaE2snj3I6BayIYOCJ7HsTLeF1bezlEGVAUzjwdxKB5QFH9Vu",
"ttl": 1209600,
"created": "2017-02-02T13:19:05.709Z",
"userId": "5885b186db6df92d3ada7777"
}
I want to change like,
{
"code": 200,
"name": "Success",
"token": "P1jAavmCRbiYB1gYaE2snj3I6BayIYOCJ7HsTLeF1bezlEGVAUzjwdxKB5QFH9Vu",
"ttl": 1209600,
"created": "2017-02-02T13:19:05.709Z",
"userID": "5885b186db6df92d3ada7777"
}
Is it possible or not?
You need to remove strong-error-handler from middlewares and add your custom error handler like this
In config.json you need to do :
...
"remoting" {
...
"handleErrors": false
...
}
...
Also create config.local.js in root/sever folder and add below :
'use strict';
var errorConverter = require('./middlewares/error-converter');
module.exports = {
remoting: {
errorHandler: {
handler: errorConverter()
}
}
};
error-converter.js in middleare folder (or any other place) is the custom error hadnling middleare
I'm using node-log4js.
(it's log4JS, not log4J!)
I thought of the loggers 'categories' to be just like the Strings you put in Log4J into the constructor of a logger (normally you put your fqn class name there), so that log4j can put logged things to the right location.
I got the following config:
{
"appenders": [
{
"type": "console",
},
{
"type": "file",
"absolute": true,
"filename": "/tmp/app.log",
"maxLogSize": 20480,
"backups": 10
},
{
"type": "console",
"category": "app.access"
}
]
}
The desired behaviour would be that all "app.access" stuff only goes to the last appender (which is, at the moment, the console, too, but could change in future). At the moment, all loggings with the category 'app.access' will be logged twice to console and once to file.
Is there a way to give those other two appenders a "all but app.access"-category? How?
Thank you very much in advance
I had a similar requirement. I wanted to exclude a bunch of categories from the console logger.
I wrote something based on the logLevelFilter, which I called categoryFilter.
categoryFilter.js:
"use strict";
var log4js = require('log4js');
function categoryFilter (excludeCategories, appender) {
return function(logEvent) {
if (excludeCategories.every(function(x){return (x!=logEvent.category);})) {
appender(logEvent);
}
};
}
function configure(config) {
log4js.loadAppender(config.appender.type);
var appender = log4js.appenderMakers[config.appender.type](config.appender);
return categoryFilter(config.exclude, appender);
}
exports.appender = categoryFilter;
exports.configure = configure;
To use it, I have this snippet near the beginning of my app:
var log4js = require('log4js');
log4js.loadAppender('categoryFilter',require('./src/categoryFilter'));
log4js.configure('log4js-conf.js');
My configuration file has the following:
{
"appenders": [
{
"type": "file",
"filename": "logs/logfile.log",
"maxLogSize": 20480,
"backups": 3
},
{
"type": "categoryFilter",
"exclude":["results"],
"appender":{
"type": "console"
}
},
],
"replaceConsole":true
}
I'd be interested in your thoughts.
I faced a similar problem and here's how I resolved it - using the levels.
Used the following config file:
{
"appenders": [
{
"type": "logLevelFilter",
"level": "INFO",
"appender": {
"type": "console",
"layout": {
"type": "colored",
"pattern": "[%d] %-5p <%c> %m"
}
}
},
{
"type": "console",
"layout": {
"type": "messagePassThrough"
},
"category": "raw"
}
]
}
The use 2 different log4js instances as follows:
var path = require('path');
var log4js = require('log4js');
log4js.configure('log4js.json');
var log = log4js.getLogger(path.basename(__filename));
var raw = log4js.getLogger('raw');
In your code use log.info(), log.warn(), log.error() or log.fatal() to have standard logs such as:
[2015-01-12 19:37:19.931] [INFO] app.js - app started
[2015-01-12 19:38:52.484] [ERROR] other.js - Error. failed to open file
Same logs above would look like this using raw.trace():
app started
Error. failed to open file
I'm using it to highlight different situations in the console. It is important to me to have it look totally different so I will notice these events. But when it is logged to a file, I don't mind if it has the timestamp (since it actually helps when looking back in time). Therefore I also have the following appender in the log4js.json file:
{
"type": "file",
"filename": "app.log",
"maxLogSize": 1048576,
"backups": 10,
"layout": {
"type": "pattern",
"pattern": "[%d] %-5p <%c> %m"
}
}
Hope this help! :)
Just assign top two appenders to a different category than "app.access" and use that category in getLogger.