I'm trying to find a way to send events to a hubot running on Slack from, say, a python script. I've looked at the Events API documentation, but it only talks about how to receive information on events from Slack. Is there any way to emit an event to slack through the API?
No, you can only receive events from Slack with the Events API. But they are many other ways to interact with the Slack using the normal Slack API, e.g. sending messages to a channel.
Related
I currently have Twilio Flex set up but need to intercept all incoming messages in order to send slack notifications to reps, if they're offline and need to respond.
Is there a way to intercept (using a webhook) only Incoming messages so that I can send those slack notifications.
Twilio developer evangelist here.
If you go into your Flex project to the Studio dashboard you will find three flows, including the Messaging Flow. Incoming messages are directed to this Flow.
If you open the Messaging Flow you will see that by default it sends the message straight to Flex.
You can add a widget in here to invoke a Twilio Function before sending the message onto Flex. Twilio Functions allow you to write Node.js to perform custom tasks, like sending a Slack notification.
I am working on a Chatbot for Slack with DialogFlow. I have put a message menu in Slack. I want to send the selected value to DialogFlow as an intent. It does not work.
Does DialogFlow supports message menus or Do I have to setup a webhook myself?
Thanks.
As #praveen suggested you will need to enable Fulfilment in DialogFlow settings for the project and point it to your fulfilment back-end service. After you have done that check Rich Messages Doc to see what data payload to respond with to DialogFlow from your Fulfilment service to make Slack display a menu.
UPDATE
If you want to perform an action in Slack and enable Slack notify you of that action then you can either user Slack RTM or Slack's event API
I am trying to figure out how to send a direct message to a bot in slack using the Slack API and get the response by the bot. For example, I use chat.postMessage:
curl -X POST -d
'token=xoxp-xxxx-xxxxxxxxx-xxxx&channel=BOT_ID&text=where?&as_user=true'
https://slack.com/api/chat.postMessage
The bot respond with:
I'm at hubot-server1.localI'm at hubot-server2.local
I want to capture the response. What Slack API I can use to capture? chat.postMessage doesn't return it.
Thanks for any reply.
Regards...
There are no API methods that will directly return a response from a bot. To capture responses of bots (and users) you need to read the messages from a channel.
With the Web API you can do that by calling channels.history for public channels (or groups.history private channels and similar names methods for other conversation types. you can also use the new conversations.history method to access all types of channels).
Those methods will give you all messages of a channel and you will need to filter out the right message within your app.
You can also get all new messages for a channel with the RTM API and the Events API.
I have read about the outbound webhook and Event api. And i am able to install a bot to a team using slack button. outbound webhook dosent fit in my scenario i think.
So how can i can get all events(specially whenever this bot receive a msg) using the event api to my webhook.?
Any direction or right way to solve this problem ..?
Outgoing Webhook and Event API are two completely unrelated functions. So you can not get event notifications through an outgoing webhook.
To get event notification your Slack App need to
request the correct oath scopes
subscribe to the events you want to get in the Slack App config
have a script ready to receive the event requests from Slack
Your script will then be called every time the subscribed event occurs.
For all details please have a look at the excellent official documentation about the Event API.
i am working on a slack app (scope including bot and incoming webhooks). I can send message to a defined channel but i don't know how to stop using the "&channel=" parameter and just send messages to listening channels. By listening i mean, when the app is installed, user is asked where to post (channel or dm has to be chosen).
String postUrl = "https://slack.com/api/chat.postMessage?token=" + botAccessToken + "&as_user=false&channel=%23community&text=testing&username=CommunityQ";
Any hints would be useful.
I think you can't: According to the official Slack API documentation it is not possible to send messages to all/multiple listening channels:
Incoming webhooks output to a default channel and can only send
messages to a single channel at a time. You can override a custom
integration's configured channel by specifying the channel field in
your JSON payload.
I interpret this as "there is always exactly one channel your message is sent to"
Furthermore, Slack restricts this channel override feature for Slack apps:
You cannot override the default username, icon, or channel for
incoming webhooks attached to Slack apps.
I think there is a slight confusion here. I am not sure what the "incoming webhook" scope does that the "bot" scope cannot do. Here's how I see things
Either you want a lightweight, low-permission app that posts in one channel, and you'd use the incoming webhook scope
Or you want an app that can ask questions to the users, like which channels they'd like to have updated posted to, process answers, etc. Then you'd use the bot scope, and the bot can post in any public channel
If you give a bit more details in what you want to achieve we can perhaps help you better
If you want a more dynamic approach on sending messages into any channel I would suggest to user the API method chat.postMessage instead of an incoming webhook.
The API method can post messages into any channel (including private channels, DMs) as long as your token as access to it.
As Michael mentioned in his answer, it is not possible to post to multiple channels at the same time. You have to look through them and do multiple requests.