API key for Google chart required? - google-cloud-platform

I am using a
https://developers.google.com/chart/interactive/docs/gallery/geochart on a website to create a really simple representation of distributions around the world. For example, we have 3 people in the USA, 4 people in Sweden and so on.
Everything works fine, but my browser sometimes warns me that I need to specify an API key.
Now my question is: Why do I need an API key when I only use static data?
Thank you very much for your answer in advance
{
type: 'GeoChart',
columnNames: ['Country', 'No'],
data: [
["United States", 2], ["Sweden", 4],...]
],
options: {
region: 'world',
}
}

Related

AWS Kendra PreHook Lambdas for Data Enrichment

I am working on a POC using Kendra and Salesforce. The connector allows me to connect to my Salesforce Org and index knowledge articles. I have been able to set this up and it is currently working as expected.
There are a few custom fields and data points I want to bring over to help enrich the data even more. One of these is an additional answer / body that will contain key information for the searching.
This field in my data source is rich text containing HTML and is often larger than 2048 characters, a limit that seems to be imposed in a String data field within Kendra.
I came across two hooks that are built in for Pre and Post data enrichment. My thought here is that I can use the pre hook to strip HTML tags and truncate the field before it gets stored in the index.
Hook Reference: https://docs.aws.amazon.com/kendra/latest/dg/API_CustomDocumentEnrichmentConfiguration.html
Current Setup:
I have added a new field to the index called sf_answer_preview. I then mapped this field in the data source to the rich text field in the Salesforce org.
If I run this as is, it will index about 200 of the 1,000 articles and give an error that the remaining articles exceed the 2048 character limit in that field, hence why I am trying to set up the enrichment.
I set up the above enrichment on my data source. I specified a lambda to use in the pre-extraction, as well as no additional filtering, so run this on every article. I am not 100% certain what the S3 bucket is for since I am using a data source, but it appears to be needed so I have added that as well.
For my lambda, I create the following:
exports.handler = async (event) => {
// Debug
console.log(JSON.stringify(event))
// Vars
const s3Bucket = event.s3Bucket;
const s3ObjectKey = event.s3ObjectKey;
const meta = event.metadata;
// Answer
const answer = meta.attributes.find(o => o.name === 'sf_answer_preview');
// Remove HTML Tags
const removeTags = (str) => {
if ((str===null) || (str===''))
return false;
else
str = str.toString();
return str.replace( /(<([^>]+)>)/ig, '');
}
// Truncate
const truncate = (input) => input.length > 2000 ? `${input.substring(0, 2000)}...` : input;
let result = truncate(removeTags(answer.value.stringValue));
// Response
const response = {
"version" : "v0",
"s3ObjectKey": s3ObjectKey,
"metadataUpdates": [
{"name":"sf_answer_preview", "value":{"stringValue":result}}
]
}
// Debug
console.log(response)
// Response
return response
};
Based on the contract for the lambda described here, it appears pretty straight forward. I access the event, find the field in the data called sf_answer_preview (the rich text field from Salesforce) and I strip and truncate the value to 2,000 characters.
For the response, I am telling it to update that field to the new formatted answer so that it complies with the field limits.
When I log the data in the lambda, the pre-extraction event details are as follows:
{
"s3Bucket": "kendrasfdev",
"s3ObjectKey": "pre-extraction/********/22736e62-c65e-4334-af60-8c925ef62034/https://*********.my.salesforce.com/ka1d0000000wkgVAAQ",
"metadata": {
"attributes": [
{
"name": "_document_title",
"value": {
"stringValue": "What majors are under the Exploratory track of Health and Life Sciences?"
}
},
{
"name": "sf_answer_preview",
"value": {
"stringValue": "A complete list of majors affiliated with the Exploratory Health and Life Sciences track is available online. This track allows you to explore a variety of majors related to the health and life science professions. For more information, please visit the Exploratory program description. "
}
},
{
"name": "_data_source_sync_job_execution_id",
"value": {
"stringValue": "0fbfb959-7206-4151-a2b7-fce761a46241"
}
},
]
}
}
The Problem:
When this runs, I am still getting the same field limit error that the content exceeds the character limit. When I run the lambda on the raw data, it strips and truncates it as expected. I am thinking that the response in the lambda for some reason isn't setting the field value to the new content correctly and still trying to use the data directly from Salesforce, thus throwing the error.
Has anyone set up lambdas for Kendra before that might know what I am doing wrong? This seems pretty common to be able to do things like strip PII information before it gets indexed, so I must be slightly off on my setup somewhere.
Any thoughts?
since you are still passing the rich text as a metadata filed of a document, the character limit still applies so the document would fail at validation step of the API call and would not reach the enrichment step. A work around is to somehow append those rich text fields to the body of the document so that your lambda can access it there. But if those fields are auto generated for your documents from your data sources, that might not be easy.

Audio tag is not working in Alexa's SSML, Alexa's reminder API

I am trying to create a reminder using Alexa's Reminder API in my custom Alexa Skill and in the SSML, I am passing the speak tag and in that, I have few words and audio tag too.
const reminderRequest = {
trigger: {
type: 'SCHEDULED_RELATIVE',
offsetInSeconds: '10',
},
alertInfo: {
spokenInfo: {
content: [{
locale: "en-US",
text: "Testing Reminder",
ssml: "<speak>Testing Reminder <audio src='https://vishalsholkaybucket.s3.amazonaws.com/uk_21042020.mp3' /></speak>"
}],
},
},
pushNotification: {
status: 'ENABLED',
},
};
The output to above in my Alexa device is:
Testing
The reminder works properly but when it comes to playing the audio file, it just keeps its light on and doesn't play the audio file, other SSML tags like break etc is working fine but only the audio tag is not working. I was under the impression that SSML tags work everywhere, I tried reading the documentation but it is not clear enough.
Also, if this is not the right approach, can anyone let me know If I can play a short audio file in Alexa's reminder API or is there any way in which I can remind the user along with an audio file.
Thanks in advance.
Edit: I am using Alexa's skill reminders demo. Nothing else is changed just trying to push the above request in the Reminders API.

AWS-Console: DynamoDB scan on nested field

I have below table in DynamoDB
{
"id": 1,
"user": {
"age": "26",
"email": "testuser#gmail.com",
"name": "test user"
}
}
Using AWS console, I want to scan all the records whose email address contains gmail.com
I am trying this but it is giving no results.
I am new to AWS, not sure what's wrong here. Is it not possible to scan on nested fields?
I've been trying to figure this out myself but it would seem that nested item scans are not supported through the console.
I'm going based off of this which offer some alternative options via CLI or SDK: https://forums.aws.amazon.com/thread.jspa?messageID=931016

How to send GET request to API

Summary: I have a job board, a user searches a zip code and all the jobs matching that zip code are displayed, I am trying to add a feature that lets you see jobs within a certain mile radius of that zip code. There is a web API ( www.zipcodeapi.com ) that does these calculations and returns zip codes within the specified radius, I am just unsure how to use it.
Using www.zipcodeapi.com , you enter a zip code and a distance and it returns all zip codes within this distance. The format for API request is as follows: https://www.zipcodeapi.com/rest/<api_key>/radius.<format>/<zip_code>/<distance>/<units>, so if a user enters zip code '10566' and a distance of 5 miles, the format would be https://www.zipcodeapi.com/rest/<api_key>/radius.json/10566/5/miles and this would return:
{
"zip_codes": [
{
"zip_code": "10521",
"distance": 4.998,
"city": "Croton On Hudson",
"state": "NY"
},
{
"zip_code": "10548",
"distance": 3.137,
"city": "Montrose",
"state": "NY"
}
#etc...
]
}
My question is how do I send a GET request to the API using django?
I have the user searched zip code stored in zip = request.GET.get('zip') and the mile radius stored in mile_radius = request.GET['mile_radius']. How can I incorporate those two values in their respective spots in https://www.zipcodeapi.com/rest/<api_key>/radius.<format>/<zip_code>/<distance>/<units> and send the request? Can this be done with Django or do I have this all confused? Does it need to be done with a frontend language? I have tried to search this on google but only find this for RESTful APIS, and I dont think this is what I am looking for. Thanks in advance for any help, if you couldn't tell i've never worked with a web API before.
You can use the requests package, to do exactly what you want. It's pretty straightforward and has good documentation.
Here's an example of how you could perform it for your case:
zip_code = request.GET.get('zip')
mile_radius = request.GET['mile_radius']
api_key = YOUR_API_KEY
fmt = 'json'
units = 'miles'
response = requests.get(
url=f'https://www.zipcodeapi.com/rest/{api_key}/radius.{fmt}/{zip_code}/{mile_radius}/{units}')
zip_codes = response.json().get('zip_codes')
zip_codes should then be an array with those dicts as in your example.

Using facebook fql, how do I find where a school is?

[Note: the first two answers, which includes the one I wrote, do not yet deal with the "optional" fql.multiquery issue.]
When I am using facebook's fql, I can get a list of schools I have attended, or that friends have attended. Specifically, I can get the school's name, and it's facebook id. However, I do not know how to query for deeper information about these schools.
Specifically, I would like to find out where the schools were located. But, I do not know what facebook graph entity (or whatever else) those school ids are part of.
How would I find out from facebook where these schools are located?
Optional: It would be even better if this can be done in the same multiquery that returned the lists of schools in the first place (this would be a query against the user table for my id and another query against the user table for some ids of my friends).
Here's an expanded version of the optional part mentioned in the above paragraph (note that I tried adding this as a separate question, but when I went in make the illustrative data more relevant, I saw that it had silently vanished. So I am assuming I tripped over some feature of stack overflow designed to weed out questions which are too similar to each other. So, instead, let's just say that this is a clarification of what I meant, in the above paragraph)
Using facebook's javascript sdk, this fails, silently:
FB.login(function(response){
disp('loginResponse', response);
var userQuery= FB.Data.query(
'select uid,name,education from user where uid= {0}'
, response.session.uid);
var friendlist = FB.Data.query(
'select uid2 from friend where uid1 = {0} order by rand() limit 10'
, response.session.uid);
var friends = FB.Data.query(
'select uid,name,education from user where uid in (select uid2 from {0})'
, friendlist);
var friendSchools= FB.Data.query(
'select page_id,name,location from page where page_id in (select education.school.id from {0})'
, friends);
self.queries= [userQuery, friendlist, friends, friendSchools];
FB.Data.waitOn(queries
, function() {alert(1)});
})
If I remove the friendSchools element from the queries array, it works just fine, and a friend might be represented by an object like this:
{
uid: '...',
name: '...',
education:
[
{
school:
{
id: '115920001751600',
name: 'Burlington High School'
},
year:
{
id: '138792749476094',
name: '1978'
},
type: 'High School'
},
{
school:
{
id: '20697868961',
name: 'Boston University'
},
degree:
{
id: '188387604516411',
name: 'BS'
},
year:
{
id: '103823546338323',
name: '1982'
},
type: 'College'
}
]
}
So, how do I restructure the where clause in the friendSchools query so that that query can be performed?
In other words, how can I use fql.multiquery to find information about schools (or other such entities) returned elsewhere in the multiquery?
I would suggest using batch requests (more information here: https://developers.facebook.com/docs/reference/api/batch/) to query the graph based on the schools ID you already have. The location of the school can be retrieved in it's default basic information returned (example below).
{
"id": "6192688417",
"name": "Stanford University",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/41571_6192688417_2310209_s.jpg",
"link": "https://www.facebook.com/stanford",
"likes": 203153,
"category": "Education",
"website": "http://www.stanford.edu",
"username": "stanford",
"founded": "1891",
"location": {
"street": "450 Serra Mall",
"city": "Stanford",
"state": "CA",
"country": "United States",
"zip": "94305",
"latitude": 37.42895,
"longitude": -122.1697
},
"public_transit": "http://transportation.stanford.edu",
"general_info": "Located between San Francisco and San Jose in the heart of Silicon Valley, Stanford University is recognized as one of the world's leading research and teaching institutions.\n\nLeland and Jane Stanford founded the University to \"promote the public welfare by exercising an influence on behalf of humanity and civilization.\" Stanford opened its doors in 1891, and more than a century later, it remains dedicated to finding solutions to the great challenges of the day and to preparing our students for leadership in today's complex world.",
"checkins": 9938
}
And, it looks like to get fql to work I want to be querying the page table. For example:
select name,location from page where page_id = 87873693141
(That said, I'm still trying to figure out how to extract the list my education's school ids into the where clause for a multi-query.)