Post message to Slack channel as BOT not as APP - slack

I am building a slack app and I am using the chat.postMessage API to post the message to user. I also have a bot user for my app and I am using the bot token for posting the message. When I post the message the message is shown as posted from my app not from my bot means posted message has my App name as the user who posted this message and just next to it 'APP' is written so looks like the app has posted this message but what I want is as I am posting as BOT using the bot token 'BOT' should be written down as with the bots of other slack apps. How do I achieve this. Is there any other parameter I need to pass for doing this. For your information I am passing the value of as_user as default which is true. Please help in achieving the desired behavior.

Related

Bot Framework Composer Sending Direct Messages

I have a lot of questions about getting started. I currently have a sample bot I built in Composer that works for my teams/slack channels and works in the testing Bot Framework Emulator without issue.
I am not sure how to make the bot send a direct message/private message to a user in a channel instead of it replying directly in the channel itself. Any one have any ideas of how to accomplish this?
You can send messages from the bot to any user (or channel) by using the Azure Bot Service REST API (using the Send an HTTP Request action in Composer as described here. As you'll see in the documentation, the main limitation is that the recipient must have had a previous conversation with your bot from which you've recorded the conversationID (and activityID if you want to reply to a thread).

Sending a message to users as a bot in bot channel of Microsoft Teams using the Graph API

I have created a bot by following the steps mentioned in the doc.I have authenticated user using oauth 2.0 (auth code grant) as mentioned in the doc and in reverse I got a access token. But when I send message to channel in the teams using (/teams/{id}/channels/{id}/messages) API the message was sent on behalf of me. But I want my bot as the sender of message. Here is the image of the message that I have sent using the above API. and is there any way to send direct message to user as a bot?
Instead of using the Graph, there's another approach using the Bot Framework itself, to send a message to a team channel, a group chat, or a 1-1 conversation. The code doesn't even need to live inside the bot itself, it just needs to leverage the bot framework under the covers (for example, I have several Azure Functions that pro-actively message users). This idea is called "Proactive messaging" and you can read more about it in the docs here.
You do need to get certain fields when the user first installs the bot though, or any time the bot receives a message. I've described that more at Programmatically sending a message to a bot in Microsoft Teams. You haven't said what language you're using, but there are examples for a bunch of them - I can send you links if you let me know what you're using.

How to message a user in a slack App via API?

When creating a slack app, it creates a new "channel" in the left hand menu. I want to be able to send a message to specific users and not to all users in a workspace who have integrated with the app.
For example, if I make the following request:
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/ABxxx/CDxxx/EFxxxxxx
It will send a message to all users who have integrated with my app with the text "Hello World".
But I only want to send a message to user A without User B being notified.
I don't want to message a user directly and it to appear to come from slack bot. I want the message to appear to come from my bot / app.
How can this be achieved via slack API?
I found this quite hard to explain so please let me know if you'd like me to clarify anything.
The problem of your request that you are using a hook URL which is bound to a particular channel (you pick it during Slack App installation).
To send a direct message to the user on behalf of your bot, you need to consider the following things (this is not the single way to achieve it, but works for me):
Ensure you have a bot registered for your Slack App.
Ask for bot and chat:write:bot permissions during App installation process (example for Slack Install button and here).
Store the bot access token on successful installation (see for details).
Now using the bot access token you can send Slack API requests.
To achieve what you need, use chat.postMessage API method. channel argument can be user ID (e.g. U0G9QF9C6). By setting up as_user argument to true, your message will be always sent on behalf (name and icon) of your bot (seems for bot tokens it's always like this, but it's recommend it to specify it explicitly).
Hope it helps. Feel free to ask for details.

Sending messages to my bot via Slack gets no response

I have a bot deployed to our Azure subscription. Using the webchat channel, I can interact with the bot using the url:
http://mybotname.azurewebsites.net/
We have added the bot to Slack as an app. We followed all the instructions given by the documentation on how to add a bot into Slack - https://learn.microsoft.com/en-us/azure/bot-service/bot-service-channel-connect-slack?view=azure-bot-service-3.0
When I send a message to the bot in the Slack channel we have created, I get no response. There is not error message, or in fact anything, returned.
Whereabouts can I start looking to see what the problem could be? Suggestions for error logs, traces, etc would be appreciated. I enabled App insights for the Azure Web App which the bot runs under, but nothing comes up as an error, or warning, or anything. I'm a bit lost here, any suggestions would be appreciated.
Note that I was made aware that, for Slack, I may need to tailor the responses in order for Slack to render them e.g. FormFlow define options for string field
I'm not sure how to do that, or even if this is a case that my bot simply isn't working in Slack regardless of how I'd format the responses.

Slack bot getting information from threads and messages?

Slack bots can get information about messages that have just been posted with the "messages" event. So why can't they get information about all the messages in a thread?
So for example when someone makes a reply to a message in a thread a message event is fired with the subtype of "message_replied" however the text fields of all of the messages in the result are out of scope for the bot.
Is there a way to access this information? I have tried using things like channels.replies and conversations.replies but the results of those are out of scope for the bot too. Requiring the channels:history scope.
I would settle for the bot being able to read the content of its own messages only.
You can access threads with your bot via API method conversations.replies (or the pendant methods) by using the user token from your Slack app. A Slack app with bot users always has both a user token (with rights inherited from the original installer) and a bot token.
As the documentation says in section Threading messages:
While Slack app-based bot users can't access these methods directly,
user tokens granted with the correlating scope can.

Resources