welfare_lottery
Conditional Lottery
Feature Overview
This module primarily handles logic related to conditional lotteries. It listens for messages such as lottery start and end notifications, and provides interfaces to retrieve detailed lottery information and draw status. Integrators can customize their own UI based on these event flows.
Initialization and Destruction
Before instantiating and using this module, the SDK must be initialized and configured. For details, see the Reference Documentation.
Online File Import Method
<script src="https://websdk.videocc.net/interactions-receive-sdk/0.24.0/lib/polyv-ir.umd.js"></script>
<script>
const { WelfareLottery } = window.PolyvIRSDK;
</script>
Import Method (Recommended)
import { WelfareLottery } from '@polyv/interactions-receive-sdk';
const welfareLotterySdk = new WelfareLottery();
// 销毁 SDK 实例,清除逻辑
welfareLotterySdk.destroy();
Usage Flow
Listen for the "Lottery Start (START)" event to obtain the latest lottery activity in real time.
After the initiator starts the lottery (please consult after-sales support for details on the initiator), the SDK internally triggers the welfareLotterySdk.events.START event. Integrators can listen for this event to obtain the lottery ID.
welfareLotterySdk.on(welfareLotterySdk.events.START, function(msg) {
console.log(`抽奖开始:`, msg);
});
Call the getPendantList API to retrieve the latest lottery activity (for cases where users enter the chat room after the lottery has started).
welfareLotterySdk.getPendantList().then(data => {
console.info(data);
});
After obtaining the lottery activity ID, call the getWelfareLotteryDetail API to retrieve specific lottery content, which can be used to display prize information, activity time, number of participants, etc.
welfareLotterySdk.getWelfareLotteryDetail().then(data => {
console.info(data);
});
To complete a comment-based lottery, call the sendComment method to automatically send a comment and fulfill the condition.
// comment 关键词
// 自动发送关键词评论,并完成抽奖
welfareLotterySdk.sendComment(comment);
// 外部发言满足关键词,如聊天室内发送关键词评论,并完成抽奖。
if(welfareLotterySdk.isBooleanToCommentLottery(comment)) {
welfareLotterySdk.finishCommentLottery();
}
Call the getTaskCondition API to retrieve the current user's task completion status.
welfareLotterySdk.getTaskCondition().then(data => {
console.info(data);
});
Listen for the "Lottery End (END)" event.
After the initiator ends the lottery (please consult after-sales support for details on the initiator), the SDK internally triggers the welfareLotterySdk.events.END event. Integrators can listen for this event to prepare for displaying results.
welfareLotterySdk.on(welfareLotterySdk.events.END, function(msg) {
console.log(`抽奖结束:`, msg);
});
After the lottery activity ends, call the getWelfareLotteryDetail API to retrieve the list of winning user IDs. Based on this list, determine whether the current user has won.
welfareLotterySdk.getWelfareLotteryDetail().then(data => {
// 从data.winnerIds判断当前用户是否中奖
// ...
});
Retrieve the personal winning list via getLotteryWinList.
welfareLotterySdk.getLotteryWinList({
keyword,
pageSize,
pageNumber
}).then(data => {
console.info(data);
});
Winners call the getLotteryPrize API to retrieve prize details. The prize claim method and redemption code will be returned in this API.
welfareLotterySdk.getLotteryPrize().then(data => {
console.info(data);
});
If the prize claim method is submitting a form, use the submitInfo API to submit the winner's information.
welfareLotterySdk.submitInfo({
lotteryId,
winnerCode,
receiveInfo: [
{
field,
value
}
],
}).then(data => {
console.info(data);
});
Notes
- If external invitations are enabled and the environment is mobile, the lottery animation will no longer be displayed, and the results will be shown directly.
- If the conditional lottery SDK is no longer needed, call the
destroymethod of the SDK instance to destroy it.
