{"size": 1044, "ext": "js", "max_stars_repo_path": "line/handler/reply-event-json.js", "max_stars_repo_name": "taichunmin/gcf-line-devbo", "max_stars_repo_stars_event_min_datetime": "2020-04-06T05:39:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T00:24:12.000Z", "max_issues_repo_path": "line/handler/reply-event-json.js", "max_issues_repo_name": "taichunmin/gcf-line-devbo", "max_issues_repo_issues_event_min_datetime": "2020-04-07T03:48:53.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-09T11:49:23.000Z", "max_forks_repo_path": "line/handler/reply-event-json.js", "max_forks_repo_name": "taichunmin/gcf-line-devbo", "max_forks_repo_forks_event_min_datetime": "2020-04-06T08:42:36.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-19T15:51:14.000Z"}
{"max_stars_count": 21, "max_issues_count": 5, "max_forks_count": 4, "avg_line_length": 24.8571428571, "max_line_length": 62, "alphanum_fraction": 0.5584291188}
const _ = require('lodash')
const msgJsonStringify = require('../msg/json-stringify')

const eventToMsgsHandlers = [
  // event 轉成 json
  ctx => { ctx.msgs.push(msgJsonStringify(ctx.event)) },

  // quickreply sticker
  ctx => {
    if (_.get(ctx, 'event.message.type') !== 'sticker') return
    const msg = _.last(ctx.msgs)
    _.update(msg, 'quickReply.items', items => {
      items = _.toArray(items)
      const { stickerId, packageId } = ctx.event.message
      items.push({
        type: 'action',
        action: {
          label: '/replySticker',
          text: `/replySticker ${packageId} ${stickerId}`,
          type: 'message',
        },
      }, {
        type: 'action',
        action: {
          label: '/notifySticker',
          text: `/notifySticker ${packageId} ${stickerId}`,
          type: 'message',
        },
      })
      return items
    })
  },
]

module.exports = async (ctx, next) => {
  ctx.msgs = []
  for (const handler of eventToMsgsHandlers) {
    handler(ctx)
  }
  await ctx.replyMessage(ctx.msgs)
}
