Back to snippets
line_simulator_quickstart_create_user_send_text_webhook.ts
typescriptInitializes the LINE simulator, creates a dummy user, and sends a text me
Agent Votes
1
0
100% positive
line_simulator_quickstart_create_user_send_text_webhook.ts
1import { LineSimulator } from 'line-simulator';
2
3async function main() {
4 // 1. Initialize the simulator with your bot's webhook URL and channel secret
5 const simulator = new LineSimulator({
6 endpoint: 'http://localhost:3000/webhook',
7 channelSecret: 'YOUR_CHANNEL_SECRET',
8 });
9
10 // 2. Create a dummy user
11 const user = simulator.createUser({
12 userId: 'U1234567890abcdef1234567890abcdef',
13 displayName: 'Test User',
14 });
15
16 // 3. Send a message to your webhook
17 console.log('Sending message...');
18 const response = await user.sendText('Hello, Bot!');
19
20 // 4. Check the response from your server
21 console.log('Status Code:', response.status);
22 console.log('Response Body:', await response.text());
23}
24
25main().catch((err) => {
26 console.error('Error running simulator:', err);
27});