Upload Alexa Slot Types via API - alexa

Is there anyway of uploading Custom Slot Types values via an API, so that you do not need to type them in manually using the new Alexa Skill Builder interface (if you have many of them):
I haven't found anything.

My recommendation is to get the model via SMAPI first, edit the json file with your new values and update it via SMAPI again.
ask api get-model -s "enter your skill id here" --stage development -l en-US > model.json
in the model.json file you can see the slots definition. Change it (with a script or manually) and update the model again
Reference to both commands:
https://developer.amazon.com/docs/smapi/ask-cli-command-reference.html#update-model-subcommand
https://developer.amazon.com/docs/smapi/ask-cli-command-reference.html#update-model-subcommand

It seems not (after searching). There is a feature request logged here with Amazon:
https://forums.developer.amazon.com/questions/9640/api-to-upload-intent-schema-and-sample-utterances.html#answer-77902

Yes you can do this via the SMAPI API/CLI. Take a look at https://developer.amazon.com/docs/smapi/ask-cli-intro.html for a full detail - it allows for full model editing via JSON.

In the left bar bellow the "Intents" and "Slot" is the option "JSON Editor". There you can write a JSON for the new intents you want to add.
Example without slot type
{
"name":"YesIntent",
"samples":[
"Yes",
"Yeah",
"I do",
"I am"
]
}
Example with slot type
{
"name":"NumberIntent",
"slots":[
{
"name":"number",
"type":"AMAZON.NUMBER"
}
],
"samples":[
"{number} is my number",
"{number}",
"my number is {number}"
]
}

As other answers suggest, you can use the SMAPI.
Alternatively, you can select the "code editor" tab on the left and drag/drop or copy/paste your schema json code.

https://github.com/williamwdu/Alexa-Custom-Slot-Generator
I wrote this to convert csv/excel to JSON format so you can paste it into code editor.
Let me know if you have any question.
There is no README for the code coz I have no time these days

Related

Want to pass in a string array into a WS.sendRequest using groovy

I am new to API testing and am using Katalon to develop the tests. I've Googled any question I could think of and couldn't find anything to answer my question.
We have an API with the following Body
[
"${idValue1}",
"${idValue2}",
"${idValue3}",
"${idValue4}",
"${idValue5}",
]
I believe the purpose of this one is to delete multiple records at once by id. The script that we have in the step definition is
response = WS.sendRequest(findTestObject('EquipmentAPI/data-objects/DELETE Equipment By Ids', [('host') : GlobalVariable.host, ('idValues') : GlobalVariable.equipId]))
GlobalVariable.equipId = WS.getElementPropertyValue(response, 'data[0].id')
There are other step definitions that run before this one to set the Global Variables for use. I was able to generate the string array without issue.
Is this something that's possible? Please help!
Please let me know if further information is needed. Thanks.

how to specify a variable/parameter in my logic app's arm template?

I am creating an Arm template for a logic app. This logic app needs to delete some old entries in azure table (say 10 or 20 days old).
In my arm template, if I do this, it works.
"queries": {
"$filter": "Timestamp le datetime'#{addDays(utcNow(),-31)}'"
}
But ideally I want to do this:
"queries": {
"$filter": "Timestamp le datetime'#{addDays(utcNow(),parameters('RetainDay'))}'"
}
Basically use a parameter to control the amount of days to check. I define this parameter as:
"parameters": {
"RetainDay": {
"type": "int"
}
}
When I deploy this, the parameters('RetainDay') isn't replaced to the parameter value. Instead it just stays same as:
Timestamp le datetime'#{addDays(utcNow(),parameters('RetainDay')
So I must be using the wrong syntax.
Can someone point it out?
You need to connect the 'Logic Apps template parameter' together with the 'ARM deployment template parameter', as much as it looks like the one and same variable, it is two parameters that work together. In my solution, I have a parameter called 'CustomVariableName'
Passing the parameter
Declaring the CustomVariableName in the "logic app code" and in the ARM template
Value in parameters file
Deployed Logic App in Azure
Postman POST response from hitting the HTTP trigger(instead of value: 'DefaultValue')
You need to use a concat() function to achieve string concatenation and variable expansion:
"$filter": "[concat('Timestamp le datetime\'#{addDays(utcNow(),', parameters('RetainDay'), ')}\'')]"
i think you can escape ' with \, if not, you can create a variable with the value ' and use that instead.
I see your template only set the parameter retionday type, you don't set the value. So go to parameter set the defaultValue like the below picture.
And I just use the this Filter Query Timestamp le datetime'#{addDays(utcNow(),parameters('retionday'))}', it will replace the time.
So please have a try, hope this could help you.

Sumologic - split JSON array into multiple records

I am passing a JSON array object in the HTTP POST as
[{"level":"INFO","data": "Test 1"},{"level":"INFO","data": "Test 2"}]
This message is seen as 1 object/log message in SumoLogic. How can I tell SumoLogic to consider each JSON object as an independent object and show 2 log messages instead of one?
I believe this can't be done with the json operator. But, have a look at the docs for the "parse regex" operator. There's an option called "multi" which creates a new message for each match of the regex. In your case, something like this might do the trick:
parse regex "\{?<fieldname>.*?\}" multi
I didn't try this in the product itself, but here is Regex101 link to play with the regex.
I believe the actual answer to this is to not send your logs as an array. Instead include each json object in your body with a '\n' at the end for Sumo to consider these as individual log messages.
{"level":"INFO","data": "Test 1"}\n
{"level":"INFO","data": "Test 2"}\n

How to export some selected records from SQLFORM.grid as doc or pdf format in web2py

When I click the checkbox before every row, export the selected records as doc or pdf format. How to realize this?
def test():
form=SQLFORM.grid(db.problem,selectable = lambda ids:download(ids)
return dict(form=form)
def export(ids):
if I set csv=True in SQLFORM.grid there are some format while no doc and pdf!
Thanks!
Jian,
Unfortunately, working with .doc, .docx (Microsoft Word) and .pdf isn't as simple as you might think it is.
For Word, you'll need python-docx that can be installed with $ pip install python-docx and you can find the documentation an sample code here.
To create a PDF document, you'll only need to import pyfpdf using from gluon.contrib.fpdf import FPDF, since web2py already comes with it. But, the same case applies here: You'll need to read some documentation and write some code.

How to export Rich Text fields as HTML from Notes with LotusScript?

I'm working on a data migration task, where I have to export a somewhat large Lotus Notes application into a blogging platform. My first task was to export the articles from Lotus Notes into CSV files.
I created a Agent in LotusScript to export the data into CSV files. I use a modified version of this IBM DeveloperWorks forum post. And it basically does the job. But the contents of the Rich Text field is stripped of any formatting. And this is not what I want, I want the Rich Text field rendered as HTML.
The documentation for the GetItemValue method explicitly states that the text is rendered into plain text. So I began to research for something that would retrieve the HTML. I found the NotesMIMEEntity class and some sample code in the IBM article How To Access HTML in a Rich Text Field Using LotusScript.
But for the technique described in the above article to work, the Rich Text field need to have the property "Store Contents as HTML and MIME". And this is not the case with my Lotus Notes database. I tried to set the property on the fields in question, but it didn't do the trick.
Is it possible to use the NotesMIMEEntity and set the "Store Contents as HTML and MIME" property after the content has been added, to export the field rendered as HTML?
Or what are my options for exporting the Notes database Rich Text fields as HTML?
Bonus information: I'm using IBM Lotus Domino Designer version 8.5
There is this fairly unknown command that does exactly what you want: retrieve the URL using the command OpenField.
Example that converts only the Body-field:
http://SERVER/your%5Fdatabase%5Fpath.nsf/NEW%5FVIEW/docid/Body?OpenField
Here is how I did it, using the OpenField command, see D.Bugger's post above
Function GetHtmlFromField(doc As NotesDocument, fieldname As String) As String
Dim obj
Set obj = CreateObject("Microsoft.XMLHTTP")
obj.open "GET", "http://www.mydomain.dk/database.nsf/0/" + doc.Universalid + "/" + fieldname + "?openfield&charset=utf-8", False, "", ""
obj.send("")
Dim html As String
html = Trim$(obj.responseText)
GetHtmlFromField = html
End Function
I'd suggest looking at Midas' Rich Text LSX (http://www.geniisoft.com/showcase.nsf/MidasLSX)
I haven't used the personally, but I remember them from years ago being the best option for working with Rich Text. I'd bet it saves you a lot of headaches.
As for the NotesMIMEEntity class, I don't believe there is a way to convert RichText to MIME, only MIME to RichText (or retain the MIME within the document for emailing purposes).
If you upgrade to Notes Domino 8.5.1 then you can use the new ConvertToMIME method of the NotesDocument class. See the docs. This should do what you want.
Alternativly the easiest way to get the Domino server to render the RichText will be to actually retrieve it via a url call. Set up a simple form that just has the RichText field and then use your favourite HTTP api to pull in the page. It should then be pretty straight forward to pull out the body.
Keep it simple.
Change the BODY field to Store contents as HTML and MIME
Open the doc in editmode.
Save.
Close.
You can now use the NotesMIMEEntity to get what you need from script.
You can use the NotesDXLExporter class to export the Rich Text and use an XSLT to transform the output to what you need.
I know you mentioned using LotusScript, but if you don't mind writing a small Java agent (in the Notes client), this can be done fairly easily - and there is no need to modify the existing form design.
The basic idea is to have your Java code open a particular document through a localhost http request (which is simple in Java) and to have your code capture that html output and save it back to that document. You basically allow the Domino rendering engine to do the heavy lifting.
You would want do this:
Create a form which contains only the rich-text field you want to convert, and with Content Type of HTML
Create a view with a selection formula for all of the documents you want to convert, and with a form formula which computes to the new form
Create the Java agent which just walks your view, and for each document gets its docid, opens a URL in the form http://SERVER/your_database_path.nsf/NEW_VIEW/docid?openDocument, grabs the http response and saves it.
I put up some sample code in a similar SO post here:
How to convert text and rich text fields in a document to html using lotusscript?
Works in Domino 10 (have not tested with 9)
HTMLStrings$ = NotesRichTextItem .Converttohtml([options] ) As String
See documentation :
https://help.hcltechsw.com/dom_designer/10.0.1/basic/H_CONVERTOHTML_METHOD_NOTESRICHTEXTITEM.html
UPDATE (2022)
HCL no longer support this method since version 11. The documentation does not include any info about the method.
I have made some tests and it still works in v12 but HCL recommended to not use it.
Casper's recommendation above works well, but make sure the ACL is such to allow Anonymous Access otherwise your HTML will be the HTML from your login form
If you do not need to get the Richtext from the items specifically, you can use ?OpenDocument, which is documented (at least) here: https://www.ibm.com/developerworks/lotus/library/ls-Domino_URL_cheat_sheet/
https://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/com.ibm.designer.domino.main.doc/H_ABOUT_URL_COMMANDS_FOR_OPENING_DOCUMENTS_BY_KEY.html
OpenDocument also allows you to expand sections (I am unsure if OpenField does)
Syntax is:
http://Host/Database/View/DocumentUniversalID?OpenDocument
But be sure to include the charset parameter as well - Japanese documents were unreadable without specifying utf-8 as the charset.
Here is the method I use that takes a NotesDocument and returns the HTML for the doc as a string.
private string ConvertDocumentToHml(Domino.NotesDocument doc, string sectionList = null)
{
var server = doc.ParentDatabase.Server.Split('/')[0];
var dbPath = doc.ParentDatabase.FilePath;
string viewName = "0";
string documentId = doc.UniversalID.ToUpper();
var ub = new UriBuilder();
ub.Host = server;
ub.Path = dbPath.Replace("\\", "/") + "/" + viewName + "/" + documentId;
if (string.IsNullOrEmpty(sectionList))
{
ub.Query = "OpenDocument&charset=utf-8";
}
else
{
ub.Query = "OpenDocument&charset=utf-8&ExpandSection=" + sectionList;
}
var url = ub.ToString();
var req = HttpWebRequest.CreateHttp(url);
try
{
var resp = req.GetResponse();
string respText = null;
using (var sr = new StreamReader(resp.GetResponseStream()))
{
respText = sr.ReadToEnd();
}
return respText;
}
catch (WebException ex)
{
return "";
}
}

Resources