Skip to content

Instantly share code, notes, and snippets.

@ilyasozkurt
Created September 24, 2021 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyasozkurt/4717e6f8ccde8431bbc8444682bf9ab0 to your computer and use it in GitHub Desktop.
Save ilyasozkurt/4717e6f8ccde8431bbc8444682bf9ab0 to your computer and use it in GitHub Desktop.
var MESSAGE = '';
var stop_processing = false;
var script = document.createElement('script');
script.src = "https://code.jquery.com/jquery-3.4.1.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
function parseUserKey() {
var user_locale_key = null;
for (var i = 0; i < Object.keys(localStorage).length; i++) {
var the_key = Object.keys(localStorage)[i];
if (the_key.search("comHBUser") >= 0) {
user_locale_key = the_key;
}
}
return user_locale_key;
}
function getToken() {
var user_data = JSON.parse(localStorage.getItem(parseUserKey()));
return user_data.token;
}
script.addEventListener("load", function () {
$.ajax({
url: 'https://cloudtalk.hubilo.com/api/v1/app/web_statecall',
type: 'post',
dataType: 'json',
processData: false,
headers: {
'devicetype': 'WEB',
},
data: '{"url":"' + window.location.hostname + '","source":"COMMUNITY"}',
contentType: 'application/json; charset=utf-8',
success: function (result) {
var event_id = result.tracking.event_id;
var organiser_id = result.tracking.organiser_id;
var api_key = result.eventSettings.event_key;
for (var i = 0; i < 3; i++) {
if (stop_processing) {
break;
}
setTimeout(function () {
$.ajax({
url: 'https://cloudtalk.hubilo.com/api/v1/app/paginate_attendee_list_v2',
type: 'post',
dataType: 'json',
processData: false,
data: '{"current_page":"' + i + '","isPaginate":1,"sort":1,"input":"","filter":"0,0,0","limit":15,"event_id":' + event_id + ',"organiser_id":' + organiser_id + ',"api_key":"' + api_key + '","access_token":"' + getToken() + '","app_version":"1.0.0","device_type":"WEB","userProfileFields":{}}',
contentType: 'application/json; charset=utf-8',
success: function (data) {
$.each(data.data.attendees, function (index, attendee) {
setTimeout(function () {
$.ajax({
url: 'https://cloudtalk.hubilo.com/api/v1/app/view_profile_v2',
type: 'post',
dataType: 'json',
processData: false,
data: '{"access_token": "' + getToken() + '","event_id":' + event_id + ',"organiser_id":' + organiser_id + ',"api_key":"' + api_key + '","app_version":"1.0.0","device_type":"WEB","info":"' + MESSAGE + '","target":"' + attendee._id + '"}',
contentType: 'application/json; charset=utf-8',
success: function (result) {
console.info(attendee.user_name + ' message sent');
},
error: function (error) {
console.error(error);
}
});
}, 100)
})
},
error: function (error) {
console.error(error + '. And Stopped.');
stop_processing = true;
}
});
}, 200);
}
},
error: function (error) {
console.error(error);
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment