Hi all,
Twitter is falling apart. So I’d like to send tweets to Bluesky (https://bsky.app). Does someone know how it works? I already saw some bots so I assume there must be a way to do it. Do they offer an API?
Thanks!
Hi all,
Twitter is falling apart. So I’d like to send tweets to Bluesky (https://bsky.app). Does someone know how it works? I already saw some bots so I assume there must be a way to do it. Do they offer an API?
Thanks!
Best answer by brkldBest answer by brkld
Hi
I found this API: https://atproto.com/blog/create-post
I managed to get it done by adding two “Code By Zapier” steps:
First one: add javascript code:
const url = 'https://bsky.social/xrpc/com.atproto.server.createSession';
const data = {
identifier: inputData['username'], // Input from Zapier, assuming 'username' corresponds to 'BLUESKY_HANDLE'
password: inputData['password'] // Input from Zapier, corresponding to 'BLUESKY_APP_PASSWORD'
};
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(data), // Sending the data as a JSON string
headers: {
'Content-Type': 'application/json' // Use JSON content type
},
redirect: 'manual'
});
// Check if the response status is OK
if (!response.ok) {
console.error('Failed request', await response.text());
return null;
}
const responseBody = await response.json(); // Parse the JSON response
if (!responseBody.accessJwt) {
console.error('accessJwt not found in the response');
return null;
}
output = {
accessJwt: responseBody.accessJwt
};
needs username and password (app password bluesky > settings > app) as input!
Second one:
const secondUrl = 'https://bsky.social/xrpc/com.atproto.repo.createRecord';
const authToken = inputData['token'];
const tweetText = inputData['tweet_text'] + " " + inputData['tweet_url'];
const tweetURL = inputData['tweet_url'];
// Finding the start and end byte positions of the tweetURL within tweetText
const byteStart = Buffer.from(tweetText.slice(0, tweetText.indexOf(tweetURL))).length;
const byteEnd = byteStart + Buffer.from(tweetURL).length;
const recordData = {
"$type": "app.bsky.feed.post",
"text": tweetText,
"createdAt": new Date().toISOString(),
"facets": [
{
"index": {
"byteStart": byteStart,
"byteEnd": byteEnd
},
"features": [
{
"$type": "app.bsky.richtext.facet#link",
"uri": tweetURL
}
]
}
]
};
const postData = {
repo: inputData['username'],
collection: 'app.bsky.feed.post',
record: recordData
};
const postResponse = await fetch(secondUrl, {
method: 'POST',
body: JSON.stringify(postData),
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
}
});
if (!postResponse.ok) {
console.error('Failed request', await postResponse.text());
output = {
success: false,
message: "Failed to create record"
};
return;
}
const postResponseBody = await postResponse.json();
if (!postResponseBody.success) {
console.error('Failed to create record', postResponseBody.message);
output = {
success: false,
message: postResponseBody.message
};
return;
}
output = {
success: true
};
needs token, username, tweet_text, tweet_url as input.
tweet_text is your text and tweet_url is a link I want to include in my tweets to websites. it’s optional and can be removed.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.