외부 시스템과 Discourse Gamification을 연동하는 방법(포인트 사용 및 지급)

일 년 전 Discourse Gamification을 출시한 이래, 로드맵에서 가장 많이 요청된 기능 중 하나는 외부 게이미피케이션 시스템과 Discourse Gamification을 통합할 수 있도록 하는 것이었습니다. 예를 들어 다음과 같은 경우가 있습니다:

  • 기업 내 기존 게이미피케이션 프로그램과 통합

  • Discourse 외부에서 발생하는 이벤트(예: 오프라인(IRL) 이벤트)나 온라인 다른 곳(예: 커뮤니티 고객, 제품 구매)에서 포인트를 부여할 수 있는 기능

  • 사용자가 포인트를 굿즈, 제품 또는 혜택으로 교환할 수 있는 기능

오늘, 플러그인의 1주년을 맞아 커스텀 스코어링 이벤트를 처리하기 위한 전체 API를 통해 위 모든 기능을 가능하게 했습니다 :tada:.

이 새로운 시스템은 관리자가 다음을 수행할 수 있게 합니다:

  • 사용자에게 커스텀 스코어링 이벤트를 부여

  • 교환 또는 패널티 이벤트를 처리하기 위해 사용자에게 음수 스코어링 이벤트를 부여

  • 이전에 생성된 커스텀 이벤트를 업데이트 및 목록으로 보기

API

:warning: API를 통해 부여된 포인트는 현재 날짜로 생성된 이벤트의 경우 사용자의 전체 점수에 반영되는 데 최대 1시간이 소요되며, 지난 10일 이내에 생성된 이벤트의 경우 최대 24시간이 소요됩니다. 10일 이전 날짜로 생성된 이벤트의 경우, 관리자 게이미피케이션 UI의 Recalculate Scores 버튼을 사용하거나 백필 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"

이벤트 업데이트

업데이트 엔드포인트에는 idpoints가 필요합니다. description은 선택적으로 업데이트할 수 있습니다. 생성 후에는 user_iddate를 변경할 수 없습니다.

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"
29개의 좋아요

Is/will there be a way to do this through the UI?

9개의 좋아요

That’s something I would consider if an Enterprise customer wants to sponsor it.

10개의 좋아요

This is incredible. We’re just in the middle of starting and piloting an ambassador/champions program, and we’ve been using Airtable to monitor webhooks from our different sources (Discourse, GitHub, Ghost) and aggregate our champions program there. I’m excited to check this out and see if it could be used for us to manage/monitor our program and contributions.

It would be great if you could award points to a user group instead of a user. The use case for us as an enterprise customer would be that we essentially want to award points to the company the users work for and aggregate their points for each company. What is the feasibility of something like this?

9개의 좋아요

Ahh I don’t know how to use this :smiling_face_with_tear:
We’re using a business plan.

I wish we could operate this via the UI.

But still, thanks for building this team! Keep up the good work.

5개의 좋아요

That could help to give one-time points within Discourse with Automation plugin?

1개의 좋아요

How does redeeming points work? I see there is an update event that could be used to subtract points from individual events, but that seems like an inefficient way to redeem points.

Also, when attempting to list events in my discourse instance, I get a 404.

GET https://developer.sailpoint.com/discuss/admin/plugins/gamification/score_events.json

404 Not Found
“The requested URL or resource could not be found.”

I have enabled the plugin and can configure it through the UI. Am I missing something to enable the external system API?

1개의 좋아요

It may be my decade of experience working at banks, but the way I envision redeeming points is issuing negative value custom events.

For example, let’s say you have a user who wants to redeem points for a T-Shirt, and that T-Shirt costs 10k points. The flow on your redeeming system would be:

  1. Check if the user has enough points:

    curl https://meta.discourse.org/u/falco.json -s | jq . | grep score
        "gamification_score": 89386,
    
  2. Issue a “point withdraw” event

    jo -p user_id="13" date="2023-04-14" points="-10000" description="T-Shirt Redeem - order #123" | curl --json @- -XPOST http://example/admin/plugins/gamification/score_events -H "Api-Key: apikeyhere" -H "Api-Username: system"
    

You will want to wrap this in a semaphore of some sorts, as this is the text book example of using those, but that is the gist of the proposed workflow.

This is a very recent feature, so let me know if the proposed workflow doesn’t work correctly.

It’s working fine for me, both in the browser and via API. It’s an admin endpoint, so you need to be a logged in admin via browser, or pass API keys like explained in the OP.

3개의 좋아요

Ok, that’s what I was missing. I didn’t realize you could issue negative points. That should work perfectly then.

:man_facepalming: I was using expired credentials. Thanks for confirming anyway.

2개의 좋아요

@Falco

Are there any plans to add scopes to this API? It appears that the only way I can create or update scores is by having an admin API key that has global access. I would love to have a scope that restricts a key to just being able to update scores. This would give me more confidence using this API in automation tools as I wouldn’t have an admin key that can do much more than just update scores.

3개의 좋아요

That’s a good idea, but I personally don’t have the bandwidth to work on this in the near future.

If you are keen on sponsoring this feature, please contact our support channel so we can get you a quote.

3개의 좋아요

Facing the same issue here:

{"errors":["The requested URL or resource could not be found."],"error_type":"not_found"}

That error was caused by

So you want to check yours :wink:

1개의 좋아요

Thanks, I’m also gonna update to latest just in case

Updating to latest worked! ty

1개의 좋아요

I’ve been testing this a bit today. I see the events I can track, though unsure if there is a direct query to view only events by userid. Looking for a way to maybe have an audit log or present to users how they have gained/lost points.

1개의 좋아요

There is something logged in UI when API call get sucess adding points?

Awesome! And I have another suggestion, is it possible to add a feature that enable users to redeem points for subscriptions in the ui interface? And the ability to add a limit to the number of points a user can earn per day on an event ( like create topics).

Thanks!

No, the feature is 100% API based. You can call the “List Events” endpoint to check for events as described in the OP.

3개의 좋아요