Reputation: 13
when ever I try to get the username from slack outgoing hook its showing default username as slackbot.it doesn't show the username of the actual person in this case Nawaf. as u can see it should save the name "Nawaf" or "test" but it's saving "slackbot" what am I doing wrong?
slack outgoing webhook documentation https://api.slack.com/custom-integrations/outgoing-webhooks
Upvotes: 1
Views: 519
Reputation: 32697
The reason you don't get the username of the app message in your outgoing webhook request is most likely that this is not supported. Outgoing webhooks is a legacy feature of Slack and replaced by the Events API, which provide a similar functionality, but is way more powerful.
I tested it to verify your requirement and can confirm that you get the name of the app sending a message with the Events API from message events.
Here is an example of the message event you receive from a message posted by incoming webhooks (as PHP array):
array (
'token' => 'XXX',
'team_id' => 'T12345678',
'api_app_id' => 'A12345678',
'event' =>
array (
'text' => 'This is a line of text.
And this is another one.',
'username' => 'magic-webhook',
'bot_id' => 'B12345678',
'type' => 'message',
'subtype' => 'bot_message',
'ts' => '1509969916.000102',
'channel' => 'G12345678',
'event_ts' => '1509969916.000102',
),
'type' => 'event_callback',
'event_id' => 'Ev12345678',
'event_time' => 1509969916,
'authed_users' =>
array (
0 => 'U12345678',
),
)
For messages posted by Slack apps you won't get the username in the message event directly, but you can then call the API method bots.info
with bot_id
to get the app name.
Upvotes: 1