There was no error in receiving the webhook or referencing the groupId.
When I run it against the groupId of a group chat that the bot has unsubscribed from, I get the following error.
{
"message": "Failed to send messages"
}
I created a new channel and enabled webhooks. After setting up the bot to be able to join the group, I registered it as a friend with a QR code and created the group. I was able to send messages to the group chat by pushing to the groupId that I could get at this time.
My lack of knowledge of webhooks may have been the cause of my confusion.
I hope this will be useful for later learners.
After restarting the server several times, I was able to retrieve messages via webhook. When I invited the bot to a group chat, I got the following message.
{
"destination":"{userId}",
"events": [
{
"type": "join",
"webhookEventId": "{webhookEventId}",
"deliveryContext": {
"isRedelivery": true
},
"timestamp": 1654244950948,
"source": {
"type": "group",
"groupId": "{groupId}"
},
"replyToken": "{replyToken}",
"mode": "active"
}
]
}
I believe the groupId shown here is the destination of the push message, but it seems to fail.
curl -L -X POST "https://api.line.me/v2/bot/message/push" -H "Authorization: Bearer {accessToken}" -H "Content-Type: application/json" -H "Content-Type: application/json" -D data-raw "{
\"to\": \"{groupId}\",
\"messages\":
[
{
\"type\" : \"text\",
\"text\" : \"Hello, world!
}
]
}"
The following message is displayed.
{
"message": "Failed to send messages"
}
Do you know why?
@ksyt Thanks for the quick reply.
Is that something that can be retrieved when the bot joins the group chat?
Hmmm...is your webhook not set up properly? On my server I run the following code and observe the response body.
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.post('/', (req, res) => {
console.log(req.body);
res.status(200);
})
app.listen(3000);
On the LINE Developers page, press the "verify" button on the webhook URL, and the following message will appear in the console.
{ destination: '{userId}', events: [] }
I am assuming from this response that the webhook is set up, but the bot's behavior does not output any other message.
Is there anything odd about my behavior?
If your bot (= official account) joins group and get some webhook, it contains group id. See https://developers.line.biz/ja/reference/messaging-api/#source-user.