Post Slack message as specific user - slack-api

I'm building a Slack bot with slash commands and I would like to post a message with an attachment as a specific user (specifically, the user that called the slash command).
I know this is possible because the Giphy Slack integration does so when responding to the /giphy [image] command, by responding as the user with a gif image.
I tried using the chat.meMessage method but this does not appear to support attachments.
I tried using the as_user argument in the chat.postMessage method, but this inherits the authenticated user rather than the user that called the slash command.
Responding to the slash command immediately or performing a delayed response (using response_url) doesn't seem to support non-bot responses. If they do, I can't seem to find where it's documented.
In the slash request Slack does provide both user_id and user_name parameters, so I imagine I can make use of those.

I reached out to Slack with this question, and unfortunately at this time it doesn't look like what I'm asking for is possible. The Giphy Slack integration was internally built.
Maybe in the future!

Related

How to forward an email and change the subject using the Microsoft Graph api

recently I ran into a problem where I was using python imap to automate outlook tasks, but microsft changed basic auth to Oauth now, and I have not being able to authenticate ever since, I get an error
imaplib.error: AUTHENTICATE failed.
So I started working with the Microsoft graph API, in which I can get the information that I need but once I need to forward an email I can't setup a custom subject, I can just add a comment and toRecepient custom arguments.
https://learn.microsoft.com/en-us/graph/api/message-forward?view=graph-rest-1.0&tabs=http
any advice here ?
If you use the Create-Forward endpoint https://learn.microsoft.com/en-us/graph/api/message-createforward that will create a draft message of the forward which you can then patch any message property you want to update and then send.
The one thing they don't mention in the documentation is you should set the Prefer: outlook.timezone header to make sure the dates in you response are set the local time of the responder.

Asana Webhooks API

So I have implemented the Asana Webhooks API as described in their documents. I can pass it a project ID and request a new webhook be created. The API successfully sends a authentication request to my application which returns the Security header as described in the Docs. Asana then returns the expected success response, outlining the newly created Webhooks unique ID.
Now if i take this ID and then query the Asana API to show me all configured webhook's on either the parent Workspace or the project resource directly it returns an empty data JSON Object or reports the resource doesn't exist, suggesting the Webhook Ive just created wasn't actually created, despite giving me the expected success response.
Also If I then make a change to a project it doesn't fire the webhook and I don't receive any events on my application.
Strangely everything was working on Friday but today (Monday) I'm experiencing these issues.
Any pointers would be good, Ive been working as the Docs suggest in terms of my request structure and am authenticating using a PAT, Ive even tried a newly created token.
Thanks,
Our webhooks use the handshake mechanism to make sure that it's possible to call you back, but there's always the possibility that subsequent requests can fail. Additionally (although we don't document this very well - there's an opportunity for us) we should immediately try to deliver a (probably) empty event after the handshake (it looks like {"events":[]}. This is kind of like a "second callback" that contains anything that has changed since you created the webhook.
If this fails - or if any subsequent request fails often enough - the webhook will get trashed. "Failure" in this context means returns HTTP response codes other that 200 or 204.
As for why you're having trouble querying the webhook itself, I wasn't able to repro the issue, so we'd have to dive deeper. It should be fine if you:
Specify the workspace
Optionally specify the resource
I tested this out, and it seemed fine. You also might want to directly query the webhook by id with the /webhooks/:id endpoint - note to use the id of the webhook returned by create, and not the id in the resource field.
If you created the webhook (specifically, your PAT or OAuth app was the one making the create request) you should see the information just fine. If you can get the webhook by id, you should see last_failure_at and last_failure_content fields which would tell you why the webhook was unable to make the delivery.
Finally, if you would like to contact us at api-support#asana.com and let them know more details (for instance, the ID of the webhook you're trying to look at) we can look at those fields from our side to see if we can identify what's going on.

How can I trigger a slash command in Slack every day at a certain time

I want to trigger a slash command in Slack every day at a certain time. Specifically, I want to clear my status every night at midnight.
From the documentation it seems like the only way to do this would be via an Incoming Webhook. However POSTing with the following JSON body just creates a message in Slack /status clear and does not actually run the command.
'{"text":"/status clear"}'
It also posts the message on behalf of the app associated with the webhook, not under my username.
Is there any way to invoke a slash command for my user from outside the official Slack app?
Here is how to execute slash command for your user with an external script.
Use the undocumented API method chat.command execute any slash command, e.g. /status
Use an access token linked to your user account for the API call. One way to get that is to create a so-called "legacy token" with your user.

creating a slack command without slash

There is this API with response of operator-city string.
https://nbhyb3s7db.execute-api.us-east-1.amazonaws.com/v1?mnumber=9819838466
I can check that it is working as expected. But when I create a command for this in slack, it does not work. It tries to visit the following URL that has extra slash / in it.
https://nbhyb3s7db.execute-api.us-east-1.amazonaws.com/v1?/mnumber=9819838466
How do I create a command without slash?
Update:
As per the docs, (Invoke external services with slash commands) response_type and text are the two essential keys those should be there in the reponse.
https://api.slack.com/custom-integrations
Is this correct or I am missing something?
You can easily build a test script that simulates slash commands from Slack. All you need is to send a HTTP POST request to your service with the correct parameters. A simple HTML page with a form will do the trick. Or you can use a more sophisticated PHP script, that will also be able to interpret the and output the result of your service in a nice way (that is what I am doing to test my services).
Here is an example from the documentation how the POST request needs to look like:
token=gIkuvaNzQIHg97ATvDxqgjtO
team_id=T0001
team_domain=example
channel_id=C2147483705
channel_name=test
user_id=U2147483697
user_name=Steve
command=/weather
text=94070
response_url=https://hooks.slack.com/commands/1234/5678

How can my slack custom command produce /remind me like links

I am writting a custom slack command that implements a
task manager like interface (I know ... there are many out there :-), mine interfaces with odesk/upwork to outsource my micro-tasks :-) ) .
Anyway, I like a lot how the /remind command included Complete Delete etc links in its output to facilitate subsequent interactions with the user that entered the command and I am trying to figure out how to do the same trick.
What I have thought so far is to include links in my output that are ... GET /slack-link?method=POST&token=xxx&team_id=xx&command=.. ie carry in their query string the complete json payload that slack would have produced from a normal custom command. slack-link acts as a "proxy" whose sole role is to submit a POST back to my normal slack endpoint. I can even reuse the same response_url for these command-links.
I have not tried it but I think these URLs will just open another window so that path wont exactly work...
Has anybody tried something like that before?
As you've learned, those are currently only available to built-in commands. However, as I was curious and wanted to know how those are done, I looked in the API and found out that the URLs are just formatted normally but have a special "protocol":
You asked me to remind you to “test”.
​_<slack-action://BSLACKBOT/reminders/complete/D01234567/1234//0/0/5678|Mark as complete>
or remind me later: <slack-action://BSLACKBOT/reminders/snooze/D01234567/1234//0/0/5678/15|15 mins> [...]
Clicking on such a link results in an API request to method chat.action, with the following parameters:
bot: BSLACKBOT
payload: reminders/complete/D01234567/1234//0/0/5678
token: xoxs-tokenhere-nowayiampostingithere
So it looks like those URLs have three parts:
<slack-action://BSLACKBOT/reminders/complete/[...]|Mark as complete>
slack-action://: the "protocol" like prefix to let Slack know this is a chat action URL.
BSLACKBOT: the bot which (who?) will receive the payload. Can only be a bot user and the ID must start with B, or the API request will fail with invalid_bot.
the rest of the URL: the payload that gets passed to the bot. It doesn't look like this is parsed nor handled specially by Slack.
This is actually not a new feature, since they used to have API URLs back in late 2013 or early 2014 (I don't remember precisely) which they removed for "security reasons".
It could be interesting to see if we can use chat actions with custom bots, and if so, what we could do with it.
I got the answer from Slack support:
In regard to your original question: currently Slack doesn't provide
the ability to embed 'action' links in our custom integrations. Only
built-in features like /remind can utilize these at the moment. For
external services, you'll need to link to a URL that opens in an
external web browser.
We do hope to provide a similar function for custom integrations in
the future, allowing for interactive messages.
Thanks,
Ben

Resources