ini_set('display_errors', 'On'); if( $_REQUEST['hub_challenge']){ echo $_REQUEST['hub_challenge']; } $raw = file_get_contents('php://input'); rewrite('webhooks.txt', "\n\n\n".$raw ."\n\n"); $data = json_decode($raw, true); if( $data['object'] == 'page'){ foreach($data['entry'] as $entry) { foreach($entry['standby'] as $messaging) { rewrite('webhooks.txt', '[sender][id] ='.$messaging['sender']['id']."\n"); rewrite('webhooks.txt', '[message][text] ='.$messaging['message']['text']."\n"); if(!empty($messaging['message']['text'])){ sendText($messaging['sender']['id'], $messaging['message']['text']); } } } } function sendText($sender,$text){ $token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $url = 'https://graph.facebook.com/v2.6/me/messages?access_token='.$token; $data['messaging_type'] = "RESPONSE"; $data['recipient'] = array('id' => $sender); $data['message'] = array('text' => 'Text received, echo: '.$text); echo json_encode($data)."\n"; $options = array( 'http' => array( 'header' => "Content-type: application/json\r\n", 'method' => 'POST', 'content' => json_encode($data) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; } function rewrite($filename, $data) { $filenum=fopen($filename,'a'); //flock($filenum,LOCK_EX); fwrite($filenum,$data); //flock($filenum,LOCK_UN); fclose($filenum); //chmod($filename,0666); } ?>
2019年12月19日 星期四
webhooks程式碼
訂閱:
張貼留言 (Atom)
-
Line提供Python的套件,給Python程式設計者可以使用套件API跟LINE互動,就不需要撰寫太多複雜的程式及JSON傳輸格式。套件是以Flask提供服務,啟動後,就是LINE的Webhook。 下載套件方法: pip install line-bot-sdk...
-
chatbots能同時提供多個使用者服務,節省時間和成本。 chatbots己經成功幫助數百萬人說明他們的健康問題並提供適當的指導 根據病患自己輸入的症狀,幫助歸納出自己的具體疾病 幫助病患參與(了解、決定)自己的治療過程 發送各種重要的提醒通知給病患 ...
沒有留言:
張貼留言