Enabling Socket.IO in frontend:
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
<script>
const socket = io('https://api.dothemath.app'); // URL to backend
socket.on('connect', () => {
socket.emit('send_message', { text: 'Message from the web!' });
});
</script>
Call once per question/session. Calling it again will result in a new thread on Slack.
Name | Type | Required | Description |
---|---|---|---|
studentName | string | * | Nickname of student |
channelId | string | * | Channel ID |
None.
socket.emit('establish_session', {
studentName: 'MyNickName',
channelId: 'C011ENW7TJQ'
});
Get the list of all available Slack channels. Takes a callback which receives an array of channel objects:
None.
Name | Type | Description |
---|---|---|
name | string | Channel name |
id | string | Channel ID |
socket.emit('get_channels', channels => {
channels.forEach(channel => {
console.log(`${channel.id}: ${channel.name}`)
});
});
Name | Type | Required | Description |
---|---|---|---|
text | string | * | Message text |
image | ArrayBuffer |
None.
socket.emit('send_message', { text: 'Message from the web!' });
Reestablishes a previous session/conversation by fetching messages from Slack. Takes a callback which receives username and messages.
Name | Type | Required | Description |
---|---|---|---|
threadId | string | * | Slack Thread Id |
channelId | string | * | Channel ID |
None.
socket.emit('reestablish_session', {
threadId: '1258750862.012300',
channelId: 'C011ENW7ABC'
}, { name, messages} => {
console.log(name);
messages.forEach(message => {
console.log(message);
});
});
Name | Type | Description |
---|---|---|
text | string | Message text |
name | string | Message sender |
avatar | string | Message sender profile image URL |
image | string | Message attached image URL (if there is one) |
socket.on('message', ({text, name}) => {
console.log(`${name}: ${text}`);
});