###前提・実現したいこと
PHPを使ってのLine Bot作成に当たってtemplate message(ボタンやConfirmメッセージなど)のテストを行いたいと思っています。
しかし、以下のようなエラーが出ています。
###発生している問題・エラーメッセージ
PHP Fatal error: Uncaught Error: Call to a member function buildTemplateAction() on array in /app/vendor/linecorp/line-bot-sdk/src/LINEBot/MessageBuilder/TemplateBuilder/ConfirmTemplateBuilder.php:65
###該当のソースコード
PHP
1// Confirmテンプレートを使うためのメソッドです。 2function replyConfirmTemplate($bot, $replyToken, $alternativeText, $text, ...$actions) { 3 $actionArray = []; 4 foreach ($actions as $value) { 5 array_push($actionArray, $value); 6 } 7 $builder = new \LINE\LINEBot\MessageBuilder\TemplateMessageBuilder( 8 $alternativeText, 9 // Confirmテンプレートの引数はテキスト、アクションの配列 10 new \LINE\LINEBot\MessageBuilder\TemplateBuilder\ConfirmTemplateBuilder($text, $actionArray) 11 ); 12 $response = $bot->replyMessage($replyToken, $builder); 13 if (!$response->isSucceeded()) { 14 error_log('Failed!' . $response->getHTTPStatus . ' ' . $response->getRawBody()); 15 } 16 }
PHP
1// 上記メソッドを呼び出しているところです。 2function __construct() { 3 4 $json_string = file_get_contents('php://input'); 5 $jsonObj = json_decode($json_string); 6 $this->userId = $jsonObj->{"events"}[0]->{"source"}->{"userId"}; 7 $this->replyToken = $jsonObj->{"events"}[0]->{"replyToken"}; 8 9 $this->httpClient = new \LINE\LINEBot\HTTPClient\CurlHTTPClient($this->token); 10 $this->bot = new \LINE\LINEBot($this->httpClient, ['channelSecret' => $this->secret]); 11 12 $this->replyConfirmTemplate( 13 $this->bot, 14 $this->replyToken, 15 "test", 16 "test", 17 [ 18 [ 19 "type" => "message", 20 "label" => "Yes", 21 "text" => "Yes", 22 ], 23 [ 24 "type" => "message", 25 "label" => "No", 26 "text" => "No", 27 ], 28 ] 29 ); 30}
###試したこと
TemplateMessageをつかわずに、おうむ返しをするだけのBotなら動くので、Tokenなどの認証に問題はありません。
Herokuにデプロイしているのでheroku logs -t
でログを見て、第5引数のArrayを二つに分けてみたりしましたが動きません。
###補足情報(言語/FW/ツール等のバージョンなど)
line公式のmessaging api用sdk
https://github.com/line/line-bot-sdk-php
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/12 14:54