Sample Smooch.io PHP webhook


Sample Smooch.io PHP webhook

我有这个PHP webhook页面,我正在为我的样例smooch.io应用程序使用它,请参阅下面。

<?php
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (!$update) {
  // receive wrong update, must not happen
  exit;
}
logf(json_encode($content));
/*curl https://api.smooch.io/v1/appusers/5790bff5237cbc5d00b10a17/conversation/messages '
     -X POST '
     -d '{"text":"Just put some vinegar on it", "role": "appMaker"}' '
     -H 'content-type: application/json' '
     -H 'authorization: Bearer your-jwt'
*/
$parameters["text"] = "Reply from the webhook!";
$parameters["role"] = "appMaker";
$handle = curl_init("https://api.smooch.io/v1/appusers/5790bff5237cbc5d00b10a17/conversation/messages");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($parameters));
curl_setopt($handle, CURLOPT_HTTPHEADER, 
    array("Content-Type: application/json; charset=utf-8","Authorization: Bearer ".MY_JWT)
);
$response = curl_exec($handle);
logf("response: ".$response);
$response = json_decode($response, true);
function logf($str){
    $logf = "smooch.txt";
    $dtnow = date("dmy H:i:s");
    $logfh = fopen($logf, 'a');
    $str = $dtnow." - ".$str."'n";
    fputs($logfh, $str);
    fclose($logfh);
}

我在我记录的响应中得到以下错误

响应:{"error":{"code":"user_not_found","description":"找不到用户"}}

我已经在这里验证了我的签名https://jwt.io/使用smooch.io 提供的凭据

我怀疑是这个{smoochId|userId}值?我刚刚从浏览器的URL中复制了这些随机字符(5790bff5237cbc5d00b10a17),我假设这是我的用户ID。请告知我如何获取smoochID或userID。谢谢

5790bff5237cbc5d00b10a17是您的应用程序id,而不是您的用户id。要获得用户id,您必须首先初始化一个:

http://docs.smooch.io/rest/#init