line-reminder-bot

linebot

This repo creates a LINE Bot. Enter the date and text you want to be reminded of. When the time arrives this Bot will remind you. Similar to Slack reminder.

I've created a front page for this Bot.

Test Locally

You need to have Docker engine running on your local.

cd hello-world
npm install
cd ..
sam build
sam local start-lambda 

After Lambda is started, start ngrok and point ngrok to the Lambda:

./ngrok http -subdomain=ezyraise -region ap 3001

Now your local LINE Bot is connected to the internet.

How to invoke Lambda

POST https://ezyraise.ap.ngrok.io/2015-03-31/functions/LineBotFunction/invocations

Point the LINE Webhook URL to the ngrok.

linebot1

Now you can add the LINE Bot to your phone, start interacting with it. All the messages will be sent to your local LINE Bot.

Deploy to AWS

export AWS_PROFILE=
sam build
sam deploy --no-confirm-changeset

The deployment will create a DynamoDB table to store users and messages. When user wants to see all reminders, the Bot will query the DynamoDB.

How does the reminder work

When you enter a text and date in the LINE Bot, a message will be sent to QStash with the text and the date. Date is converted to epoch time in seconds. QStash is a messaging queue. You can set an attribute notBefore. notBefore is the time the message pops off the queue and be sent back to you.

QStash Free Plan only supports 7 days of queuing. I worked around the limit by sending the messsage back to the queue every 7 days, until the desired time has reached.

if (scheduledTimeInSeconds === nextTimeInSeconds) {
  // remind user
} else {
  // send message back to the queue
}

DynamoDB

Model pk sk gsi1pk gsi1sk
User USER#user_id USER#user_id scheduled_reminders_count created_at
Reminder UR#user_ud REMINDER#reminder_id UR#user_id status message scheduled_at created_at

Access Patterns

  1. get total count of scheduled reminders by user
  2. get scheduled reminders by user and ordered by scheduled_at
  3. insert reminder
  4. update reminder status
  5. insert user
  6. get user
  7. update user's reminder count