Inviting new user to private channel after inviting him by Slack API - api

I invited new user into slack team using slack API method users.admin.invite. I need to join him into some public and some private channels. Channels I gave as params in my inviting request, but with private channels I have trouble. It is not channels and it have another method to join user into it.
Method groups.invite need userId to join him.
Is it possible to add this user in the slack private channels (groups) using slack API?

The undocumented API method users.admin.invite has a channels property, where you can specify a list of IDs for the channels your want a new user to be automatically invited to.
This also works with private channels (I just tested it to confirm). All you need to do is to specify a private channel ID instead, which start with a G instead of a C.
You can use the API method groups.list to get the correct private channel ID. (private channels are called groups in the Slack API)
Example request:
https://slack.com/api/users.admin.invite?token=TOKEN&email=name#example.com&channels=G12345678
If you still getting errors using this approach than its most likely due to other issues, e.g. Slack does not recognize the email address or your access token does not have the admin right.
For more details please see the unofficial documentation of users.admin.invite on github, which I have updated accordingly.

Seems like this API endpoint isn't currently documented by Slack because it's still in development and could change in the future(which may be what you're running into now). Here's a link to a github issue talking more about it. https://github.com/slackhq/slack-api-docs/issues/30
I was able to find a github with documentation for the undocumented slack API endpoints, but those could have changed since they're not official https://github.com/ErikKalkoken/slackApiDoc/blob/master/users.admin.invite.md
From these unofficial API documentation it seems like you'll have to pass in the channelID instead of the channel name. To get channel IDs you'll just need to call the channels.list end point

Related

How to send Trustpilot invitations through Trustpilot API?

In our app we are using this API call to retrieve our average rating score and display it on our website:
https://api.trustpilot.com/v1/business-units/{{BUSINESS_UNIT_ID}}/?apikey={{API_KEY}}
This works great.
Now if we want to send an invitation to rate our services to one of our customers, we use a very similar API call:
https://invitations-api.trustpilot.com/v1/private/business-units/{{BUSINESS_UNIT_ID}}/invitations?apikey={{API_KEY}}
Unfortunately, this doesn't work. We are getting this error:
{"fault":{"faultstring":"Invalid access token","detail":{"errorcode":"oauth.v2.InvalidAccessToken"}}}
What are we missing here?
We can't see why our API key works for the first call, but not for the second.
Thanks for any help.
In the first API call you are calling a public endpoint. For all public endpoints API key is enough because you are not accessing restricted data.
For your second API call (the invitations one), you are calling a private endpoint.
For all private APIs you need to authenticate yourself using the OAuth2 flow and include the access token in your request.
You can read more about the flow at:
https://developers.trustpilot.com/authentication

Identify unique user in Dialogflow V1

So I am testing out Dialogflow and one of the first questions I have is: how does my bot know who it is talking to? I need to identify a user and keep that information for as long as I can. The basic scenario being:
User starts his/her first conversation.
Chatbot send a fulfillment request to the server trying to match a user within its own database.
The user is found, the information (as a JWT or some other token) is sent back to Dialogflow and stored there for further communication. In reality, this part would involve asking for user email, sending a verification code to that email and then verifying the user with the code.
User then starts chatting with a bot and all fulfillment requests get the unique token stored for this very user, so that my REST API knows which user is being served with the response.
Couldn't find anything about it in the docs (maybe I am looking in the wrong places).
There will be several integrations, like Messenger, Viber, Telegram. I dunno, maybe those APIs add some unique information on the user?...
Thanks for the help!
Sorry, I know it's been a while, but maybe this will help someone else.
The right solution here is a user id, not a session id. A user id is provided by the chat platform (Facebook, Slack etc) and is consistent across sessions for the same user.
To get the user id, go to the Fulfillment tab, enable the editor and use a function like so:
let r = request.body.originalDetectIntentRequest
//this makes sure that you're on an integration
if (r["source"]){
return r.payload.data.sender.id;
}
To tie together ids from different platforms, you probably have to have some kind of log-in process every time you encounter a new id on a platform.
Pop,
Sessions are built in already into DialogFlow requests to your fulfilment service, if you check the payload you will find a sessionId, it remains the same for the same client until it expires.
However if you want to identify the user from any of the clients that you can connect to DialogFlow like Messenger then from the same request payload to you you will notice that there is an object named originalRequest that is only available when requests are coming from those clients.
You can personalize those users response eg using their FB firstname in a message to them.

How to get user subscriptions with twitch api v5?

I found
how to do this, but only for api v3.
There is no such functionality for v5?
They are all still available.
Get Channel Subscribers
Check Channel Subscription by User
Check User Subscription by Channel
There's a list of all the major changes on the overview page, so you can just look there to see if any endpoints have been removed.
The new version of the API uses user IDs instead of user names to reference users.
The _links object was removed from all responses. Developers are now responsible for handling the paging offsets when polling the API.
Sub-second precision was added to time fields
The /games/featured endpoint was removed.
delay, background, and banner were removed from the channels response object.
For search endpoints, the q parameter is now called query, and the type parameter is always set to suggest.
The paywalled field was removed from the video response object.
The /kraken/chat endpoint was removed.
For reference, v3 is still available for use until Feb 13, 2018.

Google GMail callback when someone reply to thread

I'm using Google GMail Api. All works fine with synchronous requests. However I would like to get notified when someone reply to given thread_id to a callback somehow.
I found this article https://developers.google.com/gmail/api/guides/push?hl=pl about push notifications and it's great but still I don't know how to setup Observer I have described above.
I'm using PHP btw, but I just need concept how it works and how I can setup that kind of communication between API and app.
There is currently no available API that detects/observes (something that behaves like a callback) if there is a reply for a specific thread_id.
You'll have to do the checking yourself, doing some polling (with users.threads.get) to see if there is a reply. Similar to what the OP was doing in this post (emphasis mine):
We have a web application that makes use of the Gmail API to automate certain emails on our users' behalf. When the application sends an email, it stores the threadId returned by the Gmail API. It then uses this threadId to poll the Gmail users.threads.get API, looking for replies. When a reply is detected, it pauses future emails.
You can use the Push notifications provided by Gmail API. The document is available here:
https://developers.google.com/gmail/api/guides/push?hl=pl#python
It's pretty much straight forward. Create a topic, then create a push subscription for the topic. It requires a webhook pointing to your web app. Grant necessary permission to the Gmail service account as mentioned in the document.
Use the below Python code to get notified:
request = {
'labelIds': ['INBOX'],
'topicName': 'projects/myproject/topics/mytopic'
}
gmail.users().watch(userId='me', body=request).execute()
We get a response with HistoryId. Tracking all the messages since the HistoryId can be done like this:
history = (service.users().history().list(userId=user_id, startHistoryId=start_history_id)
I found the below video helpful:
https://www.youtube.com/watch?v=wjHp9_NAEJo

Can a slackbot pull messages from a private channel and post in another slack channel?

I am wondering if a slack bot can pull messages that are tagged with a certain string of characters from a private channel and then post that "tagged" message in another channel (private or public). All within the same slack group.
Yes, a Slack bot can do that. But he needs to be invited to a channel (public and private) to be able to monitor it. He then receives all messages in that channel and can react to it in any way you want. Bots can only use a subset of all Slack API methods, but yes they can post a copy of a message to another channel based on keywords.
See the Slack documentation on bots for more information.
Also try setting up a webhook from that slack channel, I've had success with that