line / line-bot-sdk-php Goto Github PK
View Code? Open in Web Editor NEWLINE Messaging API SDK for PHP
Home Page: https://packagist.org/packages/linecorp/line-bot-sdk
License: Apache License 2.0
LINE Messaging API SDK for PHP
Home Page: https://packagist.org/packages/linecorp/line-bot-sdk
License: Apache License 2.0
let's I want to use this emoticon 0x100005
, how to do that in PHP ?
Hi,
I have a business connect account but my channel access token have just expired.
I tried to reissue the access token followed this doc https://developers.line.me/restful-api/overview#refresh_token but I got this result
{
"statusCode": "411",
"statusMessage": "TOKEN_INVALID_TOKEN"
}
Do you have any idea?
i've just used VideoMessageBuilder for reply
$p2 = "https://url/1.mp4";
$p1 = "https://url/1.jpg";
$this->bot->replyMessage($replyToken, new VideoMessageBuilder($p2,$p1));
it success. i cant download the video and forward it. is there any information i missed about this feature?
The current version of Guzzle is 6.2 and it has numerous incompatible API changes. The problem with PHP composer is that you can only install one version of a package and by installing this one, it is not possible to install any package written against Guzzle 6.
if(preg_match('(\bflip card\b)', $text) != 0 || preg_match('(\bflip a card\b)', $text) != 0){
$image = base_url("/asset/card/".$this->flip_card().".png");
$card = new \LINE\LINEBot\MessageBuilder\ImageMessageBuilder(
$image,
$image
);
$bot->replyMessage($reply_token, $card);
}
In Phone i could see the images, But in LINE PC the images are not showed and they didn't stop loading
Is this the right place i share this problem here?
hello ... where can I find the file
require DIR . '/../vendor/autoload.php';
thanks for the help
I can not get the attribute message['type']
with method getMessageType()
on the event
object when a user sends a sticker or a non text message. And my server did not record any error. Is this a bug in the SDK or in the API?
はじめまして。
グループチャット時は、
受け取ったメッセージイベントのソースに、ルーム情報が入りますが、
合わせて、ユーザー情報(IDなど)を知る方法はないでしょうか?
よろしくお願いします。
I'm wondering if it's possible since it's not available yet in the current one.
I think it can be done by modifying the tiny version of replyMessage, but i'm still not sure which part should be changed.
Hello and thanks for this great sdk. Please is it possible to check if a combination of Channel Secret and Channel Access Token are valid. Hope my question as well asked. That is, is there an endpoint which requirs say these 2 keys and returns a response wheater they are valid or not?
Regards.
In the chat window it says "Unable to load photo." and a button try again
Here are my code snippet
$imagemapUriActionBuilder = new \LINE\LINEBot\ImagemapActionBuilder\ImagemapUriActionBuilder(
'https://this.is.just.placeholder/',
new \LINE\LINEBot\ImagemapActionBuilder\AreaBuilder(0,0,560,120)
);
$imagemapMessageActionBuilder = new \LINE\LINEBot\ImagemapActionBuilder\ImagemapMessageActionBuilder(
'Some Tag Line',
new \LINE\LINEBot\ImagemapActionBuilder\AreaBuilder(0,120,560,120)
);
$ImageMapMessageBuilder = new \LINE\LINEBot\MessageBuilder\ImagemapMessageBuilder(
'https://this.image.is.working.on.imagemessagebuilder.but.not.here',
'Text to be displayed',
$baseSizeBuilder,
[
$imagemapUriActionBuilder,
$imagemapMessageActionBuilder
]
);
$response = $bot->replyMessage($event->getReplyToken(), $ImageMapMessageBuilder);```
Did I miss something?
The url is working just fine
in /example/SendingSample/setting.php
return [
'channelId' => 'xxx', // I see
'channelSecret' => 'xxx', // I see
'channelMid' => 'xxx', // I see
'targetMid' => '???', // here I don't know, where I can found it?
];
I tried push message with image, I noticed images from some domain display properly but some domain (with HTTPS) cannot display properly (show (i) icon instead), anyone know, what is the cause of this problem?
Hi,
I am not sure this is right place to raise my issue regarding Webhook config. Currently integrating Line app using PHP. Under Message API, when configuring sub domain path in Webhook it throws an error such as "could not connect SSL" though domain is SSL certificate. But if give Top level domain it accepts and Line gives responses whenever user any activities on official account.
And also please suggest the right channel to communicate Line Tech team.
I have try about send multiple message using same object like text, but how we sent multiple message with different object. i use oop version.
Hello, i have little problem on user information, I have found some LINE BOT tutorial how to get the user name, but i always found they using LINE_CHANNEL_MID.
Unfortunately i don't have LINE_CHANNEL_MID in my BOT basic information. I only have Channel ID, Channel Secret, And Channel Access token. I don't know why i don't have it.
But all is find, i can get the text from user, get the user_id, room_id or group_id and i could send reply message to the user.
` $bot = new \LINE\LINEBot(
new \LINE\LINEBot\HTTPClient\CurlHTTPClient('channel_access_token'),
['channelSecret' => 'channel_secret']
);
$signature = $_SERVER["HTTP_".\LINE\LINEBot\Constant\HTTPHeader::LINE_SIGNATURE];
$body = file_get_contents("php://input");
$events = $bot->parseEventRequest($body, $signature);
foreach ($events as $event) {
if ($event instanceof \LINE\LINEBot\Event\MessageEvent\TextMessage) {
$reply_token = $event->getReplyToken();
$user_id = $event->getUserId();
//i want trying to get the user information like the user name, so i could send the name as reply message
}
}'
could i get the user information by the user_id?
thank you
i need to get the user list, who is reading the message but i didnt find any tutorial for this. Can you help me?
Rel: #32
Is it possible or does getProfile
function only works with user ID ?
I tried inputting group ID in getProfile
function but it doesn't return anything.
Document reply-message in https://devdocs.line.me/ja/#reply-message
"Message to be sent Up to 5"
How to use '\LINEBot\replyMessage' multiple messages?
I read the document (https://devdocs.line.me/ja/#template-message) about postback. This reads it can send both of data and text at the same time.
But, as I saw the class of PostbackTemplateActionBuilder, it can't send text.
class PostbackTemplateActionBuilder implements TemplateActionBuilder
{
/** @var string */
private $label;
/** @var string */
private $data;
/**
* PostbackAction constructor.
*
* @param string $label Label of action.
* @param string $data Data of postback.
*/
public function __construct($label, $data)
{
$this->label = $label;
$this->data = $data;
}
/**
* Builds postback action structure.
*
* @return array Built postback action structure.
*/
public function buildTemplateAction()
{
return [
'type' => ActionType::POSTBACK,
'label' => $this->label,
'data' => $this->data,
];
}
}
When I sent just one emoji, I got this from the callback
{
...
"content": {
"toType": 1,
"createdTime": 1461747374328,
"from": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"location": null,
"id": "4232655156792",
"to": [
"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
],
"text": null,
"contentMetadata": {
"STKTXT": "[]",
"STKVER": "2",
"STKID": "47977",
"STKPKGID": "2000000"
},
"deliveredTime": 0,
"contentType": 8,
"seq": null
}
...
}
The result likes the result from sticker.
But when I sent multiple emoji, I got this
{
"content": {
"toType": 1,
"createdTime": 1461747388268,
"from": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"location": null,
"id": "4232656103122",
"to": [
"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
],
**"text": "(hahaha)(please!)(shocked)",**
"contentMetadata": {
"EMTVER": "4"
},
"deliveredTime": 0,
"contentType": 1,
"seq": null
}
}
This result came with the text content type.
Is this by design or it will be updated?
Thank you
i have installed echobot, but i'm get notice page not found.
I have 2 MIDs for send data in one time.
I write code "to":["xxxx,xxxx"] and "to":["xxx","xxx"] not work.
You can example for me?
Thankyou.
When retrieving the content of a message (e.g. an image) it can not be determined, using the SDK, whether the image (or any other content) is of a given mime type (e.g. image/jpeg
, image/png
). This makes it hard to actually write the file to disk with the right extension.
Here's some example code that shows the issue:
// $message is an instance of ImageMessage
$line = new LINEBot(new CurlHTTPClient('<token>'), [
'channelSecret' => '<secret>'
]);
$response = $line->getMessageContent($message->getMessageId());
if ($response->isSucceeded()) {
// I can get the binary body with $response->getRawBody()
// but I can't get the mime type, nor the extension.
$filePath = tmpfile() . '<extension?>';
file_put_contents($filePath, $response->getRawBody());
}
There's various solutions to the issue:
HTTPClient
with a getMimeType()
method, but since it's a private member of the LINEBot
class, I can't access this in the code.Response
class, but that just seems to much overwriting already.ImageMessage
class (if sent back from the API)In the KitchenSink
example all images are written as .jpeg
so it could be that all images are actually JPEG's, but that is not documented.
Could someone provide some guidance to the above? I can make a pull request based on suggestion and/or feedback, but looking to see what the right way to go is.
$res = $bot->sendText(['TARGET_MID'], 'Message'); // How to get the first param value?
Is there any chance you can remove or add users in the group having their id or other unique data?
From example code :
$textMessageBuilder = new \LINE\LINEBot\MessageBuilder\TextMessageBuilder('hello');
$response = $bot->replyMessage('<reply token>', $textMessageBuilder);
if ($response->isSecceeded()) {
echo 'Succeeded!';
return;
}
I want to execute example code. But php console show the error message for me.
Please check this function name exist or not.
Thank you.
PostbackTemplateActionBuilder.php
public function buildTemplateAction(){
return [
'type' => ActionType::POSTBACK,
'label' => $this->label,
'data.json' => $this->data
];
}
will work if replace data.json with data
PostbackEvent.php
public function getPostbackData(){
return $this->event['postback']['data.json'];
}
will work if replace data.json with data
i have installed echobot on my localhost. when i access to public folder, its return page not found
How to do that i tried with ('\n') but it fail,
or is there anything I can do to make a new bubble chat for reply user message
example 1 , new line
Hello,
I am bot
example 2, new bubble
-----bubble 1
Hello
-----bubble 2
I am bot
Hello, im using codeigniter to use BOT, and i want trying to use session as key for reply message. So everytime my bot has reply a message the last session should be updated.
I do this because, im trying to prevent to reply same text with same keyword
heri is my code :
$bot = new \LINE\LINEBot(
new \LINE\LINEBot\HTTPClient\CurlHTTPClient($reply_token),
['channelSecret' => $secret]
);
if(isset( $_SESSION['count']){
$count = $_SESSION['count'];
}else{
$count = 0
}
$signature = $_SERVER["HTTP_".\LINE\LINEBot\Constant\HTTPHeader::LINE_SIGNATURE];
$body = file_get_contents("php://input");
$events = $bot->parseEventRequest($body, $signature);
foreach ($events as $event) {
if ($event instanceof \LINE\LINEBot\Event\MessageEvent\TextMessage) {
$reply_token = $event->getReplyToken();
$text = strtolower($event->getText());
if($text == 'hi'){
$reply_message = $items[array_rand($items)];
$bot->replyText($reply_token, $reply_message);
}else if ($text == 'makanya belajar'){
$reply_message = $teach[array_rand($teach)];
$bot->replyText($reply_token, $reply_message);
}else if($text == 'vin' || $text == 'zi' || 'vinzi'){
if($count != 6){
$_SESSION['count'] += 1;
$reply_message = $name[$count];
$bot->replyText($reply_token, $reply_message);
}else{
$reply_message = $name[$count];
unset($_SESSION['count']);
$bot->replyText($reply_token, $reply_message);
}
}
}
}
before i tried to use it, i try to var_dump
all the session and refresh my callback funtion, i could get the result what i want. but after i tried chat my bot, he always send the same text. thak you
I use \r\n, but not working.
Hi,
I am able to send a MultiMessage with a text followed by an Imagemap.
But, when I try to send an Imagemap and followed by a text. I got only the Imagemap and the text never showed up.
Did I missed something?
I am trying to upgrade my BOT to the 1.0 SDK. The problem is that I receive calls in the old format. There is a "HTTP_X_LINE_CHANNELSIGNATURE" header only and the body JSON is the old format.
How do I switch my channel to use the new SDK? I can configure it at https://developers.line.me but don't see anything. I could not find any documentation about that either.
got 411 bad request from server.
add request body can fix the problem.
LINEBot.php:137
return $this->httpClient->post($this->endpointBase . '/v2/bot/group/' . urlencode($groupId) . '/leave', ["dummy"=>"dummy"]);
LINEBot.php:148
return $this->httpClient->post($this->endpointBase . '/v2/bot/room/' . urlencode($roomId) . '/leave', ["dummy"=>"dummy"]);
I read the callback example from
https://github.com/line/line-bot-sdk-php/blob/master/examples/EchoBot/src/routes.php.
Could you tell me how to get the url of sticker?
Thank you in advance
Dear Admin,
I have a suggestion to set default value for parameter on TextMessageBuilder
class TextMessageBuilder implements MessageBuilder { ... public function __construct($text, array $extraTexts = array()) ... }
i think $extraTexts is an optional parameter, and it made error when someone forget to set value for it.
When receiving a message from a room, only the room ID is given as the source of the message. How do I look up the user ID of the sender?
i just installed kitchen sink on hosting and have configured webhook to callback. when i try to chat from phone 'profile', line bot cant reply. i just want to learn event handler especially text message
Hi Support,
Sorry bug in my side
i try to use this sdk in localhost, but i getting error SSL certificate problem: unable to get local issuer certificate.
$imageUrl = "http://1.bp.blogspot.com/-9izs08OyhuU/VeaBPrheKHI/AAAAAAAACMQ/uUN7ELsMw_o/s1600/Gambar-Konyol-Lucu-Gila-Unik-Aneh-34.jpg";
$carouselTemplateBuilder = new CarouselTemplateBuilder([
new CarouselColumnTemplateBuilder('foo', 'bar', $imageUrl, [
new UriTemplateActionBuilder('Go to line.me', 'https://line.me'),
new PostbackTemplateActionBuilder('Buy', 'action=buy&itemid=123'),
]),
new CarouselColumnTemplateBuilder('buz', 'qux', $imageUrl, [
new PostbackTemplateActionBuilder('Add to cart', 'action=add&itemid=123'),
new MessageTemplateActionBuilder('Say message', 'hello hello'),
]),
]);
file_put_contents('php://stderr', 'MessageBuilder: '.json_encode($carouselTemplateBuilder));
$messageBuilder = new TemplateMessageBuilder('Button alt text', $carouselTemplateBuilder);
$this->bot->pushMessage($wong, $messageBuilder);
This is part of my code... I want send a Carousel but the bot isn't reply.
There is a slight error in API Reference ( [https://devdocs.line.me/en/?php#reply-message]("Push Message" section) ):
$httpClient = new \LINE\LINEBot\HTTPClient\CurlHTTPClient('<channel access token>');
$bot = new \LINE\LINEBot($httpClient, ['channelSecret' => '<channel secret>']);
$textMessageBuilder = new \LINE\LINEBot\MessageBuilder\TextMessageBuilder('hello');
$response = $bot->pushMessage('<to>', $textMessageBuilder);
echo $response->getHTTPStatus() . ' ' . $response->getBody();
After I tried this code, i got error message say $response has no 'getBody' method,
I think we should call 'getRawBody' method, not 'getBody'.
\n or \n\r not working anymore in new API.
Image message sent successfully (200 OK) but image is not displayed properly in chat window
203.104.146.152 - - [20/Nov/2016:13:28:16 +0700] "POST /callback/line/official HTTP/1.1" 200 12 "-" "LineBotWebhook/1.0"
203.104.146.152 - - [20/Nov/2016:13:28:21 +0700] "POST /callback/line/official HTTP/1.1" 200 12 "-" "LineBotWebhook/1.0"
203.104.146.152 - - [20/Nov/2016:13:28:24 +0700] "POST /callback/line/official HTTP/1.1" 200 12 "-" "LineBotWebhook/1.0"
203.104.146.152 - - [20/Nov/2016:13:31:39 +0700] "POST /callback/line/official HTTP/1.1" 200 12 "-" "LineBotWebhook/1.0"
203.104.146.152 - - [20/Nov/2016:13:34:57 +0700] "POST /callback/line/official HTTP/1.1" 200 12 "-" "LineBotWebhook/1.0"
https://line.yefta.com/images/baka.jpg
can we get user id or something data about coupon feature in LINE?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.