Posting Status

Currently minimal_activitypub only implements standard status posting (polls and direct messages / DMs are not currently implemented).

Posting text only status

The sample code below shows a very simple text only status being posted.

1from minimal_activitypub.client_2_server import ActivityPub
2from minimal_activitypub import Status
3
4async def post_status(instance_api: ActivityPub, status: str) -> Status:
5
6   posted_status = await instance_api.post_status(status=status)

Posting status that includes picture

The sample code below shows how to post a status with images attached. Basically the images/media needs to be posted first and the media id(s) need to be included when posting the status itself.

 1import aiofiles
 2import magic
 3from minimal_activitypub.client_2_server import ActivityPub
 4from minimal_activitypub import Status
 5
 6async def post_status(instance_api: ActivityPub, status: str, image_path: str) -> Dict[str, Any]:
 7
 8   # First determine mime-type
 9   mime_type = magic.from_file(image_path, mime=True)
10
11   # Post media
12   async with aiofiles.open(image_path, "rb") as image_file:
13      posted_media = await instance_api.post_media(file=image_file, mime_type=mime_type)
14
15   # Determine media id to include when posting status
16   media_id = posted_media["id"]
17
18   # Post actual status and include image
19   posted_status = await instance_api.post_status(status=status, media_ids=[media_id])

Method Signatures

Following are the method signatures used in the above examples.