自从我们一年前推出 Discourse Gamification 以来,路线图中最受请求的功能之一就是能够将 Discourse 游戏化系统与外部游戏化系统集成。示例不胜枚举:
-
与公司现有的游戏化计划集成
-
能够奖励在 Discourse 之外发生的事件的积分,例如线下活动,或在线其他地方的活动,例如成为社区客户或购买产品。
-
允许用户用积分兑换周边商品、产品或福利
今天,恰逢该插件一周年之际,我们通过完整的 API 实现了上述所有功能,以处理自定义计分事件
。
此新系统允许管理员:
-
为用户分配自定义计分事件
-
为用户分配负分事件,以处理兑换或惩罚事件
-
更新和列出之前创建的自定义事件
API
通过 API 奖励的积分,对于使用当前日期创建的事件,最多需要 1 小时才能反映在用户的总积分中;对于过去 10 天内创建的事件,最多需要 24 小时。对于使用 10 天以前的日期创建的事件,您可以使用管理员游戏化界面中的重新计算积分按钮,或运行回填 rake 任务:
rake gamification_scores:backfill_scores_from[YYYY-MM-DD]。
目前共有 3 个不同的 API 端点。
列出事件
返回最多 100 个事件。您可以按 id、user_id 和/或 date 进行筛选。
curl https://<example_url>/admin/plugins/gamification/score_events.json \
-H 'API-Key: <api_key_here>' \
-H 'API-Username: <api_username_here>'
您还可以列出特定用户或特定日期的事件:
curl https://<example_url>/admin/plugins/gamification/score_events.json?user_id=1&date=2023-05-01 \
-H 'API-Key: <api_key_here>' \
-H 'API-Username: <api_username_here>'
创建事件
curl -X POST https://<example_url>/admin/plugins/gamification/score_events.json \
-H 'API-Key: <api_key_here>' \
-H 'API-Username: <api_username_here>' \
-H "Content-Type: application/json" \
-d '{
"user_id": 13,
"date": "2023-04-14",
"points": 15,
"description": "May 2023 Karaoke attendee"
}'
使用 jo 的替代语法:
jo -p user_id="13" date="2023-04-14" points="15" description="May 2023 Karaoke atendee" | curl --json @- -XPOST http://example/admin/plugins/gamification/score_events -H "Api-Key: apikeyhere" -H "Api-Username: system"
更新事件
更新端点需要 id 和 points。您可以选择更新 description。请注意,user_id 和 date 在创建后无法更改。
curl -L -X PUT https://<example_url>/admin/plugins/gamification/score_events.json \
-H 'API-Key: <api_key_here>' \
-H 'API-Username: <api_username_here>' \
-H "Content-Type: application/json" \
-d '{
"id": 6,
"points": 25,
"description": "May 2023 keynote attendee"
}'
使用 jo 的替代语法:
jo -p id="11" points="25" description="May 2023 Karaoke attendee" | curl --json @- -XPUT http://example/admin/plugins/gamification/score_events -H "Api-Key: apikeyhere" -H "Api-Username: system"
