Skip to content

Instantly share code, notes, and snippets.

@yangshun yangshun/telegram.js
Last active Jan 26, 2017

Embed
What would you like to do?
// Name animater
var name = 'Yang.Shun.Tay.';
setInterval(function () {
name = name.substring(1) + name.charAt(0);
var flags = (1 << 0) | (1 << 1);
MtpApiManager.invokeApi('account.updateProfile', {
flags: flags,
first_name: name,
last_name: ''
}).then(function (user) {
$scope.error = {}
AppUsersManager.saveApiUser(user)
});
}, 2000);
// Fake setTyping
setInterval(function () {
// Karen
MtpApiManager.invokeApi('messages.setTyping', {
peer: AppPeersManager.getInputPeerByID('30461908'),
action: {_: 'sendMessageTypingAction'}
})['catch'](function (error) {
error.handled = true
});
// Li Kai
MtpApiManager.invokeApi('messages.setTyping', {
peer: AppPeersManager.getInputPeerByID('175097875'),
action: {_: 'sendMessageTypingAction'}
})['catch'](function (error) {
error.handled = true
});
// Yang Shun
MtpApiManager.invokeApi('messages.setTyping', {
peer: AppPeersManager.getInputPeerByID('70259901'),
action: {_: 'sendMessageTypingAction'}
})['catch'](function (error) {
error.handled = true
});
}, 2500);
var sent = {};
// Reply with message when user typing
console.log('update.user_id typing', update.user_id);
var INTERVAL = 30 * 60 * 1000; // 30 minutes between each greeting
if (!sent[update.user_id] || (Date.now() - sent[update.user_id]) > INTERVAL) {
console.log('will reply to', update.user_id);
MtpApiManager.invokeApi('messages.sendMessage', {
flags: 128,
peer: AppPeersManager.getInputPeerByID(update.user_id),
message: 'Hello there (:',
random_id: [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)],
reply_to_msg_id: 0,
entities: []
});
sent[update.user_id] = Date.now();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.