Slack API - remotely delete slash command message from channel - slack-api

I have a slash command set up in Slack to go look up some info and post a response message back to the channel. I would like the original slash command message that the user sent ("/whatever go get stuff") to be "replaced" by the response message, so effectively I want to delete the slash command message so the user only sees the response in the channel (similar to how /giphy command works).
My slash command works fine, but I can't figure out how to easily delete the message that triggered the command. I was looking into using the api/chat.delete endpoint, but I don't have enough info to form the POST data because the slash command request doesn't include ts.
Does anyone have an idea about how to get rid of that last message?

Related

How do I create an http request from Twilio Studio

I'm technical, but not experienced in coding and could use some help. I need to create an http request from Twilio studio. I am setting up a phone survey for my client and I need to log both voice and number inputs from the call to a database. I already have the database set up externally. It logs responses with an http request from CLI curl. I'm using the following curl request successfully:
curl --data "q=1 -X POST localhost/test.php
When I try to duplicate the same curl request using the http request widget (no http parameters), I only get error 500 back. By the way, I know it's collecting the data correctly with the flow because I've had it collect and then read back to me successfully.
Twilio studio http request.
I have tried adding http parameters instead of putting them in the body as well. Nothing I try works. My guess is that I have a fundamental misunderstanding of http requests and thus can't duplicate it in Twilio.
Any help you could give me would be great! Thank you!
When you add http parameters instead of putting them in the body (see the capture below)
there is a big red "Save" button on bottom left corner, and a gray (hard to see and easy to miss) "Save" link on the right, above the trash bin.
The gray "Save" link needs to be clicked when adding each name/value pair of the parameters.
The red "Save" button is to be clicked at the end when you're done with the http widget.

"Number to Contact" does not send message when edited

When I change the {{contact.channel.address}} number to a different number that I receive form REST Parameters the message will not send.
I am trying to take a POST request that then triggers the Twilio Studio to call a store and tell them they have a new online order. They then press Keys to indicate how long the order will take to process and then I send a message to the customer telling them when to pick up their order.
When I keep the {{contact.channel.address}} the same the code runs correctly but when I change this it doesn't work anymore.
Found this link that says it cannot be changed for outbound call but it is possible to edit for send message
Does anyone know can I do this or is this functionality not support at all?
curl -X POST "URL" -d "To=+1xxxxxxxxxx" -d "From=+1xxxxxxxxxx" -d "Parameters={\"orderid\":\"12345\", \"name\":\"Johen\", \"phone\":\"+1xxxxxxxxxx\"}" -u SID:AUTH
Studio Flow
The {{contact.channel.address}} should be equal to the To you pass in when calling the Studio REST Api URL. In your example, "To=+1xxxxxxxxxx".

Post Slack message as specific user

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!

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

Resources