Mon 21 Jul 22:43:21 CEST 2025
This commit is contained in:
parent
83437850dd
commit
768895c4b2
49
js/ui/botui/examples/git-stars-bot/stars-bot.js
Normal file
49
js/ui/botui/examples/git-stars-bot/stars-bot.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
var loadingMsgIndex,
|
||||
botui = new BotUI('stars-bot'),
|
||||
API = 'https://api.github.com/repos/';
|
||||
|
||||
function sendXHR(repo, cb) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var self = this;
|
||||
xhr.open('GET', API + repo);
|
||||
xhr.onload = function () {
|
||||
var res = JSON.parse(xhr.responseText)
|
||||
cb(res.stargazers_count);
|
||||
}
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function init() {
|
||||
botui.message
|
||||
.bot({
|
||||
delay: 1000,
|
||||
content: 'Enter the repo name to see how many stars it have:'
|
||||
})
|
||||
.then(function () {
|
||||
return botui.action.text({
|
||||
delay: 1000,
|
||||
action: {
|
||||
value: 'moinism/botui',
|
||||
placeholder: 'moinism/botui'
|
||||
}
|
||||
})
|
||||
}).then(function (res) {
|
||||
loadingMsgIndex = botui.message.bot({
|
||||
delay: 200,
|
||||
loading: true
|
||||
}).then(function (index) {
|
||||
loadingMsgIndex = index;
|
||||
sendXHR(res.value, showStars)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function showStars(stars) {
|
||||
botui.message
|
||||
.update(loadingMsgIndex, {
|
||||
content: 'it has !(star) ' + (stars || "0") + ' stars.'
|
||||
})
|
||||
.then(init); // ask again for repo. Keep in loop.
|
||||
}
|
||||
|
||||
init();
|
Loading…
Reference in New Issue
Block a user