sportstalk-js v3.0.9
Sportstalk 247 Javascript SDK
Usage
The Sportstalk SDK is a helpful wrapper around the Sportstalk API
The set of SDKs and source (iOS, Android, and JS) is here: https://gitlab.com/sportstalk247/
$ npm install sportstalk-js
You will need to register with SportsTalk and get an API Key in order to use sportstalk functions. it's as simple as:
GETTING STARTED: How to use the SDK
Sportstalk is an EVENT DRIVEN API. When new talk events occur, the SDK will trigger appropriate callbacks, if set. At minimum, you will want to set 5 callbacks:
- onChatStart
- onChatEvent
- onPurgeEvent
- onReaction
- onAdminCommand
See a simple example below:
// first create a client
const client = SportsTalkClient.create({apiKey:'YourApiKeyHere'}, {...EventHandlerConfig});
// you can set the event handlers as part of the factory or with the setEventhandlers method.
client.setEventHandlers({
onChatStart: onPollStart,
onChatEvent: onChatEvent,
onPurgeEvent: onPurge,
onReaction: onReaction,
onAdminCommand: onAdminCommand,
});
// For goals, you can set a default image or send it as part of each goal API call.
client.setDefaultGoalImage("https://res.cloudinary.com/sportstalk247/image/upload/v1575821595/goal_l6ho1d.jpg");
// Set the user, if logged in.
client.setUser({
userid:UserId,
handle:Handle
});
// List rooms, join a room, and then start talking!
client.listRooms().then(function(rooms){
return client.joinRoom(rooms[0]);
}).then(client.startTalk);
...
For use of these events in action, see the demo page: https://www.sportstalk247.com/demo.html
You can also use the client in node.
import { SportsTalkClient } from 'sportstalk-js'
const client = SportsTalkClient.client({apiKey:'YourApiKeyHere'}, {...EventHandlerConfig});
Events Callbacks
Sportstalk uses callback functions to handle events. These callbacks are specified with the EventHandlerConfig
:
export interface EventHandlerConfig {
onChatStart?: Function;
onNetworkResponse?(response: EventResult[]);
onChatEvent?(event: EventResult),
onGoalEvent?(event: EventResult),
onAdEvent?(event: EventResult),
onReply?(event: EventResult),
onReaction?(event:EventResult),
onPurgeEvent?(event:EventResult),
onAdminCommand?(response: ApiResult<Kind.api>),
onHelp?(result:ApiResult<any>),
onNetworkError?: Function
}
The only critical events that you need to handle are onChatEvent
which will be called for each new chat event, onAdminCommand
which will handle messages from administrators, onPurgeEvent
which will be called when purge commands are issued to clear messages that violate content policy.
The easiest way to see how these event works is to see the demo page: https://www.sportstalk247.com/demo.html
Copyright & License
Copyright (c) 2019 Sportstalk247