Here is an example of a simple client. It uses Main.run to parse the command line and call a function post which posts a note, acting as each of the actors of the configuration file. The content of the note is the concatenation of the anonymous command line arguments.
module AP = Activitypub module C = Activitypub_client (* To build our note content, we put each argument in a paragraph and concatenates. This is for an example purpose, else we should perform proper HTML escaping.*) let build_msg args = String.concat "\n" (List.map (fun s -> Printf.sprintf "<p>%s</p>" s) args) let post_note msg (_actor_iri, (module A : C.Actor.T)) = (* build the actor object and dereference it *) let%lwt actor = A.actor () in (* create a public note with our message *) match%lwt actor#create_note msg ~public:true () with | Ok (Some iri) -> AP.Log.app (fun m -> m "Note posted: %a" Iri.pp iri); Lwt.return_unit | Ok None -> AP.Log.app (fun m -> m "Note posted (no IRI?)"); Lwt.return_unit | Error e -> AP.Log.err (fun m -> m "Error while posting note as %a: %a" Iri.pp actor#iri AP.E.pp e); Lwt.return_unit (* We build the message and make each actor create a note in parallel. *) let post _conf actor_map args = let msg = build_msg args in Lwt_list.iter_p (post_note msg) (Iri.Map.bindings actor_map) let () = C.Main.run post
Compilation requires lwt_ppx
to handle the %lwt
extension nodes, and the package activitypub_client
.