hota1024 / twict

A library for Twitter Account Activity API written in TypeScript
MIT License
9 stars 0 forks source link

Allow users to freely create Webhook handlers #6

Open hota1024 opened 1 year ago

hota1024 commented 1 year ago

🎏 Goals

💡 Ideas

The ActivityActivityControllable#emit(body: ActivityEvent): Promise<void> and ActivityControllable#crc(): CrcResponse methods

/* Twict */
const activity = new Activity('{LABEL}', { /* options */ })
activity.onFavoriteEvent(() => /* ... */)

/* express */
const app = express()
app.get('/', (req, res) => {
  const crcToken = req.query.crc_token

  if (typeof crcToken === 'string') {
    res.send(activity.crc()) // Activity#crc(): CrcResponse
  } else {
    res.status(400).send('crc_token missing from request.')
  }
})
app.post('/', ({ body }) => activity.emit(body)) // Activity#emit(body: ActivityEvent): Promise<void>
winstxnhdw commented 1 year ago

I am not very experienced in TypeScript/JavaScript patterns but grammY, a Telegram bot framework, uses adapters.

See this https://github.com/grammyjs/grammY/blob/main/src/convenience/frameworks.node.ts