Slack RTM API post from a given username

89 Views Asked by At

I have integrated the Slack RTM API into my program, and I am able to post to Slack as well as receive new messages from Slack.

The one problem I am having is when posting to Slack, the post comes from my username. I know it is possible to change the posting user in the Web API by setting the "username" and "as_user" field, so I am not sure why this would be any different. Below is my message that I am using. Comment.user.name is a string.

        var message =
        {
            id : 1,
            type : "message",
            channel : self.channel,
            text : comment.text,
            thread_ts : self.timestamp,
            username : comment.user.name,
            as_user : false
        };
        self.websocket.send(JSON.stringify(message));

Is this possible with the way I am doing it, or is there a better way? Thanks.

1

There are 1 best solutions below

0
On

It is not possible in the Slack Web API to set a user in that way. There is only one way to achieve this: Obtain an API token for the user you want to post as and use it when making your API request.