QnA maker, Is it possible that stores JSON content as an answer - qnamaker

I'm trying to save the JSON content in the answer.
For example, the QnA pair is like
Question: where is the repair center.
Answer: { "text" : "the repair center locates ...", "next": "would
you like to know the phone number of the repair center" }
My chatbot will do some particular things when receiving this kind of answer from QnA service.
dynamic answser = JObject.parse(qnaResponse.answer);
if (answer.next == string.Empty){
//End conversation
}else{
await context.PostAsync(answer.next);
}
But I always got the gibberish string in response answer that I can't parse to JSON object and do rest of conversations.
{ "text":" the repair center locates ... " ,"next": "would you like to know the phone number of the repair center" }
Is it possible that stores JSON content as an answer? Or did I miss something?

Related

Shopware 6 Store-API set newsletter recipient tags

I'm trying to add a newsletter recipient through store-api, which works. But when I try to add a tag inside the request, it fails. The documentation states that it is possible to add a tag as a string to the request, see here
My request looks like the following:
POST /store-api/newsletter/subscribe
{"option":"subscribe","email":"email#email.com","storefrontUrl":"http://myhost.test","tags":"men"}
I also tried to make the tags value an array, but this doesn't work either...
So my question is: how do I add a tag to the newsletter recipient through the store api?
As of Version 6.4.3.0 this seems not possible.
I tried the same request as you, as well as
"tags":["men"]
and
"tags":["uuidOfExistingTagGoesHere"]
all does not work.
Also the doc block for tags is wrong (it says "zip code" instead of a useful description).
In addition I tried to assign existing tags - this is what works via the admin API:
"tags": [
{
"id": "80df380188364f3c9bbaaa4d6b993dbd"
},
{
"id": "108428f0a37c4d11a66976adc5337c23"
}
]
Which still returns
"code": "FRAMEWORK__WRITE_MALFORMED_INPUT",
"title": "Bad Request",
"detail": "Expected data to be array.",
Also looking at the code there currently seems no handling of the tags. As far as I understand it, the tags would needed to be created on the fly
A possible fix would be the following code:
if (isset($data['tags']) { // inserted that lines
$data['tags'] = $data['tags']->all();
} // end inserted lines
$data = $this->completeData($data, $context);
Using that line, the last mentioned request works (you could then use the IDs of existing newsletter recipient tags).
Of course in this case the API docs have to be adapted.
TL;DR
In my opinion, this seems a flaw in the current Store API implementation.
I would suggest to create an issue on the Shopware 6 issue tracker.

ImportXML google sheet for shipment package tracking

I want to track each FEDEX, DHL and UPS shipment status directly from google sheets. I am using importxml function:
=IMPORTXML("https://www.fedex.com/apps/fedextrack/?action=track&tracknumbers="&C2&"&locale=en_US&cntry_code=us","//h1/div[#class="redesignSnapshotTVC snapshotController_addr_label dest"]/title")
However it shows error.
Attaching my sheet link for this: https://docs.google.com/spreadsheets/d/1E1L0rn9-H4MCutI1On2uHDkkPo1pdjRpv014YREGIdU/edit?usp=sharing
Please tell what is best way to do it. I am from non tech background.
Thanks so much for help!
Common issue. You're trying to import html that is generated after loading. That means we have to look for how the data you want is generated.
Data source
Upon inspection of the site, I found that it was making an XHR to the URL https://www.fedex.com/trackingCal/track, and that it was doing so via POST with a long payload. The response was in JSON format. Of note, there is the scanEventList entry.
"scanEventList": [{
"date": "2020-07-15",
"time": "13:15:00",
"gmtOffset": "-07:00",
"status": "Delivery exception",
"statusCD": "DE",
"scanLocation": "SAN BERNARDINO, CA",
"scanDetails": "Future delivery requested",
"scanDetailsHtml": "",
"rtrnShprTrkNbr": "",
"statusExceptionCode": "17",
"isClearanceDelay": false,
"isDelivered": false,
"isDelException": true,
"isException": true
},
...
]
Solution
First, get the ImportJSON script from GitHub, and add it into your sheet's scripts (Tools > Script Editor). It's not the most amazing thing, but it will at least give us ImportJSONViaPost() to get the data we want:
=INDEX(ImportJSONViaPost("https://www.fedex.com/trackingCal/track","data=%7B%22TrackPackagesRequest%22%3A%7B%22appType%22%3A%22WTRK%22%2C%22appDeviceType%22%3A%22DESKTOP%22%2C%22supportHTML%22%3Atrue%2C%22supportCurrentLocation%22%3Atrue%2C%22uniqueKey%22%3A%22%22%2C%22processingParameters%22%3A%7B%7D%2C%22trackingInfoList%22%3A%5B%7B%22trackNumberInfo%22%3A%7B%22trackingNumber%22%3A%22"&A2&"%22%2C%22trackingQualifier%22%3A%22%22%2C%22trackingCarrier%22%3A%22%22%7D%7D%5D%7D%7D&action=trackpackages&locale=en_US&version=1&format=json",,"/TrackPackagesResponse/packageList/scanEventList,/TrackPackagesResponse/packageList/trackingCarrierDesc","noHeaders"),1)
Arguments:
URL for the tracker
The POST payload. Cell A2 Holds your tracking number.
Leave empty
Query - Lets us select the data that we want. In this example, I chose to select the carrier description and the entire scanEventList entry, but you can specify particular elements of that as well.
"noHeaders" means just the data.
Just using the JSON import gives us an entry for each element of scanEventList, but the first is the most recent, so, we use INDEX to retrieve the first entry, which should contain what you need.
For additional help on the ImportJSON package, see here.

Which fields are required to create an event through Social Tables API

I have the following questions that I was not clear on from the API documentation:
Which fields are required to create an event?
What does "Invalid field: 0" mean? (this was an error message received when trying to create an event)
The sample body includes "spaces" as string -- is this the space name or ID?
Is this required? If yes, to create a space I need an event ID but to create an event do I need a space?
Hey thanks for using our API. It looks like the developer docs on our portal got kind of mangled. We'll be working on fixing that soon.
In the meantime, let me try to help.
So, the actual required fields for that endpoint are very minimal, here is a small sample post I made for a room here at Social Tables:
{
"name": "Dan's Office Party",
"category": "Other",
"spaces": [
{
"name": "st test"
}
]
}
The key thing here is that spaces is an array, with at least a name property attached.
The error message you referred to is a failing validation check on the type of one of the fields you submitted.
You do need a space to create an event, but as you can see, only the name is absolutely required. However, if you want to do any diagramming with that event, you'll probably want to attach a venue_id with one of our floorplan IDs in addition to the name property.
I have created an issue to update the mangled doc located at https://developer.socialtables.com/api-console#!/Events/post_4_0_legacyvm3_teams_team_events and will comment here when it is updated.

Google Search Image "no longer available: 403" [duplicate]

I am using google image search API. Till yesterday it was working, but today morning it says "This API is no longer available"
Is it officially closed, Or any error at my side
Request
https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q=cute+kittens
Response
{"responseData": null, "responseDetails": "This API is no longer available.", "responseStatus": 403}
The answer I found was using Google's Custom Search Engine (CSE) API. Note that this is limited to 100 free requests per day.
Creating cx and modifying it to search for images
Create custom search engine at https://cse.google.com/cse/create/new based on your search criteria.
Choose sites to search (leave this blank if you want to search the entire web, otherwise you can enter a site to search in one particular site)
Enter a name and a language for your search engine.
Click "create." You can now find cx in your browser URL.
Under "Modify your search engine," click the "Control Panel" button. In the "edit" section you will find an "Image Search" label with an ON/OFF button, change it to ON. Click "update" to save your changes.
Conducting a search with the API
The API endpoint url is https://www.googleapis.com/customsearch/v1
The following JSON parameters are used for this API:
q: specifies search text
num: specifies number of results. Requires an integer value between 1 and 10 (inclusive)
start: the "offset" for the results, which result the search should start at. Requires an integer value between 1 and 101.
imgSize: the size of the image. I used "medium"
searchType: must be set to "image"
filetype: specifies the file type for the image. I used `"jpg", but you can leave this out if file extension doesn't matter to you.
key: an API key, obtained from https://console.developers.google.com/
cx: the custom search engine ID from the previous section
Simply make a GET request by passing above parameters as JSON to the API endpoint (also listed above).
Note: If you set a list of referrers in the search engine settings, visiting the URL via your browser will likely not work. You will need to make an AJAX call (or the equivalent from another language) from a server specified in this list. It will work for only the referrers which were specified in the configuration settings.
Reference:
https://developers.google.com/custom-search/json-api/v1/reference/cse/list
Now You can search images with Custom image search API.
You can do this with two steps:
Get CUSTOM_SEARCH_ID
Go to - https://cse.google.ru/cse/all
Here you must create new Search Engine. Do this and enable Image Search at there.
Screen(i am Russian... sorry)
then get this search engine ID. To do this press at Get Code button:
And there find line with cx = "here will be your CUSTOM_SEARCH_ID":
Ok. It's done, now second step:
Get SERVER_KEY
Go to google Console - https://console.developers.google.com/project
Press to Create project button, enter the name and other required information.
Pick this project and go to Enable Apis
Now find Custom Search Engine.
And Enable it.
Now we must go to Credentials and create new Server Key:
Ok. Now we can use Image Search.
Query:
https://www.googleapis.com/customsearch/v1?key=SERVER_KEY&cx=CUSTOM_SEARCH_ID&q=flower&searchType=image&fileType=jpg&imgSize=xlarge&alt=json
Replace the SERVER_KEY and CUSTOM_SEARCH_ID and call this request.
Limit: for free you can search only 100 images per day.
If this is just for your own purposes (not for production) and you're not planning to abuse Google Image Search, you can simply extract first image URL from Google search results using JSOUP.
For example:
Code to retrieve image URL of the first thumbnail:
public static String FindImage(String question, String ua) {
String finRes = "";
try {
String googleUrl = "https://www.google.com/search?tbm=isch&q=" + question.replace(",", "");
Document doc1 = Jsoup.connect(googleUrl).userAgent(ua).timeout(10 * 1000).get();
Element media = doc1.select("[data-src]").first();
String finUrl = media.attr("abs:data-src");
finRes= "<img src=\"" + finUrl.replace("&quot", "") + "\" border=1/>";
} catch (Exception e) {
System.out.println(e);
}
return finRes;
}
Guide:
question - image search term
ua - user agent of the browser
After I read several responses I compiled a response with images:
Access the website: https://developers.google.com/custom-search/v1/introduction, on the page you will find this part, so click in the button Get a Key:
Create or select a project, and then NEXT:
Copy the API KEY:
Access the website to create your CX: https://cse.google.com/cse/create/new, write some random domain like “www.anypage.com”, (after we will delete), select a language, and define some name for your search engine. Click on the Button CREATE.
Will see this page, then click in Control Panel:
Copy the Search engine ID for later (this is your CX). After you can set to search in all websites (active Search the entire web, select on the random website www.anypage.com then click on the button Delete) and you can active Image search. So will see like this:
And Using REST you can get the results, using this example code (searching for flower):
<html lang="pt">
<head>
<title>JSON Custom Search API Example</title>
</head>
<body>
<div id="content"></div>
<script>
function hndlr(response) {
console.log(response);
for (var i = 0; i < response.items.length; i++) {
var item = response.items[i];
// in production code, item.htmlTitle should have the HTML entities escaped.
document.getElementById("content").innerHTML += "<br>" + item.htmlTitle;
}
}
</script>
<script src="https://www.googleapis.com/customsearch/v1?key=API_KEY&cx=SEARCH_ENGINE_KEY&q=flower&searchType=image&callback=hndlr"></script>
</body>
</html>
The base code is found here: https://developers.google.com/custom-search/v1/using_rest
After setting your API_KEY (key) and your SEARCH ENGINE KEY (cx), the result will see like this:
Thanks to #Vijay Shegokar, #aftamat4ik and #Alladinian
This is the full URL template to be used
We can eliminate unnecessary parameters.
https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json
I am using
https://www.googleapis.com/customsearch/v1?key=ap_key&cx=cx&q=hello&searchType=image&imgSize=xlarge&alt=json&num=10&start=1
Change the API url to
Google Custom Image search
Provide the same parameters along with with API KEY and CX.
More Info and Explorer
The Yahoo Boss API is a reasonable substitute, although it's not free and the results are not quite as good.
UPDATE: YAHOO BOSS JSON Search API will discontinue on March 31, 2016
SerpAPI enables to search through Google Images and returns a clean json. it integrates with most of the programming languages: python, php, java, golang, nodejs...
https://serpapi.com/images-results
Google limit the number of search per day.
but this service provides unlimited searches...
looks like we need to implement google custom search API
https://developers.google.com/custom-search/
says so on top of the page you provided yourself

How to get the most popular page under a section using Site Catalyst (Omniture)?

I want to use the site catalyst api to get the most popular page (page that has maximum pageviews) under a given site-section? Let me explain better with an example.
My website has multiple channels (News/Journals/Books/Events etc). Each of the channel has many pages under it. I want a api call that will get the most popular news page or Journals page or Books page etc.
I am passing data to sitecatalyst like this..
s.pageName = o_title;
s.channel = o_structure
s.prop1 = o_iden
where o_title has the page title of a newspage or a journalpage etc..
o_structure refers to either "News" or "Journals" or "Books" etc.
Currently I am able to only get the most popular page on the entire site. I would appreciate if someone can help me find the most popular page per section.
Thanks,
Rag
I assume that you already know the basics of using the Omniture API, how to queue up a report and look for status and get it etc... here is a basic REST data string to get site sections (s.channel) broken down by page names (s.pageName) with page views as metric. You will use the Report.QueueRanked API method, and you need to specify the rsid(s) to get the data from and the date ranges.
{
"reportDescription": {
"reportSuiteID":"RSID",
"dateFrom":"YYYY-MM-DD",
"dateTo":"YYYY-MM-DD",
"metrics":[
{
"id":"pageViews"
}
],
"sortBy":"pageViews",
"elements":[
{
"id":"siteSection"
},
{
"id":"page"
}
]
}
}