Skip to content
View tourlek's full-sized avatar
🏠
Working from home
🏠
Working from home

Block or report tourlek

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Content in all repositories owned by your account will be closed.
Maximum 250 characters. Please don’t include any personal information such as legal names or email addresses. This note will only be visible to you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
tourlek/README.md

tourlek affiliate bot

Auto loop bot for Shopee Affiliate / TikTok Shop Affiliate: discover trending products β†’ generate a caption with Claude β†’ post to your own social channels β†’ track clicks/orders/commission. Runs as a Cloudflare Worker on a Cron Trigger (hourly by default), backed by a D1 database.

Current state: mock mode

FORCE_MOCK_MODE = "true" in wrangler.toml is on by default. In this mode every step (product discovery, content generation, publishing) uses fake data so you can see the full loop run end-to-end (/status after /run) before connecting any real account. Nothing is posted to real social media or fetched from Shopee/TikTok while this is on.

Turn it off ("false") only after you've configured the real secrets below for the platforms you want live.

Accounts / API access you need (none of this exists yet β€” start here)

  1. Anthropic API key β€” https://console.anthropic.com β†’ used for caption generation. Without it, captions fall back to a mock template.
  2. Shopee Affiliate Program β€” apply at https://affiliate.shopee.co.th (or your country's Shopee Affiliate site). Approval is required before Shopee issues Open API (AppId/AppSecret) credentials for the Affiliate Open API (GraphQL, open-api.affiliate.shopee.com/graphql).
  3. TikTok Shop Partner Center β€” https://partner.tiktokshop.com. TikTok's affiliate/creator marketplace API access and auth flow depend on your region and approval status β€” src/providers/affiliate/tiktok.ts is left unimplemented on purpose until you have real docs/access to verify against (do not trust a fabricated endpoint here).
  4. Facebook Page + Graph API app β€” https://developers.facebook.com, create an app, add a Page, generate a long-lived Page Access Token with pages_manage_posts. Needed to auto-post to your Page.
  5. Instagram Business/Creator account linked to that Facebook Page β€” posting goes through the same Graph API token as Facebook.
  6. TikTok Content Posting API β€” separate from TikTok Shop; needs its own developer app + video.publish scope + content-posting audit. Left unimplemented in src/providers/publish/tiktok.ts for the same reason as above β€” TikTok requires a multi-step upload flow, not a single caption+image call.

Once you have credentials, set them as Worker secrets (never commit them):

wrangler secret put ANTHROPIC_API_KEY
wrangler secret put SHOPEE_APP_ID
wrangler secret put SHOPEE_APP_SECRET
wrangler secret put TIKTOK_APP_KEY
wrangler secret put TIKTOK_APP_SECRET
wrangler secret put TIKTOK_ACCESS_TOKEN
wrangler secret put FACEBOOK_PAGE_ID
wrangler secret put FACEBOOK_PAGE_ACCESS_TOKEN
wrangler secret put INSTAGRAM_BUSINESS_ACCOUNT_ID

For local dev, copy .dev.vars.example to .dev.vars and fill in the same values instead.

Setup

npm install
wrangler login

# create the D1 database and paste the returned database_id into wrangler.toml
wrangler d1 create affiliate_bot

npm run db:migrate:local   # local dev DB
npm run db:migrate:remote  # production DB

Run locally

npm run dev
curl -X POST http://localhost:8787/run
curl http://localhost:8787/status

Deploy

npm run deploy

This registers the Worker and the hourly Cron Trigger (wrangler.toml [triggers]). Adjust the cron schedule and PRODUCTS_PER_RUN to taste.

Architecture

src/
  index.ts                 Worker entrypoint: scheduled handler (cron) + /run, /status
  orchestrator.ts           Ties discovery -> content -> publish -> tracking together
  types.ts                  Shared types (Env bindings, domain types)
  db/
    schema.sql              D1 tables: products, posts, commission_snapshots, run_logs
    client.ts                Query helpers
  providers/
    affiliate/               Product discovery per platform (Shopee, TikTok, mock)
    content/                 Caption generation (Claude, mock fallback)
    publish/                 Posting adapters (Facebook, Instagram, TikTok, mock)
    tracking/                Commission/click/order snapshot capture

Every provider category has a mock implementation and a factory (getAffiliateProvider, getPublishAdapters) that falls back to mock mode whenever real credentials are absent or FORCE_MOCK_MODE is on β€” so the loop is always runnable, and you can light up one real integration at a time without breaking the others.

Known gaps to close before this is production-ready

  • ShopeeAffiliateProvider implements the documented request-signing pattern but its GraphQL query shape is not verified against a live account β€” confirm field names in Shopee's GraphQL playground once approved.
  • TikTokAffiliateProvider (discovery) and TikTokPublishAdapter (posting) are stubs β€” TikTok's APIs need to be implemented against real Partner Center / Developer docs once you have access.
  • No image generation yet β€” imageUrl is passed through from whatever the affiliate API returns; Instagram in particular requires a public image URL to post.
  • No dedup/rate-limiting logic yet to avoid re-posting the same product across runs β€” add a check against posts/products in orchestrator.ts before scaling up posting frequency.

Popular repositories Loading

  1. tourlek tourlek Public

    Config files for my GitHub profile.

    TypeScript

  2. iwdc_th iwdc_th Public

    iwdc_project

    Vue 1

  3. jm-work jm-work Public

    Vue

  4. backend backend Public

    JavaScript

  5. abc-demo abc-demo Public

    TypeScript

  6. migrant-labor-crm migrant-labor-crm Public

    TypeScript