Send Push Notifications With LINE Notify API And Python

Developed a personal AI assistant app with Flutter and LLM, featuring a monitor system. Faced challenges implementing push notifications for iOS due to costs. Discovered LINE Notify as a free alternative. Detailed 10-step process to set up and use LINE Notify for sending alerts, including obtaining access tokens and integrating with chats.

I started a new side project a while ago, which aims to develop my personal AI assistant app with Flutter and LLM. One of the features is a monitor system. I hope the system can send me an alert via mobile push notifications when an error happens. I planned to implement it with Firebase. However, I got stuck because sending push notifications to iOS devices requires an Apple Developer account to get Apple Push Notification service (APNs) certificate, which costs $99 per year. I don’t want to pay for it, so I tried to find a free way to send push notifications. LINE Notify is a good choice.

Step 1. Visit LINE Notify

Go to the LINE Notify page, scroll down, and find “add service”.

Step 2. Fill The Form

Two points need to be noticed. First, the service name is the name before the message. Pick a good name you like.

Second, the callback URL will be used later, but you don’t have to create a page or do anything on your server.

Step 3. Receive Verification Email

Step 4. Access The Service

Now you can access the service and get the client id and client secret.

Step 5. Visit The Link To Connect A Chat

Next, adjust the URL and enter the link. This step corresponds to the screenshot of the document. By the way, according to the document, the state is used to respond to CSRF attacks. It doesn’t show in the notification.

https://notify-bot.line.me/oauth/authorize?response_type=code&client_id={client_id}&redirect_uri={your_callback_url}&scope=notify&state={your_custom_state}

Step 6. Select A Chat

Step 7. Copy The Code In URL

In the old tutorials, a popup will show the access_token after clicking “Agree and connect”. However, the process is changed. You will be redirected to the URL below, copy the code.

{your_callback_url}?code={generated_code}&state={your_state}

Step 8. Get Access_Token

def get_token(redirect_uri, client_id, secret, code):
    url = 'https://notify-bot.line.me/oauth/token'
    payload = {
        'grant_type': 'authorization_code',
        'code': code,
        'redirect_uri': redirect_uri,
        'client_id': client_id,
        'client_secret': secret
    }
    r = requests.post(url, params=payload)
    return r.text

If success, you will get a response like:

{\n  "status" : 200,\n  "message" : "access_token is issued",\n  "access_token" : {your_access_token}\n}

Step 9. Invite LINE Notify To The Chat

To send notifications to the chat, It is essential to invite LINE Notify. You can search to find it or click the link.

Step 10. Start To Send Notifications!

Now you can use the function to send notifications. Besides, LINE Notify API can send URLs. The method is the same as the text.

def send_line_notify(message, access_token):
    url = 'https://notify-api.line.me/api/notify'
    headers = {
        'Authorization': f'Bearer {access_token}'
    }
    payload = {'message': message}
    response = requests.post(url, headers=headers, params=payload)
    return response

You can also find the code on my GitHub.

🚀 Unlock Ads-Free Experience At $5/year

14 days free trial Cancel anytime

58 thoughts on “Send Push Notifications With LINE Notify API And Python”

  1. I got this site from my friend who shared with me concerning this web site and at the moment this time I am visiting this web site and reading very informative articles or reviews at this time.

  2. I’ve tried several apps before, but this casino app feels more stable than most. The loading speed is fast, and I can switch between games without any issues. It’s a solid choice if you want a reliable mobile experience.

Leave a Comment

Your email address will not be published. Required fields are marked *