How to create a shared channel via Slack conversation API? - slack-api

I would like to programmatically create a channel in Slack, make it shared and get the invitatino link. I found two APIS: conversations.create and conversations.invite but they'r only applicable to channels within the workspace. Doesn't seem what I want to do is possible with the Slack APIs currently, but wanted to see if anybody had a work around.

You could use the conversations.inviteShared API method.
This Slack Connect API method creates an invitation to a Slack
Connect channel. The invitation can be sent to users or bots in
another workspace either as a shareable URL or as an email invite.
The invited user must be known to your app (i.e., a channel is already
shared between the organization your app is installed on and the
organization of the user).
If the channel to be joined is not already a Slack Connect channel, it
becomes a Connect channel when you use this method to invite users
from another workspace.
Here's what worked for me:
Step 1: Create a Slack Channel via Vanilla JS
// Headers
const headers = {
'Content-type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer ' + yourAPIToken
}
// Create Slack channel
let create = await fetch('https://slack.com/api/conversations.create', {
method: 'POST',
headers: headers,
body: JSON.stringify({
'team_id': 'CXXXXXXX' // Your team id,
'is_private': true, // Optional. Create a private channel instead of a public one
'name': 'your-channel' // Your desired channel name
})
}).then(response => response.json());
console.log(create);
Step 2: Invite yourself (and/or default users)
This is important. Otherwise no one will see the channel.
// Invite default users
let invite = await fetch('https://slack.com/api/conversations.invite', {
method: 'POST',
headers: headers,
body: JSON.stringify({
channel: create.channel.id,
users: 'XXXXXXXXX,XXXXXXXXX' // A comma separated list of user IDs.
})
}).then(response => response.json());
console.log(invite);
Step 3: Invite external users via email
// Invite default users
// NOTE: The body object wasn't accepted for some reason, so moved it to the URI instead.
let inviteShared = await fetch('https://slack.com/api/conversations.inviteShared?channel='
+ create.channel.id + '&emails='
+ encodeURIComponent('yourExternal#email.com'), {
method: 'POST',
headers: headers,
}).then(response => response.json());
console.log(inviteShared);

Related

Perform call to Microsoft Graph Api for Intune approveApps

I am working on automating Intune to perform the Managed Google Play Application approvals, the API documentation I have been referencing is here:
https://learn.microsoft.com/en-us/graph/api/intune-androidforwork-androidmanagedstoreaccountenterprisesettings-approveapps?view=graph-rest-beta
Requirements for approveApps is almost identical to syncApps:
https://learn.microsoft.com/en-us/graph/api/intune-androidforwork-androidmanagedstoreaccountenterprisesettings-syncapps?view=graph-rest-beta
I can make the call to syncApps successfully but approveApps returns BadRequest. The only difference between the calls appears to be the body requirements.
It needs packageIds as a String collection and approveAllPermissions as a Boolean.
Please help me to successfully make a post to https://graph.microsoft.com/beta/deviceManagement/androidManagedStoreAccountEnterpriseSettings/approveApps
Minimum Reproducible Code:
var authHeader = {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json"
};
var appApprovePostData = JSON.stringify({
packageIds: ["com.bundle.example"],
approveAllPermissions: true
});
var appApproveOptions = {
method: "POST",
uri:
"https://graph.microsoft.com/beta/deviceManagement/androidManagedStoreAccountEnterpriseSettings/approveApps",
headers: authHeader,
body: appApprovePostData
};
response = await request(appApproveOptions);
The application needs to be prefaced with "app:". So, in your example, you need
var appApprovePostData = JSON.stringify({
packageIds: ["app:com.bundle.example"],
approveAllPermissions: true
Couple of thoughts -
If you get back a RequestID, can you post that?
Can you compare the request body submitted by the Azure Portal (F12 developer mode to get the request body trace) for the same app approval with your request body generated from code?
Dave

How to create SendBird user with SendBird Platform API and Request node library

We are building a react-native chat app. We are implementing a back end authentication solution on google Firebase. The creation of a new user in Firebase Auth triggers a cloud function which should create a new SendBird user with an access token. The access token will be stored in Cloud Firestore, ready for retrieval the next time the user logs in.
We are having trouble implementing the POST request that creates the new user via the platform API. We are using the Request library for node.js. We are able to reach the API endpoint, but the following object is returned: { message: 'SendBird API Endpoint.', error: true }. There is no indication of what the error may be.
This happens when sending the request to the base url. When we send the request to /users or /v3/users, we receive a 403 error.
Any indication as to what may be causing this problem would be greatly appreciated.
Below is the cloud function index.js code
const functions = require('firebase-functions');
const admin = require("firebase-admin");
const request = require('request');
admin.initializeApp();
exports.handleNewUser = functions.auth.user().onCreate((user) => {
var newUserRequestBody = {
"user_id": user.email,
"nickname": user.email,
"profile_url": "",
"issue_access_token": true,
}
request.post({
headers: {
'Content-Type': 'application/json, charset=utf8',
'Api-Token': // API Token
},
url: 'https://api-{application_id}.sendbird.com',
form: newUserRequestBody
}, function(error, response, body){
if (!error && response.statusCode === 200) {
const info = JSON.parse(body);
console.log("request successful");
console.log(response.statusCode);
console.log(info);
}
else{
console.log("request unsuccessful");
console.log(response.statusCode);
console.log(error);
}
});
return null;
});
Did you try with full path of end point to url: (including /v3/users)?
Or you may need to use "baseUrl" like below?
https://github.com/request/request#requestoptions-callback
Also, you need to make sure that you correctly used {application_id} value and {API Token} value.
You can double check this from your dashboard of SendBird.
http://dashboard.sendbird.com > Log in with your ID > select your APP.
There is a section named "App credentials" in "Overview" menu.
You can double check your API-request URL and API-Token value from there.

find all requests in which user is participant in the service desk

In JIRA, how to get the all issues which user is participant?
I can get the results for assignee and reporter.
I am using following query to get the issues when the user is reporter.
reporter = user AND updated > -10d
I need to display the issues only the user is participant not the reporter or assignee. How to achieve this in the search API?
If you prefer to use the Jira's search API, given that you're looking for issues that the user is a participant of, try adding this in your JQL "Request participants" in (currentUser()).
Since you're concerned with Jira Service Desk (JSD), you might want to try the following JSD specific REST APIs depending on which deployment you're working with:
Server: Get my customer requests then pass requestOwnership query parameter with the value of PARTICIPATED_REQUESTS.
Cloud: Get customer requests then pass requestOwnership query parameter with the value of PARTICIPATED_REQUESTS.
EDIT: (added code snippet)
app.get('/getMyRequests', addon.checkValidToken(), function(req, res) {
var httpClient = addon.httpClient(req).asUserByAccountId("myAccountId");
httpClient.get({
url: '/rest/servicedeskapi/request',
headers: {
'X-Atlassian-Token': 'nocheck',
'Content-Type': 'application/json'
}
},
function (err, httpResponse, body) {
if (err) {
return console.error('failed:', err);
}
console.log('successful:', body);
});});

How to make a request to a website, which has user authentication, to access its contents?

I am working on an IOS app as my college project. Basically my college has a website which has login form[no sign up forms there], and students using their unique college ID and their own password can login into this website and access things like courses they have registered for, their grades etc. Now in my app i have a log in form and i want the students to be able to login with the same existing ID and password and access the same information as they would be able to do on the website itself. Simply speaking, i want to access the post authentication information on the website in my app. How do i approach this problem?
It depends if your school server allows request from different origins (different domain). If, yes just check when you login what info it posts and to which address. Then send a request to this address with the same info and check the result from the request.
Example:
Just use chrome or firefox dev inspector, fill the login form, send it and check the request done.
Let say the request done is a POST # http://myschool.com/login with username and password form, and the result if successful is a 200 code and a cookie. Then in node js you could do:
const querystring = require('querystring');
const request = require('request');
const form = {
username: 'usr',
password: 'pwd',
};
const formData = querystring.stringify(form);
const contentLength = formData.length;
request(
{
headers: {
'Content-Length': contentLength,
'Content-Type': 'application/x-www-form-urlencoded'
},
uri: 'http://myschool.com/login',
body: formData,
method: 'POST'
},
function (err, res, body) {
// check the result here
}
);

Slack slash command response_type ephemeral are sent to the entire channel

Ephemeral messages are supposed to be only visible to the user that issued the command. However, in my experience, it's sent to the entire channel.
Am I missing anything?
According to Slack Slash commands documentation, the only attribute needed is to set response_type to ephemeral in the response of Node.js app.
The code in my app looks like this:
var t = {
"response_type": "ephemeral",
"text": "How to use /please"
}
request({
uri: uri,
headers: {
'content-type': 'application/json',
},
method: 'POST',
body: JSON.stringify(t)
}, function (error, response, body) {
return res.status(200).end();
});
Ephemeral messages are only supported in slash commands currently. From your screen capture it looks like you're sending your payload to an incoming webhook. Unfortunately, I can't find the wiki that backs this up, but here's another post with a similar answer: Slack API "attachments" not showing

Resources