Google Action Console(Cloud function editor) How to add image to a Media/MediaObject - google-assistant-sdk

Hi i'am working with google assistant, i'am using Action Builder in the Google Action Console. And i working with google Cloud function editor provided in the Action Console to test my webhook. I would like to use a media player to read an mp3 song that i provide with an url. i followed the documentation here : https://developers.google.com/assistant/conversational/prompts-media and i used this code :
app.handle('media', (conv) => {
conv.add('This is a media response');
conv.add(new Media({
mediaObjects: [
{
name: 'Media name',
description: 'Media description',
url: 'https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
image: {
large: JAZZ_IN_PARIS_IMAGE,
}
}
],
mediaType: 'AUDIO',
optionalMediaControls: ['PAUSED', 'STOPPED'],
startOffset: '2.12345s'
}));
});
Problem is that this code work when i remove the image but if i keep it i got an error :
Unsuccessful webhook call due to client issue: Error querying agent endpoint. State: URL_UNREACHABLE, reason: UNREACHABLE_5xx.
and in the webhookResponse i got :
"error": "JAZZ_IN_PARIS_IMAGE is not defined"
My question is how to send image in a MediaObject send by a webhook? Where do i have to store my image and how to add it in the response?

In the code snippet, JAZZ_IN_PARIS_IMAGE is not defined directly but is supposed to be an Image object, like png or jpg. A MediaObject can have a large image and/or an icon.
For testing purposes, you can upload a file to your Cloud Storage or just take any image from the web. But when you move forward you really should fix that image URL and provide corrected alt text.
conv.add('This is a media response');
conv.add(new Media({
mediaObjects: [
{
name: 'Media name',
description: 'Media description',
url: 'https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
image: {
large: {
url: 'https://serebii.net/pokearth/sprites/green/025.png',
alt: 'This is a sprite of Pikachu!',
},
}
}
],
mediaType: 'AUDIO',
optionalMediaControls: ['PAUSED', 'STOPPED'],
startOffset: '2.12345s'
}));
});

Related

sending an email with attachments using 'react-native-mail' library works but didn't receive email

I have a React Native app (Only for IOS) and I implemented a feature where user can share a pdf file via email using the Mail app on ios devices. I used 'react-native-mail' library for this feature and it works great. However, there was one person who said that it did send an email but didn't get an email. Checked spam folder and tried everything we could to find an email. Thought it was an issue with email credentials so we tried with a brand new gmail account but still didn't get an email.
Let me explain how this library works first. You need to set up a gmail account (has to be gmail to get this library to work) in Settings on your ios device (if there are multiple gmail accounts, only the first one is used as a sender for the react-native-mail library.) Then activate mail app with this email account. Go to the app then enter a recipient then send an email with any attachments (for my case, a small pdf file.) then we get an email on the recipient gmail account!
I could be sure an email is sent because when I get the event, it says 'sent'. I tried to reproduce the issue that person had but there was no luck. Here's my code snippet below.
const sharePdf = async () => {
Mailer.mail(
{
subject: 'Assessment Report',
recipients: [currentUser.email ? currentUser.email : ''],
body: 'Assessment Report',
isHTML: true,
attachments: [
{
path: reportUri,
type: 'pdf',
name: 'Report',
},
],
},
(error, event) => {
console.log('error => ', error);
if (error === 'not_available') {
Alert.alert(
'Please add a Gmail (Google) account to your iPad',
'Go to settings > Mail > accounts > Add Account > Google',
[
{
text: 'OK',
onPress: () => console.log('OK: Email Error Response'),
},
],
{cancelable: true},
);
} else {
Alert.alert(
event,
error,
[
{
text: 'Ok',
onPress: () => console.log('OK: Email Error Response'),
},
],
{cancelable: true},
);
}
},
);
};
please help me if anyone has faced this issue or has an idea of fixing this issue.. Thank you :)

File Upload is not uploading in React Native iOS, Same is working in android platform

I am try to upload the document, file from react native app. The api is working fine in Android platform but in iOS, I am not able to upload the same. I am using apisauce version ^2.0.0, the strange thing I am not getting any error. Server did not get the request.
Following is the form data:
{ "_parts": [ [ "attachment", { "uri": "file:///Users/yogeshchauhan/Library/Developer/CoreSimulator/Devices/3BCF94FF-0E3E-41E4-B1D5-700E1F85BF4F/data/Containers/Data/Application/9E8CB982-DB6F-439F-BFB8-0DB341E15768/Library/Caches/ImageManipulator/0D8DAD55-4658-4132-A118-12F2302ACF93.jpg", "type": "image/jpeg", "name": "C23BD088-411F-4C4A-A6B0-82DB9945D49A.jpg" } ] ] }
I am using the following version of react:
"react": "16.13.1",
"react-native": "0.63.0"
In iOS you have to remove file:// from the uri, pass image path without file://. For example on file select set selected image in one of your state variable for example call it selectedImage. And when you pass on image replace file:// with blank string based on device like this :
const datas = new FormData();
datas.append('images', {
name: selectedImage.fileName,
type: selectedImage.type,
uri:
Platform.OS === 'android' ? selectedImage.uri : selectedImage.uri.replace('file://', ''),
});

How to get remote GraphQL data when i use local state in Vue-apollo

I used Vuex with vue-apollo.
But now i know vue-apollo store data in cache then i can use local state by using cache.
When i saw offical document from local state
I knew how can i get and set data from local state but there is no mention how to get data from remote server.
I saw this code from document, they just write to cache temp data.
cache.writeData({
data: {
todoItems: [
{
__typename: 'Item',
id: 'dqdBHJGgjgjg',
text: 'test',
done: true,
},
],
},
});
So, i think i can get remote data by using vue-apollo query like below.
apollo: {
world: {
query: gql`query {
hello
}`,
update: data => data.hello
}
}
After i get server data like above, i can query/mutate from local state.
But this is only my guess, is this correct?
I found example from github. My guess is right.

React native share function on ios not share the right content

React native IOS Share.
When i use share function on ios, the application share all application file and not the words passed by message parameter.
Help?
Share.share({
message: ('' + this.props.words),
url: '',
title: title
}, {
dialogTitle: title,
excludedActivityTypes: [
'com.apple.UIKit.activity.PostToTwitter'
],
});

updating a youtube video (api v3) returns 'video not found' but works in their API explorer

I'm trying to update the description on my youtube video via some python code.
This is my PUT request
body (this is converted to a json string):
{'id': <the video's youtube id>,
'snippet': {
'categoryId': <category id>,
'channelId': <channel id>,
'description': 'new title',
'title': 'new title'
}}
headers:
{'Authorization': 'Bearer <access token given via the oauth flow>'
url:
https://www.googleapis.com/youtube/v3/videos?part=snippet&key=<my_youtube_api_key>
}
and I'm getting this response:
{
"error": {
"errors": [
{
"message": "Video not found"
}
],
"code": 500,
"message": "Video not found"
}
}
The odd thing is that the same query works from the API explorer on this page:
https://developers.google.com/youtube/v3/docs/videos/update
I'm copying and pasting the params from my python code, so it's not like a youtube video with that id doesn't actually exist.
What's going on?
The only change I've made is add the following header:
'Content-Type':'application/json'
and the API call works now.

Resources