1

I'm pretty new to Python, but I've created a slackbot from a tutorial in Python as a small project, here is the code: https://github.com/sophiefitzpatrick/gallagherbot/blob/master/index.py

At the moment the bot works within my own Slack workspace, but in the future I'd like the bot to be available in other workspaces.

For this, the username and icon of the bot would have to be passed in my code's payload.

I know I need to call this method: https://api.slack.com/methods/chat.postMessage

And pass these arguments:

icon_url
username

and make sure is_user is set to false

But I'm struggling making this a reality within the code, any help for a newbie would be greatly appreciated.

Cheers

Sophie
  • 11
  • 4

1 Answers1

1

As you're using python-slackclient, that's pretty straight forward. Currently you call postMessage with the following parameters:

slack_client.api_call(
        "chat.postMessage",
        channel=channel,
        text=response or default_response
)

You simply need to add the desired parameters to your code like:

slack_client.api_call(
        "chat.postMessage",
        channel=channel,
        text=response or default_response,
        icon_url='https://example.tld/icon.png',
        username='gallagherbot',
        as_user=False
)

Mind that it's as_user and not is_user as stated in your question. Also mind that as_user must be omitted if you're building a Slack app for the previewed new workspace-style.

Dunedan
  • 7,848
  • 6
  • 42
  • 52