'Get recipient of a DM message in Slack

I have a Slack App that listens to message events with the appropriate user and bot scopes (The app has im:read and im:history permissions among others, on behalf of the user). The event payload looks like this:

{"client_msg_id": "...", 
"type": "message", 
"text": "...", 
"user": "<sender id>", 
"ts": "...", 
"team": "...", 
"blocks": [...], 
"channel": "D012345678 <example direct channel id>", 
"event_ts": "...", 
"channel_type": "im"}

Is there a way to identify the recipient id of this message?

  1. I have looked into conversations_members API and used the channel_id provided by the event payload. It throws a channel_not_found error. I tried a hardcoded test with an actual private channel that the user of the app is in, and it returned the list of user-ids as expected. So it seems like the issue is related to DM channels.
  2. Tried to use the user-id instead of the channel id as this comment suggested. Didn't work either.

Any help is appreciated.

Additional info:

pip freeze | grep slack

slack-bolt==1.13.2
slack-sdk==3.16.1


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source