Git Product home page Git Product logo

bluesky-chatbot-tutorial's Introduction

bluesky-chatbot-tutorial

Quickstart

This requires Node.js 18 or above. Create a .env from the .env.template and fill it with your login information. Then run the following command to setup the developer environment:

npm install

All changes should be made in the index.ts which will then compile into a index.js which can be run

npx tsc
node index.js

Complete install and run instructions

These are the steps I run in the Youtube Video. To setup a working project from scratch (delete all files except for this README file and the .gitignore) do the following:

  1. Make sure you have Node 18 or above installed. If you don't install using
  1. Install a package.json config
npm init -y
  1. Change the package.json config to run your script as a module by adding the following line
{
    "type":"module",
    ...
}
  1. Then use npm to install the following packages
npm install dotenv @atproto/api && npm install typescript @types/node --save-dev
  1. Create an empty index.ts file. We will be writing here shortly, but the next command prefers there to be an existing .ts file or else it will show a warning.
touch index.ts
  1. Create a tsconfig
npx tsc --init
  1. Adjust the following values in the tsconfig.json
{
    ...
    "target": "esnext", 
    "module": "Nodenext",
    "moduleResolution": "nodenext", 
    ...
}
  1. Create a .env with the following information set
BLUESKY_USERNAME=
BLUESKY_PASSWORD=
  1. Add the following code to login to the Bluesky API
import bsky from '@atproto/api';
const { BskyAgent } = bsky;
import * as dotenv from 'dotenv';

dotenv.config();
const agent = new BskyAgent({ service: 'https://bsky.social' })

await agent.login({
  identifier: process.env.BLUESKY_USERNAME!,
  password: process.env.BLUESKY_PASSWORD!,
});
  1. To run the code you must compile into a .js file which you can do by running npx tsc. Then you can run your file using node. This whole proccess looks like
npx tsc
node index.js
  1. Run the lexicons here as function calls to interact with the Bluesky API.

For example getProfile

const response = await agent.getProfile({"actor":"thinja.bsky.social"})
console.log(response)
  1. (Optional) This is the code I run in the video in order to generate an emoji based on the percent of the year complete and write that as a post in bsky
function getYearProgressEmoji() {
    const currentDate = new Date();
    const dayOfYear = Math.floor((Number(currentDate) - Number(new Date(currentDate.getFullYear(), 0, 1))) / (1000 * 60 * 60 * 24));
    const percentageDone = dayOfYear / 365;

    const greenCircles = Math.round(percentageDone * 10);
    const greyCircles = 10 - greenCircles;

    return '๐ŸŸข'.repeat(greenCircles) + 'โšช'.repeat(greyCircles);
}

agent.post({"text": getMonthProgressEmoji()});

bluesky-chatbot-tutorial's People

Contributors

justinchavez avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.