slack incoming webhook - send message to another channel - webhooks

I am trying to post message to any channel in a slack team.
My webhook has been properly created and installed into my test team. As part of the install process, I selected "Post to #channel1"
When I review permissions, I see my app has been granted Other/Post to specific channels in Slack (#channel1).
From there, I am able to post into #channel1 with a basic JSON request:
{
"text":"Hello, World!"
}
Now I want to validate I can use same webhook to post to any other channel of the same team. So I created a channel #channel2 and I try the following request:
{
"channel":"#channel2",
"text":"Hello, World!"
}
The request is accepted (HTTP Status 200) but it still publishes on #channel1.
What am I doing wrong ? Is that a syntax or permission issue ? I guess it is more a permission issue but I have not found how to grant my app access to additional channels (or all channels).
Regards.

I created an incoming Webhook, and I found this documentation (see image)
I followed the instructions given in that, and I found that it worked. I can send a message to a different channel than the one the Incoming Webhook was set for

The app needs the chat:write:bot permission to post messages to other channels.
The permission can be added in Manage Apps → your app → OAuth & Permissions:
Reading Slack's own documentation, this was not obvious to me. (although it is mentioned under "Using the Web API" in the Intro to Messaging.)

Related

Slack bot posting in a conversation without being in it

Everything I see around slack bot say that a bot cannot post within a conversation it's not been invited to.
➡️ However, why /giphy or simple poll (/poll) can post in PM (one to one) OR in a conversation where the bot has not been added to?
The current permissions are chat:write,commands,files:write
The oauth token is a "Bot User OAuth Access Token"
The plan is to support the Add to slack and to distribute the app.
Functionality wise, it support a /command and post file to a conversation.
The bot can:
- receive the oauth token uppon app install (via add to slack)
- delete ephemeral messages
- post a file only where it's been added too, which suck because the bot does not need to read any message within anything.
Code of the bot here
If the bot is not invited too, the answer is either channel_not_found or not_in_channel.
What am I missing?
It is correct that bots in general can only post messages to channels they are invited to. However, there are two exceptions:
Bots can inherit the rights of the installing user. So bots can post to every private channel the installing user is a member of (including direct message channels).
Slash commands work differently. If a user issues a slash command from a channel the bot can reply to that slash command. That works for every channel and does not require the bot to be invited. Those replies are normal Slack messages, so the can contain all kind of message features incl. image attachments or blocks with images.
A common pattern to give bot full access to private channels is the following:
User starts the bot with a slash command
Bot checks if it has full access to the current channel
If not it asks the user to invite it to that channel

How to have app send message to Microsoft Teams via Graph API?

I want to be able to use the graph API to get a list of channels & teams, then have the app send an update to the appropriate channel without the user having to interact with MS Teams. Looking around I see a lot of posts saying this isn't possible yet, but Monday.com and Smartsheet seem to be doing this. Monday.com even specifies its using the beta api and neither are using connectors.
I attempted to do use the api POST /teams/{id}/channels/{id}/messages after authenticating via the way shown in this documentation
First Call for adminconsent
https://login.microsoftonline.com/organizations/v2.0/adminconsent?&client_id={botID}&response_type=code&redirect_uri=https://myoauthCallback&scope=offline_access User.ReadWrite.All Group.ReadWrite.All
After that returns I do an immediate call to get an access token, the above call doesn't seem to return anything I need to put into this request.
POST => /organizations/oauth2/v2.0/token
body = client_id={botId}&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default&client_secret={secret}&grant_type=client_credentials
I set the permissions in https://portal.azure.com/#blade/ for the bot to have the same scope as the first request above. Here it doesn't like the scope passed in the same way so I set it to default
I then take the access_token that is returned and attempt the call to POST a message to the channel.
URL: /teams/{TEAM_ID}/channels/{CHANNEL_ID}/messages
body: {
subject: 'test subj',
body: { contentType: 'text', content: 'Test message from app' },
}
This results in an error
statusCode: 401, code: 'UnknownError', message: ''
So how do I get the same functionality of these other apps so I can send a message directly to teams without setting up a connector?
Turns out it was a Office 365 Connector vs the regular "connector" that requires configuration within teams.
https://www.youtube.com/watch?v=EqodWkS5PYM
Edit: Disregard, even with office 365 connectors it requires the user to still interact with MS Teams in some way.
Another Edit: Turns out it is using Proactive Messaging https://learn.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bot-conversations/bots-conv-proactive#net-example-from-this-sample
Although technically you cannot actually send a message to the app without a user interacting with the bot first, the installation of the app does trigger a conversationUpdate to which you can reply. So In the end, I can install the Teams app, and send a bot notification all within my web app, without the user having to actually touch Microsoft Teams.
If you look at the "auth" page you linked to, it's talking about creating Application permissions. However, see the "create chatMessage in a channel" graph documentation and under "permissions" near the top it shows that it supports "Delegated" permissions only, so you can't use that particular endpoint with Application permissions unfortunately.
Connectors (Webhooks) will be able to do what you need, but you say you want to avoid that - perhaps you can explain why it's not ideal? I'm not aware of how to create a webhook programmatically, I'm afraid.

Slack Bot to see all Direct Message Channels

I am trying to implement a Bot which can get all the Direct Message Channels, all the workspace Users and send Direct Messages to them.
If I work with my development workspace everything works as expected but when I try with my company workspace, my Bot is only capable to retrieve the Direct Message Channel it is belonging to.
Any idea on how to fix by production Bot.
You can't. Due to the security architecture of Slack one can only see the messages of channels he is part of. Its the same even for the "super admin" of a Slack team (the primary owner). Bots and apps inherit that right from the user who installed it (= authed the access token).
The reason it works on your development Slack, is that your user has probably created all private channels on Slack, and/or is the same that authed the access token your app uses.
Thanks to Slack support I got my answer:
The OAuth Token issued is specific to the user who has installed your app and represents the permission(s) to perform actions on behalf of the user. More detailed information here - https://api.slack.com/docs/oauth.
The token can only perform the same actions as the user who installed the app i.e If the user can’t view or post in the channel, they can’t grant permission to something they do not have.

How to get conversation details in microsoft bot framework for skype?

I'm able to get conversation details for webchat using https://webchat.botframework.com/api/conversations/[conversationId]/messages
Service URL for skype channel is https://skype.botframework.com, but I dont find any documentation for getting conversation details
You can use the DirectLine Rest API (see docs).
The Direct Line API is a simple REST API for connecting directly to a single bot. This API is intended for developers writing their own client applications, web chat controls, mobile apps, or service-to-service applications that will talk to their bot.
Within the Direct Line API, you will find:
An authentication mechanism using standard secret/token patterns
The ability to send messages from your client to your bot via an HTTP POST message
The ability to receive messages by polling HTTP GET
A stable schema, even if your bot changes its protocol version
You need to enable the DirectLine channel for your bot on (see screenshot)
You don't have to access each specific channel endpoint separately, you can do it all (with some limitations) through the DirectLine API.
Start a New Conversation
POST /api/conversations
Get Messages in a Conversation
GET /api/conversations/{conversationId}/messages
Send a Message
POST /api/conversations/{conversationId}/messages
The full details are in the docs as linked above.
Hope this helps
Can you be more specific about conversation details and what you're looking for?
Generally, you shouldn't assume those URL's are static BTW; an incoming message from the Bot Framework will have a ServiceURL that should be used for the life of that conversation. Some services may have multiple ServiceUrl's that they give out for different users.

Can anyone post an example for event notification using docusign java-client sdk?

I want to implement event notification webhook method into my app. I am using docusign-java-client SDK for docusign, but I am unable to find any example using SDK. Can anyone provide some example to achieve this?
I'm sorry to report that we (DocuSign) don't yet have a Java recipe for this. We do have a Python example. Java is on the list of things to do. Perhaps someone else can provide an example in the meantime.
Here is a general description:
First, set up your webhook subscription. You can have an envelope-specific webhook subscription by including the eventNotification fields in your envelope create request.
Or you can set up a more general subscription by using the "Connect" feature. You can setup Connect subscriptions either via the DocuSign web tool, or programmatically.
As part of the subscription you provide your url for the incoming XML notification messages.
To handle them, you write a small web app using whatever web app framework is easiest for you and your stack. Your web server will receive the incoming https calls from DocuSign.
You can see what the incoming XML messages look like by using the beta Recipe Framework. Run it on Heroku. Use the embedded signing recipe and click the button to see the Webhook / Connect messages. You can then see the sorts of messages that you will receive.
Your incoming message web server will simply parse the XML messages and then handle them accordingly.
Thanks for using the webhook system. Please ask more questions here if you have any issues.

Resources