Consider two users A and B. I'm trying to make a bot that can send a message to user A on behalf of user B, not in the app channel, but in the personal IM channel between A and B. Once the message is sent, it should look like it was sent by user B only. Is there a way to make this happen?
I scoured the documentation, and here's what I tried:
chat.postMessage - This worked well, but the only issue is that when user B tells the bot to send a message to user A, user A gets this message in the app channel, not in the DM of user B.
chat.postMessage with user details - I passed in the username and icon_url of user B in chat.postMessage, so it would look like the user B sent the message. It kind of worked, but not really. User A gets the message in the default 'slackbot' channel. And in the message, although it showed user B's name and image, the "App" tag that's there for bots remained.
So is it actually possible to let a bot send a DM as user B and make it seem exactly like a normal DM to user A by user B? If not, (in the second case I tried) is it at least possible to receive the message in the IM channel between user A and B, rather than slackbot?
The documentation suggested using conversations.open to get the user ID, and then to pass this user ID in chat.postMessage. I tried this as well, but conversations.open gave me an error saying
Error: An API error occurred: user_not_found
The only way to send a message in the DM between User A and User B is to acquire the user token of either User A or B (depending on who you want the message to come from) and use that token to send the message.
It isn't possible to mimic a user and have it appear within the DM between two users.