import * as bp from '.botpress'

const bot = new bp.Bot({
  register: async (props) => {
    props.logger.info('Registering Hello World bot!')
  },
  actions: {
    sayHello: async ({ input }) => {
      const name = input?.name || 'World'
      return { message: `Hello, ${name}!` }
    },
  },
})

bot.on.message('*', async (props) => {
  const { message, client, ctx } = props

  const { message: response } = await bot.actionHandlers.sayHello({ ...props, input: {} })
  await client.createMessage({
    conversationId: message.conversationId,
    userId: ctx.botId,
    tags: {},
    type: 'text',
    payload: {
      text: response,
    },
  })
})

export default bot
