Comparing version 2.0.0 to 2.0.1
@@ -62,13 +62,105 @@ module.exports = { | ||
messageExtractors: { | ||
text: (message) => message.text, | ||
contact: (message) => message.contact, | ||
location: (message) => message.location, | ||
venue: (message) => message.venue, | ||
voice: (message) => message.voice.file_id, | ||
audio: (message) => message.audio.file_id, | ||
video: (message) => message.video.file_id, | ||
document: (message) => message.document.file_id, | ||
sticker: (message) => message.sticker.file_id, | ||
photo: (message) => message.photo[message.photo.length - 1].file_id | ||
text: (message) => { | ||
var result = {text: message.text} | ||
console.log(message.entities) | ||
message.entities.reverse().forEach((entity) => { | ||
switch (entity.type) { | ||
case 'bold': | ||
result.text = insert(result.text, entity.offset + entity.length, '</b>') | ||
result.text = insert(result.text, entity.offset, '<b>') | ||
break | ||
case 'italic': | ||
result.text = insert(result.text, entity.offset + entity.length, '</i>') | ||
result.text = insert(result.text, entity.offset, '<i>') | ||
break | ||
case 'code': | ||
result.text = insert(result.text, entity.offset + entity.length, '</code>') | ||
result.text = insert(result.text, entity.offset, '<code>') | ||
break | ||
case 'pre': | ||
result.text = insert(result.text, entity.offset + entity.length, '</pre>') | ||
result.text = insert(result.text, entity.offset, '<pre>') | ||
break | ||
case 'text_link': | ||
result.text = insert(result.text, entity.offset + entity.length, '</a>') | ||
result.text = insert(result.text, entity.offset, `<a href="${entity.url}">`) | ||
break | ||
default: | ||
return | ||
} | ||
result.parse_mode = 'HTML' | ||
}) | ||
return result | ||
}, | ||
contact: (message) => { | ||
return { | ||
phone_number: message.contact.phone_number, | ||
first_name: message.contact.first_name, | ||
last_name: message.contact.last_name | ||
} | ||
}, | ||
location: (message) => { | ||
return { | ||
latitude: message.location.latitude, | ||
longitude: message.location.longitude | ||
} | ||
}, | ||
venue: (message) => { | ||
return { | ||
latitude: message.venue.location.latitude, | ||
longitude: message.venue.location.longitude, | ||
title: message.venue.title, | ||
address: message.venue.address, | ||
foursquare_id: message.venue.foursquare_id | ||
} | ||
}, | ||
voice: (message) => { | ||
return { | ||
voice: message.voice.file_id, | ||
duration: message.voice.duration | ||
} | ||
}, | ||
audio: (message) => { | ||
return { | ||
audio: message.audio.file_id, | ||
duration: message.audio.duration, | ||
performer: message.audio.performer, | ||
title: message.audio.title | ||
} | ||
}, | ||
video: (message) => { | ||
return { | ||
video: message.video.file_id, | ||
caption: message.caption, | ||
duration: message.video.duration, | ||
width: message.video.width, | ||
height: message.video.height | ||
} | ||
}, | ||
document: (message) => { | ||
return { | ||
document: message.document.file_id, | ||
caption: message.caption | ||
} | ||
}, | ||
sticker: (message) => { | ||
return { | ||
sticker: message.sticker.file_id | ||
} | ||
}, | ||
photo: (message) => { | ||
return { | ||
photo: message.photo[message.photo.length - 1].file_id, | ||
caption: message.caption | ||
} | ||
} | ||
} | ||
} | ||
function insert (input, index, string) { | ||
if (index > 0) { | ||
return input.substring(0, index) + string + input.substring(index, input.length) | ||
} else { | ||
return string + input | ||
} | ||
} |
@@ -132,7 +132,7 @@ const debug = require('debug')('telegraf:api') | ||
if (message[type]) { | ||
params[type] = platform.messageExtractors[type](message) | ||
params = Object.assign(params, platform.messageExtractors[type](message)) | ||
methodName = platform.copyMethods[type] | ||
} | ||
}) | ||
var opts = Object.assign({chat_id: chatId}, params, extra) | ||
const opts = Object.assign({chat_id: chatId}, params, extra) | ||
return this.sendRequest(methodName, opts) | ||
@@ -139,0 +139,0 @@ } |
{ | ||
"name": "telegraf", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "📢 Modern Telegram bot framework", | ||
@@ -5,0 +5,0 @@ "main": "lib/telegraf.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69065
1328