Send slack message via api using `xoxp` User token 

  • Create an app here: https://api.slack.com/apps
    • You can see newly created Slack app here: https://api.slack.com/apps/
    • On App screen, click OAuth & Permissions in the sidebar.
      • Under User Token Scopes section, click Add an OAuth Scope
      • Under OAuth Tokens , click Install to Productiwitty. This will generate User OAuth Token starting with xoxp.

Now install slack_sdk inside virtualenv using:

pip install slack_sdk

Then you can send messages via Slack API using following Python 3 code:

#!/usr/bin/env python3
import datetime
from slack_sdk import WebClient

# ID of channel you want to post message to
#
channel_id = "CXXXXXXX"

user_token = "xoxp-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

client = WebClient(user_token)

def send_slack_message(channel_id, msg):
    try:
        result = client.chat_postMessage(
            channel=channel_id,
            text=msg
        )
        print(result)

    except SlackApiError as e:
        print(f"Error: {e}")

send_slack_message(channel_id, "hello")

You can also schedule a message using this code:

def schedule_msg(channel_id, at_hour, at_minute, msg, day):
    scheduled_time = datetime.time(hour=at_hour, minute=at_minute)
    schedule_timestamp = datetime.datetime.combine(day, scheduled_time).strftime('%s')
    try:
        result = client.chat_scheduleMessage(
            channel=channel_id,
            text=msg,
            post_at=schedule_timestamp
        )
        print(result)
    except Exception as e:
        print(f"EXCEPTION!!! {e}")

today = datetime.date.today()

# Schedule a message to be sent at 23:35 (11:35pm) today:
schedule_msg(channel_id, 23, 35, "bye", today)

Related post

Generating Images from the CLI Using ChatGPT's $20 Plan (Without Getting Blocked by Cloudflare)

How OpenAI's Codex CLI Quietly Unlocked Scriptable Image Generation for Paying Users

Most people using ChatGPT's $20-per-month plan think of it as a chat subscription. That's reasonable, because that's how it's marketed - but it undersells what's actually included by a significant margin. Buried inside that flat monthly fee is access to image generation compute that, priced out through any direct API or credits-based system, would cost most active users several times what they're paying. The problem is that getting that compute to do anything useful outside the browser - to slot into a script, a pipeline, a server-side workflow - has historically been an exercise in frustration, mostly because the chatgpt.com website sits behind Cloudflare's bot detection and actively resists automation. A recent, relatively quiet update to OpenAI's Codex tooling changes that picture considerably, and if you're someone who cares about programmatic access to AI capabilities without paying per-image rates, it's worth understanding what just became possible.