Discourse Gamificationを1年前にローンチして以来、私たちのロードマップで最もリクエストの多い機能の一つは、Discourse Gamificationを外部のゲーミフィケーションシステムと統合できるようにすることでした。例は数多くあります。
- 企業内の既存のゲーミフィケーションプログラムとの統合
- Discourse 以外のイベント(オフラインイベントや、コミュニティでの顧客としての活動、製品の購入など)に対してポイントが付与される機能
- ユーザーがポイントをグッズ、製品、または特典と交換できる機能
本日、プラグインの1周年記念に合わせて、カスタムスコアイベントを処理するための完全なAPIを備え、上記のすべてを可能にしました
。
この新しいシステムにより、管理者は以下のことができます。
- ユーザーにカスタムスコアイベントを付与
- 交換やペナルティイベントに対応するため、負のスコアイベントをユーザーに付与
- 以前に作成されたカスタムイベントの更新と一覧表示
API
APIを通じて付与されたポイントは、現在の日付で作成されたイベントの場合、ユーザーの総合スコアに反映されるまでに最大1時間、過去10日以内に作成されたイベントの場合は最大24時間かかる場合があります。10日以上前の日付でイベントが作成された場合は、管理者ゲーミフィケーションUIのスコアの再計算ボタンを使用するか、以下のバックフィル 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"
