Skip to content

Commit

Permalink
fix variables not passing
Browse files Browse the repository at this point in the history
  • Loading branch information
jerdog committed Dec 1, 2024
1 parent 09f98aa commit fa389ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
44 changes: 25 additions & 19 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@ export default {
// Handle HTTP requests
async fetch(request, env) {
try {
// debug('Variables loaded:', 'info', env);

// Copy environment variables from env to process.env
Object.assign(process.env, {
MASTODON_API_URL: env.MASTODON_API_URL,
MASTODON_ACCESS_TOKEN: env.MASTODON_ACCESS_TOKEN,
BLUESKY_API_URL: env.BLUESKY_API_URL,
BLUESKY_USERNAME: env.BLUESKY_USERNAME,
BLUESKY_PASSWORD: env.BLUESKY_PASSWORD,
MASTODON_SOURCE_ACCOUNTS: env.MASTODON_SOURCE_ACCOUNTS,
BLUESKY_SOURCE_ACCOUNTS: env.BLUESKY_SOURCE_ACCOUNTS,
EXCLUDED_WORDS: env.EXCLUDED_WORDS,
DEBUG_MODE: env.DEBUG_MODE,
DEBUG_LEVEL: env.DEBUG_LEVEL,
MARKOV_STATE_SIZE: env.MARKOV_STATE_SIZE,
MARKOV_MIN_CHARS: env.MARKOV_MIN_CHARS,
MARKOV_MAX_CHARS: env.MARKOV_MAX_CHARS,
MARKOV_MAX_TRIES: env.MARKOV_MAX_TRIES
});
process.env = {
...process.env,
MASTODON_API_URL: env.MASTODON_API_URL || '',
MASTODON_ACCESS_TOKEN: env.MASTODON_ACCESS_TOKEN || '',
BLUESKY_API_URL: env.BLUESKY_API_URL || '',
BLUESKY_USERNAME: env.BLUESKY_USERNAME || '',
BLUESKY_PASSWORD: env.BLUESKY_PASSWORD || '',
MASTODON_SOURCE_ACCOUNTS: env.MASTODON_SOURCE_ACCOUNTS || '',
BLUESKY_SOURCE_ACCOUNTS: env.BLUESKY_SOURCE_ACCOUNTS || '',
EXCLUDED_WORDS: env.EXCLUDED_WORDS || '',
DEBUG_MODE: env.DEBUG_MODE || 'false',
DEBUG_LEVEL: env.DEBUG_LEVEL || 'info',
MARKOV_STATE_SIZE: env.MARKOV_STATE_SIZE || '2',
MARKOV_MIN_CHARS: env.MARKOV_MIN_CHARS || '100',
MARKOV_MAX_CHARS: env.MARKOV_MAX_CHARS || '280',
MARKOV_MAX_TRIES: env.MARKOV_MAX_TRIES || '100'
};

// debug('Environment variables loaded:', 'info', process.env);

const url = new URL(request.url);

Expand All @@ -52,14 +57,15 @@ export default {
headers: { 'Content-Type': 'application/json' }
});
}
return new Response('Method not allowed', { status: 405 });
}

// Handle bot execution
if (url.pathname === '/run') {
if (request.method === 'POST') {
console.log('Starting bot execution...');
debug('Starting bot execution...');
await main(env);
console.log('Bot execution completed');
debug('Bot execution completed');
return new Response('Bot execution completed', { status: 200 });
}
return new Response('Method not allowed', { status: 405 });
Expand All @@ -68,7 +74,7 @@ export default {
return new Response('Not found', { status: 404 });
} catch (error) {
debug('Worker error:', 'error', error);
return new Response('Internal error', { status: 500 });
return new Response('Internal Server Error', { status: 500 });
}
},

Expand Down
2 changes: 2 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ MARKOV_STATE_SIZE = "2"
MARKOV_MAX_TRIES = "100"
MARKOV_MIN_CHARS = "100"
MARKOV_MAX_CHARS = "280"
MASTODON_API_URL = "https://hachyderm.io"
BLUESKY_API_URL = "https://bsky.social"

# KV namespace for storing source tweets
[[kv_namespaces]]
Expand Down
14 changes: 7 additions & 7 deletions wrangler.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ compatibility_date = "2024-11-06"
# Configure your Workers environment
[vars]
# Example environment variables (DO NOT put actual values here)
MASTODON_URL = "https://mastodon.example.com"
MASTODON_API_URL = "https://mastodon.example.com"
MASTODON_ACCESS_TOKEN = "your_mastodon_token"
BLUESKY_SERVICE = "https://bsky.social"
BLUESKY_IDENTIFIER = "your.handle.bsky.social"
BLUESKY_APP_PASSWORD = "your_app_password"
BLUESKY_API_URL = "https://bsky.social"
BLUESKY_USERNAME = "your.handle.bsky.social"
BLUESKY_PASSWORD = "your_app_password"
DEBUG_MODE = "false"

# Development environment variables
[env.development]
name = "serverless-social-bot-dev"
vars = { DEBUG_MODE = "true" }
vars = { DEBUG_MODE = "true", DEBUG_LEVEL = "verbose" }

# Production environment variables
[env.production]
name = "serverless-social-bot"
vars = { DEBUG_MODE = "false" }
name = "<YOUR_WORKER_NAME>" # UPDATE WITH YOUR WORKER NAME
vars = { DEBUG_MODE = "false", DEBUG_LEVEL = "verbose" }

# Customize the build process if needed
[build]
Expand Down

0 comments on commit fa389ff

Please sign in to comment.