How to submit posts that include labels? #242
-
Hey there! Thanks so much for creating this package. I've just started using it and it is working great for me. This issue is to request the ability to include labels when submitting posts. From what I can tell, labels are used to apply content warnings on posts when submitting on https://bsky.app/. Please let me know if this is already possible and I just missed it! Here's what the request looks like when submitting via bsky.app and including a content warning: {
"collection": "app.bsky.feed.post",
"record": {
"$type": "app.bsky.feed.post",
"createdAt": "2024-01-13T16:28:19.938Z",
"embed": {
"$type": "app.bsky.embed.images",
"images": [
{
"alt": "",
"aspectRatio": {
"height": 626,
"width": 640
},
"image": {
"$type": "blob",
"mimeType": "image/jpeg",
"ref": {
"$link": "bafkreichm4wf4ru2omi2v7iefx5f63kejfycs5ggnltf4g6zxyn3or3kxe"
},
"size": 299493
}
}
]
},
"labels": {
"$type": "com.atproto.label.defs#selfLabels",
"values": [
{
"val": "sexual"
}
]
},
"langs": [
"en"
],
"text": "Test content warning"
},
"repo": "did:plc:b76akgyhvhtykcp7j7jsehrc"
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi and welcome to the community! The SDK implements the whooooole lexicon! But, I provided only the most common high-level methods for users that don't want to care about atproto details. Like But for the first time, I wrote the code for you xd. feel free to use it to solve your needs def send_post_with_labels(client, text, labels):
return client.com.atproto.repo.create_record(
models.ComAtprotoRepoCreateRecord.Data(
repo=client.me.did,
collection=ids.AppBskyFeedPost,
record=models.AppBskyFeedPost.Main(
created_at=client.get_current_time_iso(),
text=text,
labels=labels,
),
)
)
def usage_example() -> None:
client = Client()
client.login(os.environ['USERNAME'], os.environ['PASSWORD'])
labels = models.ComAtprotoLabelDefs.SelfLabels(
values=[
models.ComAtprotoLabelDefs.SelfLabel(val='sexual'),
]
)
my_sexual_python_content = send_post_with_labels(client, 'My sexual python content', labels)
print(my_sexual_python_content) to add images pass embed arg. see the link above the final code with images:def send_post_with_labels(client, text, labels, embed):
return client.com.atproto.repo.create_record(
models.ComAtprotoRepoCreateRecord.Data(
repo=client.me.did,
collection=ids.AppBskyFeedPost,
record=models.AppBskyFeedPost.Main(
created_at=client.get_current_time_iso(),
text=text,
labels=labels,
embed=embed,
),
)
)
def usage_example() -> None:
client = Client()
client.login(os.environ['USERNAME'], os.environ['PASSWORD'])
labels = models.ComAtprotoLabelDefs.SelfLabels(
values=[
models.ComAtprotoLabelDefs.SelfLabel(val='sexual'),
]
)
with open('cat2.jpg', 'rb') as f:
upload = client.upload_blob(f.read())
images = [models.AppBskyEmbedImages.Image(alt='Img alt', image=upload.blob)]
embed = models.AppBskyEmbedImages.Main(images=images)
my_sexual_python_content = send_post_with_labels(client, 'My sexual python content', labels, embed)
print(my_sexual_python_content) p.s. i converted it to discussion and mark as question |
Beta Was this translation helpful? Give feedback.
Hi and welcome to the community! The SDK implements the whooooole lexicon! But, I provided only the most common high-level methods for users that don't want to care about atproto details. Like
send_post(text)
. But labeling is not for all (IMO). It would help if you learned about the advanced usage that i detailed here: https://github.com/MarshalX/atproto#advanced-usageBut for the first time, I wrote the code for you xd. feel free to use it to solve your needs