Last time Use the created LineBot so that you can send messages regularly.
Add a schedule to Heroku.
heroku addons:add scheduler:standard
Heroku Scheduler will be added, so select it.
Select Create job to create a new schedule.
Specify when to execute and the command to execute.
Add a file to be executed on a schedule separately from main.py.
scheduler.py
from flask import Flask, request, abort
import os
from linebot import (
LineBotApi, WebhookHandler
)
from linebot.exceptions import (
InvalidSignatureError
)
from linebot.models import (
MessageEvent, TextMessage, TextSendMessage,
)
app = Flask(__name__)
LINE_CHANNEL_ACCESS_TOKEN = os.environ["LINE_CHANNEL_ACCESS_TOKEN"]
LINE_CHANNEL_SECRET = os.environ["LINE_CHANNEL_SECRET"]
USER_ID = os.environ["USER_ID"]
line_bot_api = LineBotApi(LINE_CHANNEL_ACCESS_TOKEN)
def main():
pushText = TextSendMessage(text="Do you want to register your attendance?")
line_bot_api.push_message(USER_ID, messages=pushText)
if __name__ == "__main__":
main()
Make main.py also give a specific response to the received message.
main.py
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
if "Attendance" in event.message.text and "Registration" in event.message.text :
#registration process
replyText = "Has registered"
line_bot_api.reply_message(event.reply_token, TextSendMessage(text=replyText))
line_bot_api.reply_message(event.reply_token, TextSendMessage(text=event.message.text))
Recommended Posts