npm.io
0.0.12 • Published 3 years ago

twict

Licence
MIT
Version
0.0.12
Deps
5
Size
114 kB
Vulns
23
Weekly
0
Stars
9

twict

A library for Twitter Account Activity API written in TypeScript

Installation

yarn add twict
# or
npm install twict

Tutorial

1. Install twict
yarn add twict
# or
npm install twict
2. ngrok

download ngrok to your environment.

start http tunnel on port 5000 and copy https://*.ngrok.io url.

ngrok http 5000
3. Like detection
// like-detection.ts
import { Activity, isExpectEventType } from 'twict'

async function main() {
  const activity = new Activity('your environment label', {
    consumerKey: 'your consumer key',
    consumerSecret: 'your consumer secret',
    token: 'your access token',
    tokenSecret: 'your access token secret',
  })

  activity.onFavorite((event) => {
    for (const like of event.favorite_events) {
      console.log(
        `${like.user.screen_name} liked your tweet (${like.favorited_status.text})`
      )
    }
  })

  await activity.listen(5000)

  await activity.deleteAllWebhooks()
  await activity.registerWebhook('your ngrok url here')
  await activity.subscribe()
}

main()

and run with ts-node.

npx ts-node like-detection.ts