Messenger sharing causes "Messenger Extensions unexpected error" - javascript

I'm trying to perform a share with the beginShareFlow()function of the facebook MessengerExtensions. However, when performing the call, I get following error message:
Messenger Extensions unexpected error.
The code for this error is 2018154.
I'm using following code to start a share:
ajax.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
var message = JSON.parse(this.responseText);
MessengerExtensions.beginShareFlow(function(share_response) {
if(share_response.is_sent){
// close the window w/ requestCloseBrowser().
}
},
function(errorCode, errorMessage) {
console.log(errorCode+"-"+errorMessage);
},
message,
"current_thread");
}
}
You'll see that I'm using the response of an ajax call to fill up the actual message. This is generated by some backend php code, an example:
{"attachment":{"type":"template","payload":{"template_type":"generic","sharable":"true","elements":[{"title":"Kerk Poederlee","image_url":"https:\/\/www.wouterh.be\/pogo\/static\/images\/raid.jpg","subtitle":"joining at 1535629500","default_action":{"type":"web_url","url":"https:\/\/www.wouterh.be\/pogo"},"buttons":[{"type":"web_url","url":"https:\/\/www.wouterh.be\/pogo","title":"join raid"}]}]}}}
Messenger extension themselves have been loaded correctly, since I'm able to retrieve the PSID with following code:
window.extAsyncInit = function() {
MessengerExtensions.getContext('APPID',
function success(thread_context){
fb_user_id = thread_context.psid;
},
function error(err){}
);
};
This error occurs on a web client and on the most recent iOS messenger. When I send the exact same message through the Send API instead of the sharing messenger extensions, it works perfectly. Could somebody help me figure out what's causing the error?

I found the mistake, in the message you can pass a 'sharable' property. I passed the string value "true" to it, but this should be a boolean value.
This is the corrected content:
{
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"sharable": true,
"elements": [{
"title": "Kerk Poederlee",
"image_url": "https:\/\/www.wouterh.be\/pogo\/static\/images\/raid.jpg",
"subtitle": "joining at 1535629500",
"default_action": {
"type": "web_url",
"url": "https:\/\/www.wouterh.be\/pogo"
},
"buttons": [{
"type": "web_url",
"url": "https:\/\/www.wouterh.be\/pogo",
"title": "join raid"
}]
}]
}
}
}

Related

How to get JSON payload sent by the Slack action message?

I am trying to build a Slack bot with interactive buttons. I have set up a Google Apps Script to handle the action performed on the Slack message. I want the payload of the request sent by the Slack. I have tried to get the request object by doing
function doPost(e) {
return processComment(e);
}
function processComment(e) {
Logger.log(e);
}
{postData=FileUpload, queryString=method=slack, parameter={method=slack, payload={"type":"block_actions","user":{"id":"U01835Mxxxx","username":"ravsamteam","name":"ravsamteam","team_id":"T0160UQZZZZ"},"api_app_id":"A018MPZ2xxx","token":"NTNRCTPDz8mxxxzxxxxxxxxx","container":{"channel_id":"C0190D8L2AU","is_ephemeral":false,"message_ts":"1597154895.001500","type":"message"},"trigger_id":"1281039280903.1204976558018.aa1055f6900d7884d9cd4ac34ffzzzzz","team":{"id":"T0160UQGE0J","domain":"ravsamhq"},"channel":{"id":"C0190D8L2AU","name":"blogs"},"message":{"type":"message","subtype":"bot_message","text":"This content can't be displayed.","ts":"1597154895.001500","bot_id":"B019BNL08BS","blocks":[{"type":"section","block_id":"mNavk","text":{"type":"mrkdwn","text":" New comment on RavSam's blog by hello","verbatim":false}},{"type":"section","block_id":"v3Ip","text":{"type":"mrkdwn","text":"*Blog:*\nhello\n\n*Comment:*\nravgeet errorCannot read property 'payload' of undefined","verbatim":false}},{"type":"actions","block_id":"1maVO","elements":[{"type":"button","action_id":"WSo=","text":{"type":"plain_text","text":"Approve","emoji":true},"style":"primary","value":"approved"},{"type":"button","action_id":"Vek\/","text":{"type":"plain_text","text":"Deny","emoji":true},"style":"danger","value":"denied"}]}]},"response_url":"https:\/\/hooks.slack.com\/actions\/T0160Uxxxxx\/1301968xxxxxx\/Q3gZhbeUCUIxxxxxxxxxxxxx","actions":[{"action_id":"WSo=","block_id":"1maVO","text":{"type":"plain_text","text":"Approve","emoji":true},"type":"button","value":"approved","action_ts":"1597213837.152704"}]}}, contentLength=2391.0, parameters={payload=[Ljava.lang.Object;#53f2e9fa, method=[Ljava.lang.Object;#5793298b}, contextPath=}
How do I get the payload? Once I have the payload JSON, I can use the actions to determine what action was taken by the user?
Yes. The payload contains all the information you need to identify the action. And it also contains a response_url to respond back.
Slack payload should look like this.
{
"actions": [
{
"name": "channels_list",
"selected_options": [
{
"value": "C012AB3CD"
}
]
}
],
"callback_id": "select_simple_1234",
"team": {
"id": "T012AB0A1",
"domain": "pocket-calculator"
},
"channel": {
"id": "C012AB3CD",
"name": "general"
},
"user": {
"id": "U012A1BCD",
"name": "musik"
},
"action_ts": "1481579588.685999",
"message_ts": "1481579582.000003",
"attachment_id": "1",
"token": "iUeRJkkRC9RMMvSRTd8gdq2m",
"response_url": "https://hooks.slack.com/actions/T012AB0A1/123456789/JpmK0yzoZDeRiqfeduTBYXWQ",
"trigger_id": "13345224609.738474920.8088930838d88f008e0"
}
You can learn more here.

Teams botframework send proactive message REST api

I Try to create new converation and send proactive message with teams bot (botfreamwork).
I used this document to do that.
I POST to : SERVICE_URL/v3/conversations/
BODY:
{
"bot": {
"id": BOT_ID
},
"members": [
{
"id": USER_ID
}
],
"channelData": {
"tenant": {
"id": TENANT_ID
}
}
}
BOT_ID - I put the app id of the bot (with a prefix of "28:")
USERֹ_ID - I copied the USER_ID from a message I received from the user (not in a proactive message)
TENANT_ID - I took the tenant id from the link of the teams
I get this error:
{
"error": {
"code": "BadSyntax",
"message": "Invalid user identity in provided tenant"
}
}
I made several attempts to change the user ID: I changed to a user that appears in ADD, I changed with a prefix of 29: and without a prefix of 29: - nothing helped, this error continues to appear.
What am I missing?

How to use text to Speech feature in Cocos creator Java script - Android/IOS APP

I am developing a cocos creator game and it is build both android and IOS versions. I need to add "text to speech" feature into that APP. But I tried a lot to find a text to speech API but none of them work with Android/IOS app.
following solutions also work only with web browser.
Using Google Text-To-Speech in Javascript
So I decided to use Google Cloud - text to speech API but after lot of try, I decided to ask from you all...
As my understanding in Google Cloud, we have given following details.
Request URL : https://texttospeech.googleapis.com/v1beta1/text:synthesize
Request body :
{
"audioConfig": {
"audioEncoding": "LINEAR16",
"pitch": 0,
"speakingRate": 1
},
"input": {
"text": "Hello world"
},
"voice": {
"languageCode": "en-US",
"name": "en-US-Wavenet-D"
}
}
I think I have to write HTTP Post request using above information in order to get translation. I wrote sample server request but it does not give good result. please see below..
sendServerReq : function(){
var restChannel = cc.loader.getXMLHttpRequest();
restChannel.open("POST", 'https://texttospeech.googleapis.com/v1beta1/text:synthesize', true);
restChannel.setRequestHeader("Content-Type", "application/json");
var jsonObj = {
"audioConfig": {
"audioEncoding": "LINEAR16",
"pitch": 0,
"speakingRate": 1
},
"input": {
"text": "おはようございます"
},
"voice": {
"languageCode": "ja-JP",
"name": "ja-JP-Standard-B"
}
};
var response = restChannel.send(jsonObj);
},
could you please let me know how to use Google cloud for "text to speech" feature or is there are any free api to get text to Speech feature in COCCOS Creator Android/IOS app.
Thank you very much
what I need is to add text to speech feature into my game app
sendServerReq : function(){
var restChannel = cc.loader.getXMLHttpRequest();
restChannel.open("POST", 'https://texttospeech.googleapis.com/v1beta1/text:synthesize', true);
restChannel.setRequestHeader("Content-Type", "application/json");
var jsonObj = {
"audioConfig": {
"audioEncoding": "LINEAR16",
"pitch": 0,
"speakingRate": 1
},
"input": {
"text": "おはようございます"
},
"voice": {
"languageCode": "ja-JP",
"name": "ja-JP-Standard-B"
}
};
var response = restChannel.send(jsonObj);
},
That’s an error.
The requested URL /v1beta1/text:synthesize was not found on this server

What is wrong with my JSON output for a Slack Message payload?

I have set up what I think should be a working JSON output to send a message in slack but Slack keeps rejecting it.
I have tried multiple different message layout formats using the guides on slack's api site, but so far the only method that has successfully sent is a fully flat JSON with no block formatting.
function submitValuesToSlack(e) {
var name = e.values[1];
var caseNumber = e.values[2];
var problemDescription = e.values[3];
var question = e.values[4];
var completedChecklist = e.values[5];
var payload = [{
"channel": postChannel,
"username": postUser,
"icon_emoji": postIcon,
"link_names": 1,
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Name:*\n " + name
}
]
}]
}];
console.log(JSON.stringify(payload, null, "\t"));
var options = {
'method': 'post',
'payload': JSON.stringify(payload)
};
console.log(options)
var response = UrlFetchApp.fetch(slackIncomingWebhookUrl, options);
}
When I run this, I get the following output:
[
{
"channel":"#tech-support",
"username":"Form Response",
"icon_emoji":":mailbox_with_mail:",
"link_names":1,
"blocks":[
{
"type":"section",
"fields":[
{
"type":"mrkdwn",
"text":"*Name:*\n test"
}
]
}
]
}
]
Which I believe is correct, however slack api just rejects it with an HTTP 400 error "no text"
am I misunderstanding something about block formatting?
EDIT:
To Clarify, formatting works if I use this for my JSON instead of the more complex format:
{
"channel":"#tech-support",
"username":"Form Response",
"icon_emoji":":mailbox_with_mail:",
"link_names":1,
"text":"*Name:*\n test"
}
The reason you are getting the error no_text is because you do not have a valid message text property in your payload. You either need to have a text property as top line parameter (classic style - your example at the bottom) or a text block within a section block.
If you want to put to use blocks only (as you are asking) the section block is called text, not fields. fields is another type of section bock that has a different meaning.
So the correct syntax is:
[
{
"channel":"#tech-support",
"username":"Form Response",
"icon_emoji":":mailbox_with_mail:",
"link_names":1,
"blocks":[
{
"type":"section",
"text":[
{
"type":"mrkdwn",
"text":"*Name:*\n test"
}
]
}
]
}
]
Also see here for the official documentation on it.
Blocks are very powerful, but can be complicated at times. I would recommend to use the message builder to try out your messages and check out the examples in the docu.

How to correctly use Google's Javascript OAuth2.0 library

I am trying to access some google APIs from my javascript client using Oauth2. I've succeeded in getting the user to authenticate requests, but there's some unexpected behaviour when running the code below that'd I'd like to understand. When I click the 'authorize' button the first time, the result is:
'[ { "error": { "code": 401, "message": "Login Required", "data": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", "location": "Authorization" } ] }, "id": "gapiRpc" } ] '
on the second click the result is
[ { "id": "gapiRpc", "result": { "id": "1115793426680xxxx", "email": "xxxxx#gmail.com", "verified_email": true } } ]
here is the code for the page I am testing
<div id='sign in'>
<button onclick="init();">Authorize</button>
</div>
<p id="output">hello</p>
<script type="text/javascript">
function init() {
document.getElementById('output').innerHTML='loading oauth2 api'
gapi.client.load('oauth2', 'v2', auth);
}
function auth() {
var config = {
client_id: '2264xxxxx-odt0g7jn8vspa3ot9ogjxxxxxxxxx.apps.googleusercontent.com',
scope: 'https://www.googleapis.com/auth/userinfo.email',
immediate:true
};
document.getElementById('output').innerHTML='authorizing'
gapi.auth.authorize(config, authed());
}
function authed() {
document.getElementById('output').innerHTML='authorized'
var request = gapi.client.oauth2.userinfo.get().execute(
function(resp, raw) {
document.getElementById('output').innerHTML=raw
}
);
}
</script>
<script src="https://apis.google.com/js/client.js"></script>
<!--<script src="https://apis.google.com/js/client.js?onload=init"></script>-->
Could you please explain why I would get a 'login required' on the first execution of the code and a successful authentication on the second execution?
Due to the parentheses immediately after "authed" in the call to gapi.auth.authorize, the authed() callback is run immediately, prior to the call to gapi.auth.authorize.
Also, in your authed() handler you need to check to see whether the authorization check with immediate: true succeeded; for more details, see the reference documentation here:
https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiauthauthorize
Also refer to the section on pop-up blocking here:
https://developers.google.com/api-client-library/javascript/features/authentication#popup
When the "immediate" authorization fails, the authed callback will be invoked with a null token object, or a token object containing an "error" field; in these cases you need to present a user interface element the user can click which will re-run the gapi.auth.authorize call but with "immediate" set to false (or omitted). This allows the authorization pop-up to be opened without running afoul of your browser's pop-up blocker.

Categories

Resources