this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

declareLabeler script

futurGH 6761aaeb d463fa78

+41
+41
src/scripts/declareLabeler.ts
··· 1 + import { AtpAgent, ComAtprotoLabelDefs } from "@atproto/api"; 2 + 3 + /** 4 + * Declare the labels this labeler will apply. Necessary for users to be able to configure what they see. 5 + * @param agent The agent logged into the labeler account. 6 + * @param labelDefinitions The label definitions to declare. You can learn about the definition format [here](https://docs.bsky.app/docs/advanced-guides/moderation#custom-label-values). 7 + */ 8 + export async function declareLabeler( 9 + agent: AtpAgent, 10 + labelDefinitions: Array<ComAtprotoLabelDefs.LabelValueDefinition>, 11 + ): Promise<void>; 12 + /** 13 + * Declare the labels this labeler will apply. Necessary for users to be able to configure what they see. 14 + * @param credentials The credentials of the labeler account. 15 + * @param labelDefinitions The label definitions to declare. You can learn about the definition format [here](https://docs.bsky.app/docs/advanced-guides/moderation#custom-label-values). 16 + */ 17 + export async function declareLabeler( 18 + credentials: { pds?: string; identifier: string; password: string }, 19 + labelDefinitions: Array<ComAtprotoLabelDefs.LabelValueDefinition>, 20 + ): Promise<void>; 21 + export async function declareLabeler( 22 + agentOrCredentials: AtpAgent | { pds?: string; identifier: string; password: string }, 23 + labelDefinitions: Array<ComAtprotoLabelDefs.LabelValueDefinition>, 24 + ) { 25 + const agent = agentOrCredentials instanceof AtpAgent 26 + ? agentOrCredentials 27 + : new AtpAgent({ service: agentOrCredentials.pds || "https://bsky.social" }); 28 + if (!agent.hasSession) { 29 + if (!(agentOrCredentials instanceof AtpAgent)) { 30 + await agent.login(agentOrCredentials); 31 + } else { 32 + throw new Error("A password must be provided to log in to the labeler account."); 33 + } 34 + } 35 + 36 + const labelValues = labelDefinitions.map(({ identifier }) => identifier); 37 + await agent.app.bsky.labeler.service.create({ repo: agent.did }, { 38 + policies: { labelValues, labelValueDefinitions: labelDefinitions }, 39 + createdAt: new Date().toUTCString(), 40 + }); 41 + }