botframework v4: send slack blocks in channelData property not working - javascript

I'm using botframework v4 to deploy an azure bot. The bot will be used on both Teams and Slack channel.
The bot needs to send blocks layout to slack users. But when I put the blocks in channelData property, it always returns below issue
Error: Invalid ChannelData
at new RestError (D:\home\site\wwwroot\node_modules\#azure\ms-rest-js\dist\msRest.node.js:1397:28)
at D:\home\site\wwwroot\node_modules\#azure\ms-rest-js\dist\msRest.node.js:1849:37
at process._tickCallback (internal/process/next_tick.js:68:7)
Here is the code snippet
await context.sendActivity({
"channelData": {
"blocks": [
{
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/beagle.png",
"alt_text": "Welcome to my bot"
}
]
}
}
)
I've tried adding "text" property to the payloads, the text will be replied by the bot correctly, but no image shows after the text.
And I've also tried other several ways, like put the blocks to attachments property, all didn't work.
Does someone knows what is the correct way to pass the blocks data to Slack?
Thanks.

As I posted in the issue that #ErikKalkoken linked to, this feature currently isn't available. You have a couple of options:
Wait for the feature to be implemented. However, as one of the developers states:
Based on my understanding of the roadmap right now, the activities endpoint will not be updated with support for Block Kit any time soon.
Since it looks like you're looking for a javascript answer, you can use the BotKit Slack adapter

Related

Trying to build a slack bot and facing error "Error: not_allowed_token_type"

Was just trying to build a simple slack bot by following a YouTube link and started getting the error
Error: not_allowed_token_type
const bot = new SlackBot({
token: 'xoxb-TOKEN_GENERATED FROM SLACK SITE',
name: 'escalatorbot' // what name should I give here
})
Can somebody tell why I am facing this error
From your code snippet, I think you're using Slackbots.js and encountering a known problem resulting from recent changes in the slack api. The issue is logged here: https://github.com/mishk0/slack-bot-api/issues/145
The issue is releated with the new granular permissions app in slack, use the legacy bot on this url: https://api.slack.com/apps?new_classic_app=1 and then in Bots you can add legacy bot user and generate correct token
I have not fully understood your use case. On which API you got this error? For now, I can suggest you to use slack built-in tool for testing all API's (https://api.slack.com/methods/api.test/test)

track message reports using Multicast ID on google firebase in php

Is there a way to track delivery report of a particular message that have been sent via FCM to android device, i found we can add delivery_receipt_requested to track delivery and i have added that my json data as follows,
{"to":"KEY",
"data":{
"data":{
"title":"test message",
"message":"sent",
"image":null}
},
"notification":{
"delivery_receipt_requested":true
}
}
and i receive a response
{"multicast_id":6417448921485349071,"success":1,"failure":0,"canonical_ids":0,"results":[{"error":"false"}]}
In php or javascript i need something like if we pass that multicast_id need to get the current status of the text. I found it was almost nightmare to get the desired result, but its not impossible is there anyway guys?
There is currently no way to manually ask the FCM server about the status of the sent message.
Based from your post, it seems you already did your homework on checking the FCM service. Implementing the delivery receipts is the only way (AFAIK) that you could attain the behavior you mentioned in your post.
Implementing the delivery receipt not only needs the delivery_receipt_requested parameter in your payload, you have to implement an XMPP server protocol as well. Along with the Upstream Messaging part on your client app (for the acknowledgement part).

facebook graph api node.js invalid appsecret_proof

this is my first post so please go easy on me!
I am a beginning developer working with javascript and node.js. I am trying to make a basic request from a node js file to facebook's graph API. I have signed up for their developer service using my facebook account, and I have installed the node package for FB found here (https://www.npmjs.com/package/fb). It looks official enough.
Everything seems to be working, except I am getting a response to my GET request with a message saying my appsecret_proof is invalid.
Here is the code I am using (be advised the sensitive info is just keyboard mashing).
let https = require("https");
var FB = require('fb');
FB.options({
version: 'v2.11',
appId: 484592542348233,
appSecret: '389fa3ha3fukzf83a3r8a3f3aa3a3'
});
FB.setAccessToken('f8af89a3f98a3f89a3f87af8afnafmdasfasedfaskjefzev8zv9z390fz39fznabacbkcbalanaa3fla398fa3lfa3flka3flina3fk3anflka3fnalifn3laifnka3fnaelfafi3eifafnaifla3nfia3nfa3ifla');
console.log(FB.options());
FB.api('/me',
'GET',
{
"fields": "id,name"
},
function (res) {
if(!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
console.log(res);
console.log(res.id);
console.log(res.name);
}
);
The error I am getting reads:
{ message: 'Invalid appsecret_proof provided in the API argument',
type: 'GraphMethodException',
code: 100,
fbtrace_id: 'H3pDC0OPZdK' }
I have reset my appSecret and accessToken on the developer page and tried them immediately after resetting them. I get the same error, so I don't think that stale credentials are the issue. My
console.log(FB.options())
returns an appropriate looking object that also contains a long hash for appSecretProof as expected. I have also tried this code with a number of version numbers in the options (v2.4, v2.5, v2.11, and without any version key). Facebook's documentation on this strikes me as somewhat unclear. I think I should be using v2.5 of the SDK (which the node package is meant to mimic) and making requests to v2.11 of the graph API, but ??? In any case, that wouldn't seem to explain the issue I'm having. I get a perfectly good response that says my appSecretProof is invalid when I don't specify any version number at all.
The node package for fb should be generating this appSecretProof for me, and it looks like it is doing that. My other info and syntax all seem correct according to the package documentation. What am I missing here? Thank you all so much in advance.
looks like you have required the appsecret_proof for 2 factor authorization in the advance setting in your app.
Access tokens are portable. It's possible to take an access token generated on a client by Facebook's SDK, send it to a server and then make calls from that server on behalf of the client. An access token can also be stolen by malicious software on a person's computer or a man in the middle attack. Then that access token can be used from an entirely different system that's not the client and not your server, generating spam or stealing data.
You can prevent this by adding the appsecret_proof parameter to every API call from a server and enabling the setting to require proof on all calls. This prevents bad guys from making API calls with your access tokens from their servers. If you're using the official PHP SDK, the appsecret_proof parameter is automatically added.
Please refer the below url to generate the valid appsecret_proof,and add it to each api call
https://developers.facebook.com/docs/graph-api/securing-requests
I had to deal with the same issue while working with passport-facebook-token,
I finally released that the problem had nothing to have with the logic of my codebase or the app configuration.
I had this error just because I was adding intentionally an authorization Header to the request. so if you are using postman or some other http client just make sure that the request does not contain any authorization Header.

invite friends to created event using Graph API javascript

on my website users can already create facebook-events, but I can't figure out how to invite a list of selected user' friends to the newly created event by using the Graph API in javascript.
I already found lots of code examples using PHP but none using Javascript.
This is from the fb developer site:
"You can invite multiple users by issuing an HTTP POST to
/EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3."
but what code do I have to use to do so? My last try was:
FB.api('/EVENT_ID/invited?users=USER1_ID,USER2_ID','post', function(response) {
alert(response);
}
I've been searching for days now, please help me :)
I just discovered that you'll get a 200 error if you try and add the access tokens UID to the invitees list (yourself basically)... Took this into the graph explorer and kept trying my command, removing one UID at a time, and once I locked onto the offending UID the rest went through fine.
Try fooling around in the Graph Explorer - https://developers.facebook.com/tools/explorer/?method=GET&path=731980402

Facebook access token issue in JS implementation

I am new to FB apps and trying to get the accessToken for my website using JS. I have followed the steps given on the API docs, but I keep getting an
"error": {
"type": "OAuthException",
"message": "Error validating application."
}
I know that theres some issue with my implementation. Can someone please help me out.
If you can provide a link to a tutorial/code snippet that would be really great.
Since today there is a change in Facebook Graph API, the given access token is now URI-encoded, it may be this your problem, give a look here: http://forum.developers.facebook.net/viewtopic.php?pid=273730

Categories