My request URL is not receiving any events for the Slack Events API. What am I missing? - slack-api

I want to subscribe to Slack Events API for any message posted in a slack channel. These are the following steps I took as given in Slack Event API documentations.
I created a slack app with following permission scopes :
channels:history, groups:history, im:history, mpim:history
In Event Subscriptions, I enabled events, verified Request URL ( "https://api.example.com/slack/event/push") successfully, and subscribed to the following Team Events :
channel_history_changed, group_history_changed, message.channels, message.groups, message.im, message.mpim
I made the user go through oauth authorization to install the app. The url is shown below with scope and redirect uri. (PHP Code)
$url = "https://slack.com/oauth/authorize/?client_id=" . SLACK_CLIENT_ID .
"&scope=users.profile:read,users:read,groups:history,channels:history,im:history,mpim:history" .
"&redirect_uri=" . urlencode('https://api.example.com/slack/oauth/callback') .
"&state=XXXXXXXXX";
I receive a code from slack which I exchange for access token.
Access Token: xoxp-XXXXXXXXX-XXXXXXXXX-XXXXXXX-XXXXXXXXXXXXXXXXXXXX
Scope: identify,channels:history,groups:history,im:history,mpim:history,users:read,users.profile:read
Team Id: XXXXXXXX
I checked the apps and integration of the team to see if the app was installed and yes it is in the list of Apps.
Now as per my understanding when any message is posted in any channel of the team, a POST request should be made to my verified URL ( "https://api.example.com/slack/event/push"). But I don't get any POST request there.
I thought maybe the URL is broken but I tested it with a counter and every time the URL is hit it increments the counter. So the URL is fine.
Is there a step I missed somewhere? I don't know what to try next.

I contacted Slack support and they were very helpful. The logs at slack showed that Slack was actually sending POST requests to my Request url. So my setup worked fine. But my API framework was failing to parse the request body and hence sending internal server error (500) to Slack. We figured this out by using requestb.in.
All I had to do was change the way I parsed request body.

Having the channel be public is VERY important!

Related

Using send API of gupshup to reply to a user within 24 hrs shows an User not opted-in error

I have my own bot running locally and have made it publicly accessible using ngrok
Trying to use the sandbox environment of gupshup to communicate with my bot.
Have hooked my bot using webhook (link your bot)
Have also created a BOT and configured the webhook as a callback POST to my ngrok server.
However when i try replying to a user supplied whats app message after say about 10 min using the Delayed response strategy i.e. by passing the contextobj and message via the send API (http://api.gupshup.io/sm/api/bot/{botname}/msg), I get an error stating "User Not Opted In".
Why isnt the user considered as an Active User since the messaging was initiated by the user and the send API is only replying to that message with 24 hrs ?
How do i simply give a delayed response to the user within 24hrs without forcing the user to opt-in ?
We do this all the time, however we are using the endpoint documented here:
https://www.gupshup.io/developer/docs/bot-platform/guide/whatsapp-api-documentation#OutboundMessage
You have to take the consent of user once before sending messages.
Also while using sandbox the user needs to opt in but for verified user it will be relaxed.
But still you will need to take consent of user at any place (your site, your terms and conditions or anywhere) before sending him anything for the record purposes so that they cannot claim that you are spamming them without consent.

Sign In With Slack - Invalid scopes: identity.basic, identity.avatar

I've set up my slack app to be installed using Oauth2.0 successfully calling
https://slack.com/oauth/v2/authorize?client_id=<myAppsClientId>&scope=chat:write,commands,incoming-webhook,users:read&user_scope=chat:write,users:read
but when i try to use Sign In With Slack (So user can manage their slack on my web app) I use
https://slack.com/oauth/v2/authorize?scope=identity.basic,identity.avatar&client_id=<myAppsClientId>
The user gets the error on the slack url (before being redirected to my app):
Error details
Invalid permissions requested
Invalid scopes: identity.basic, identity.avatar
Since the add to slack and sign in with slack both call the same uri, im assuming the scope params are what separate the two. Not sure where Im going wrong because I followed the docs and used the button they generated for me.
I don't know that this is the correct fix, but I encountered the same issue and I was able to get it working by renaming the 'scope' parameter to 'user_scope'
Ok I actually was able to get it to work by NOT using v2 for Sign In With Slack. But I HAD to use v2 for Add to Slack.
So using /oauth/v2/authorize and /api/oauth.v2.access for add to slack
and /oauth/authorize and /api/oauth.access for signin with slack
I don't think it should work like this but it's the only combo that's working.

Do WooCommerce Webhooks send X-WC-Webhook-Signature header on save?

I'm trying to add a WooCommerce Webhook to hit an endpoint on my Ruby on Rails API. I can see in the logs that it is hitting the endpoint when I save the Webhook in the WP dashboard, but when I inspect said request I don't see the X-WC-Webhook-Signature header included with the other headers.
Does this header not get sent when it does the trial ping on save, and only when it is actually triggered by the Webhook's topic?
WooCommerce does not send the X-WC-Webhook-Signature header when the webhook is saved (see links below, courtesy of Kaperto).
deliver_ping is called when a webhook is saved)
and
deliver is called when the webhook is actually triggered)

Account linking with actions on google

I am facing an issue regarding account linking in Actions on Google:
I am able to authenticate the user and access his email address and username however after this how can I redirect the user back to the google assistant and close the browser where he was authenticated?
Any help will be appreciated!
Update: Hey Prisoner thanks a lot for that.
I did what you said and yeah now it does redirect to google.com but without result_code=SUCCESS when I test it in the simulator.
The link is:
https://www.google.co.in/?gws_rd=cr&dcr=0&ei=z77fWbjQGIXxvATs_oqwBA
Now if I type talk to... again it shows me the message you need to link your account!
In the device the browser automatically closes and it shows SIGNING_IN however when I type an intent it is not recognized.
It would be great if you could point me in the right direction! (I am not sure but I might be at the token exchange stage that you mentioned, but I don't have a clue how to proceed!)
Update 2: As requested the entire flow that I am following:
This is the URL that I receive from debugInfo:
https://assistant.google.com/services/auth/handoffs/auth/start?account_name=cha***#gmail.com&provider=***_dev&scopes=email&return_url=https://www.google.com/
When I paste this in the browser the request that I receive at the authorization endpoint is:
ImmutableMultiDict([
('response_type', 'code'),
('client_id', ****.apps.googleusercontent.com'),
('redirect_uri', 'https://oauth-redirect.googleusercontent.com/r/****'),
('scope', 'email'),
('state', ' CtcCQUxWM2ROU3hNMjl4LUItVXhQSGd4THRMLU4yNExnb3lYbGRKQnQwa3NwTVFva19NUWpYNE5jNGJURzIyZFN3RDBXd2d4enFGVWJGb0Q0ZW1vaS1OaFdkaHdhb05HZ2xlWTR6SllKVlRWYktwd09faklyUTVheFhQbGw2dmVKYzVFTk05N3B1QkxaZG41RVdHN0wyTktvRFdCYzFPVFBzM1dQUlFtN2RmM1VtRU4****(state)')
])
The response (redirect_url) that I send back:
https://accounts.google.com/o/oauth2/v2/auth?scope=email&response_type=code&redirect_uri=https%3A%2F%2F******.herokuapp.com%2Fcallback%2Fgoogle&client_id=****.apps.googleusercontent.com
When it reaches my endpoint again the request arguments are:
ImmutableMultiDict([
('code', '4/***********')
])
Now I am able to access the email address and other details
The url that I redirect to from here:
https://oauth-redirect.googleusercontent.com/r/****?code=abcdefgh&state=CtcCQUxWM2ROU3hNMjl4LUItVXhQSGd4THRMLU4yNExnb3lYbGRKQnQwa3NwTVFva19NUWpYNE5jNGJURzIyZFN3RDBXd2d4enFGVWJGb0Q0ZW1vaS1OaFdkaHdhb05HZ2xlWTR6SllKVlRWYktwd09faklyUTVheFhQbGw2dmVKYzVFTk05N3B1QkxaZG41RVdHN0wyTktvRFdCYzFPVFBzM1dQUlFtN2RmM1VtRU4****(state)
This redirects me to :
https://www.google.co.in/?gws_rd=cr&dcr=0&ei=5c_fWdfKNYndvASO7o6ACA
Edit 3: I checked the network logs:
result_code=FAILURE&result_message=Account+linking+failed
I also added /token/google as the token URL in AoG. It is detected in heroku however I never receive this request in my code.
Note: I am using python flask and hosting my app on heroku
Once you have authenticated the user, you'll need to return a temporary auth code back to Google. Later, Google will exchange this auth code for an access token and a refresh token, but you're not there yet. The important part is that this code needs to be unique and that, later, you'll be able to recognize what user it is for. The code should be valid for a limited time - 10 minutes is a generally accepted time frame.
In the request Google sent to you as part of the login, they've provided a redirect_uri and a state as parameters. You'll need to use these in your reply. (state can be anything - you shouldn't care what it is, you're just going to send it back with your redirect. Its purpose is to improve security by preventing replay attacks.)
Verify that the redirect_uri has the form
https://oauth-redirect.googleusercontent.com/r/YOUR_PROJECT_ID
Where YOUR_PROJECT_ID is... you guessed it, the ID of your project. You can find this in the cloud console.
You'll then redirect the user to this URL with a few additional parameters:
https://oauth-redirect.googleusercontent.com/r/YOUR_PROJECT_ID?code=AUTHORIZATION_CODE&state=STATE_STRING
Where YOUR_PROJECT_ID is as noted above, AUTHORIZATION_CODE is the code you've generated, and STATE_STRING is the value of the state parameter that you were sent in the request.
For details, you can see https://developers.google.com/actions/identity/oauth2-code-flow#handle_user_sign-in

Facebook OpenGraph API: Can I Silently Send a Request from One User to Another?

How do I send a facebook app requests from one mobile user to another using the Graph API?
I have looked at facebooks documentation but the only options I have found are to A) send an app to user message from the app (which I can't get working) or B) to use the request dialog, which doesn't seem to let me send a request to a single user.
FB has instructions for how to build a custom "Multi-Friend Selector" but apparently not for mobile.
I have tried using HTTP POSTing to
https://graph.facebook.com/%s?access_token= ...
with POST data set to
message='Test Message'
but I get
WWW-Authenticate: OAuth "Facebook Platform" "invalid_request" "(#2) Failed to create any app request"
I have also tried in the Graph API Explorer but I get the same thing.
I don't want to send these messages to users that have installed the app and I don't mind the user having to provide confirmation for the FBFrictionlessRecipientCache. Also, my app is in Sandbox mode, but I only need to send the requests to the other developers.
I am looking for anything that will let me do multi-friend selectors or ask for lives, or get help from a friend, like I see in several mobile games these days.
You can use presentRequestsDialogModallyWithSession from FBWebDialogs.
You must specify a "to" parameter to identify the recipient, and you must use the FBFrictionlessRecipientCache.
The "to" parameter identifies the recipient. It stops the select user dialog from appearing.
The first time you send the request to each recipient the user will have to grant permission. After that, the FBFrictionlessRecipientCache will allow the request to be sent relatively silently (a dialog pops up briefly and goes away by itself).

Resources