Discourse Gamificationを1年前にリリースして以来、ロードマップで最も要望の多かった機能の1つが、Discourse Gamificationを外部のゲーミフィケーションシステムと統合する機能でした。例は多数あります。
-
企業における既存のゲーミフィケーションプログラムとの統合
-
IRLイベントや、コミュニティの顧客であること、製品の購入など、Discourse外で発生するイベントに対してポイントを付与する機能。
-
ユーザーがポイントを景品、製品、特典と交換できるようにする機能
本日、プラグインの1周年記念に合わせて、カスタムのスコアリングイベントを処理するための完全なAPIにより、上記すべてが可能になりました
。
この新しいシステムにより、管理者は次のことができるようになります。
-
ユーザーにカスタムスコアイベントを付与する
-
交換やペナルティのイベントに対応するため、ユーザーにマイナスのスコアイベントを付与する
-
以前作成されたカスタムイベントを更新および一覧表示する
API
API経由で付与されたポイントがユーザーの総合スコアに反映されるまでには、現在の日付で作成されたイベントの場合は最大10分、過去10日間に作成されたイベントの場合は最大24時間かかります。過去10日より前の日付で作成されたイベントについては、バックフィル(backfill)のrakeタスクを実行する必要があります。
現在、3つの異なるAPIエンドポイントがあります。
イベントの一覧表示
curl https://\u003cexample_url\u003e/admin/plugins/gamification/score_events.json \
-H 'API-Key: \u003capi_key_here\u003e' \
-H 'API-Username: \u003capi_username_here\u003e'
特定のユーザーまたは日付のイベントを一覧表示することもできます。
curl https://\u003cexample_url\u003e/admin/plugins/gamification/score_events.json?user_id=1\u0026date=2023-05-01 \
-H 'API-Key: \u003capi_key_here\u003e' \
-H 'API-Username: \u003capi_username_here\u003e'
イベントの作成
curl -X POST https://\u003cexample_url\u003e/admin/plugins/gamification/score_events.json \
-H 'API-Key: \u003capi_key_here\u003e' \
-H 'API-Username: \u003capi_username_here\u003e' \
-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"
イベントの更新
curl -L -X PUT https://\u003cexample_url\u003e/admin/plugins/gamification/score_events.json?id=6 \
-H 'API-Key: \u003capi_key_here\u003e' \
-H 'API-Username: \u003capi_username_here\u003e' \
-H "Content-Type: application/json" \
-d '{
"user_id": 11,
"date": "2023-04-15",
"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"
