1. Opening Problem Statement
Meet Lin, a language tutor and content creator who spends hours manually translating messages and images from her Line app followers into Chinese with pinyin and English explanations. Every day, she receives mixed text and picture messages requesting translations that take her away from creating valuable lessons. This manual process is slow, prone to errors, and causes delays that frustrate both Lin and her followers.
These translation tasks consume at least 2-3 hours daily and often result in inconsistent or incomplete translations. What Lin needs is an automation tailored to instantly recognize and process various types of messages to provide accurate, comprehensive translations including Chinese characters, pinyin, and English meanings.
2. What This Automation Does
This n8n workflow automates the entire Chinese translation process by integrating Line Messaging, OpenRouter.ai LLM models, and smart routing. When a message arrives on Line, here’s what happens:
- Detects the message type (text, image, audio, or others) using a Switch node.
- For text messages, sends the content to OpenRouter’s Qwen LLM that generates Chinese characters, pinyin, and English translation.
- For images, it fetches the image content via Line API, converts it to base64, and then sends it to OpenRouter for extraction and translation.
- Sends a “loading” animation back to the user on Line to keep the interaction engaging while the workflow processes the data.
- Replies to the user with a clear, formatted translation message directly in Line.
- Handles unsupported message types gracefully by informing the user to retry.
By using this workflow, Lin instantly saves multiple hours daily, reduces errors, and enhances her followers’ experience with prompt, multi-format Chinese translations right inside Line.
3. Prerequisites ⚙️
- n8n account with access to HTTP Request, Webhook, Switch, and Extract From File nodes.
- Line Developer account configured with Messaging API channel for webhook and sending messages (https://developers.line.biz/en/docs/messaging-api/receiving-messages/).
- Line Messaging API credentials (Channel Access Token) set up as HTTP Header Authentication in n8n.
- OpenRouter.ai API key for accessing LLM models (like Qwen). Create an account and get API credentials from https://openrouter.ai/docs/quickstart.
- Basic understanding of Line message structures and API triggers.
4. Step-by-Step Guide
Step 1: Configure the Line Webhook Trigger
Go to n8n → Click + New Workflow → Drag the Webhook node.
Set HTTP Method to POST and Path to cn (this will form your webhook URL).
Copy the generated webhook URL, then navigate to your Line Developer Console → Messaging API → Webhook settings, and paste this URL (remove any test suffix for production).
This webhook node listens for incoming Line messages and triggers the workflow.
Common mistake: Forgetting to set the webhook URL in Line Console or not switching webhook from test to active mode.
Step 2: Add Line Loading Animation Node
Drag in an HTTP Request node and rename to Line Loading Animation.
Set the method to POST and URL to https://api.line.me/v2/bot/chat/loading/start.
Under Body Parameters (JSON), insert:
{
"chatId": "{{ $json.body.events[0].source.userId }}",
"loadingSeconds": 60
}
Use HTTP Header Authentication with your Line Channel Access Token credential.
This node sends a loading indicator to Line user to signal processing.
Step 3: Insert a Switch Node to Handle Message Types
Add a Switch node and set up four rules based on {{$('Line Webhook').item.json.body.events[0].message.type}}:
- “text” (for text messages)
- “image” (for images)
- “audio” (for audio; not fully supported here)
- “else” (catch-all for unsupported types)
Rename outputs accordingly: text, img, audio, else.
Expected result: Messages are routed depending on their types.
Step 4: Setup Text Message Translation with OpenRouter.ai
Drag an HTTP Request node and rename to OpenRouter: qwen/qwen-2.5-72b-instruct:free.
Configure POST method to https://openrouter.ai/api/v1/chat/completions with the following JSON body template:
{
"model": "qwen/qwen-2.5-72b-instruct:free",
"messages": [
{
"role": "system",
"content": "please provide chinese character, pinyin and translation in english. if the input is in english, you will translate and also provide chinese character, pinyin and translation in english for each word"
},
{
"role": "user",
"content": "{{ $('Line Webhook').item.json.body.events[0].message.text }}"
}
]
}
Attach your OpenRouter.ai HTTP Header Authentication credential.
This node processes the incoming text message with AI to generate a full Chinese translation set.
Step 5: Setup Image Message Handling
For image input, add another HTTP Request node named Get Image.
Configure GET with URL:
=https://api-data.line.me/v2/bot/message/{{ $('Line Webhook').item.json.body.events[0].message.id }}/content
This grabs the image binary data from Line.
Then pass the file to an Extract from File node to convert binary data to base64 under the property img_prompt.
Next, send this base64 image in a POST HTTP Request node calling OpenRouter.ai with JSON body:
{
"model": "qwen/qwen2.5-vl-72b-instruct:free",
"messages": [
{
"role": "system",
"content": "please provide chinese character, pinyin and translation in english for all the text in the image"
},
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,{{ $json.img_prompt }}"
}
}
]
}
]
}
This sends image data for AI translation.
Step 6: Reply to User on Line
For text translations, add an HTTP Request named Line Reply (Text), for images a node Line Reply (image).
Each uses POST to https://api.line.me/v2/bot/message/reply with JSON body:
{
"replyToken": "{{ $('Line Webhook').item.json.body.events[0].replyToken }}",
"messages": [
{
"type": "text",
"text": "{{ $json.choices[0].message.content.replaceAll("n","\n").replaceAll("n","").removeMarkdown().removeTags().replaceAll('"',"") }}"
}
]
}
This sends clean, formatted translated text back to the user.
Step 7: Handle Unsupported Message Types
For audio or other unsupported messages, set up HTTP Request nodes with replies saying “Please try again. Message type is not supported.”
Connect these outputs on the Switch node accordingly.
5. Customizations ✏️
- Expand to audio translation: Integrate an audio transcription service to convert audio messages before translation.
- Multi-language support: Modify the OpenRouter.ai system prompts to include translations in other languages, adding more output formats.
- Custom message formatting: Change the text replacement or apply markdown styling within the Line Reply nodes for richer output.
- Multiple Line accounts: Duplicate webhook and credential sets to manage translations for several Line bots simultaneously.
- Timeout adjustments: Adjust loading animation duration in the Line Loading Animation node to match typical processing time.
6. Troubleshooting 🔧
Problem: “Webhook not receiving messages from Line”
Cause: Missing or incorrect webhook URL in Line Developer Console settings.
Solution: Confirm webhook URL matches exactly the n8n webhook URL, set to active and retry.
Problem: “OpenRouter API authentication errors”
Cause: Invalid or expired OpenRouter API key.
Solution: Refresh or re-enter API key in credentials, check quota usage on OpenRouter dashboard.
Problem: “Line reply messages not sending”
Cause: Incorrect HTTP Header Authentication with invalid Line Channel Access Token.
Solution: Verify the Channel Access Token credential in n8n, reauthenticate if needed.
7. Pre-Production Checklist ✅
- Test the Line webhook with sample text and image messages from your Line official account.
- Ensure loading animation appears promptly in Line chat.
- Verify OpenRouter AI responses contain correct Chinese characters, pinyin, and English.
- Confirm replies are received correctly in Line message feed.
- Check Switch node routes messages accurately by type.
- Backup your workflow JSON and credential configurations before deployment.
8. Deployment Guide
Activate your workflow by toggling it on in n8n editor after confirming all connections and credentials are working.
Monitor executions via n8n’s dashboard and watch for any errors in real-time.
Adjust loading animation time and retry messages as needed based on performance feedback.
Encourage users to send sample messages and images for ongoing validation.
9. FAQs
Q: Can I use other LLM providers instead of OpenRouter.ai?
A: Yes, if they support similar APIs. You will need to adjust the HTTP Request node with new endpoint and body structure.
Q: Does this consume a lot of API credits?
A: Yes, depending on message volume and model. Monitor OpenRouter.ai dashboard to manage costs.
Q: Is my data safe?
A: The workflow uses HTTPS and authenticated APIs, but avoid including sensitive personal data in messages.
Q: Can this handle bulk translation requests?
A: The workflow is designed for real-time interactive messaging, not bulk batch processing.
10. Conclusion
By implementing this automated Chinese translator for Line built with n8n and OpenRouter.ai, you’ve transformed manual, error-prone translation tasks into instant, multi-format responses. Whether text or images, you’ve created an interactive language assistant that saves hours daily and delights your Line followers with precise Chinese characters, pinyin, and English breakdowns.
Next, consider expanding this workflow to handle spoken audio translations, add more languages or integrate with other messaging platforms to reach wider audiences.
You’ve just taken an important step in blending AI and chatbots to modernize language learning and communication—great job!