Comparing version 2.0.4-rc.1 to 2.0.4-rc.2
@@ -6,3 +6,3 @@ import { Context } from './context'; | ||
import { InputMediaUnion, TelegramInlineKeyboardMarkup, TelegramMessage } from '../interfaces'; | ||
import { AttachmentType, ChatAction, ChatType, DiceEmoji, EntityType, MessageEventName, Optional, TelegramInputFile } from '../types'; | ||
import { AttachmentType, ChatAction, ChatType, DiceEmoji, EntityType, MessageEventName, Optional, TelegramInputFile, UpdateName } from '../types'; | ||
import { EditMessageCaptionParams, EditMessageLiveLocationParams, EditMessageMediaParams, EditMessageReplyMarkupParams, EditMessageTextParams, SendAnimationParams, SendAudioParams, SendContactParams, SendDiceParams, SendDocumentParams, SendInvoiceParams, SendLocationParams, SendMediaGroupParams, SendMessageParams, SendPhotoParams, SendPollParams, SendStickerParams, SendVenueParams, SendVideoNoteParams, SendVideoParams, SendVoiceParams, StopMessageLiveLocationParams, StopPollParams } from '../methods'; | ||
@@ -15,3 +15,3 @@ import { Poll } from '../updates/'; | ||
payload: TelegramMessage; | ||
constructor(telegram: Telegram, update: TelegramMessage); | ||
constructor(telegram: Telegram, update: TelegramMessage, type?: UpdateName); | ||
/** Sender's ID */ | ||
@@ -18,0 +18,0 @@ get senderId(): number | undefined; |
@@ -14,4 +14,4 @@ "use strict"; | ||
class MessageContext extends context_1.Context { | ||
constructor(telegram, update) { | ||
super(telegram, 'message'); | ||
constructor(telegram, update, type = 'message') { | ||
super(telegram, type); | ||
this.payload = update; | ||
@@ -18,0 +18,0 @@ } |
@@ -146,2 +146,3 @@ "use strict"; | ||
formValue = value; | ||
const isUrl = isURL.test(value); | ||
form.append(key, formValue); | ||
@@ -151,2 +152,5 @@ if (options.method === 'sendMediaGroup') { | ||
} | ||
else { | ||
keys.push(`${isUrl ? 'url' : 'fileId'}:${value}`); | ||
} | ||
} | ||
@@ -168,6 +172,9 @@ }); | ||
let mediaValue = keys.map((key, index) => { | ||
const { key: _, value: elementValue, ...valueContext } = values[index]; | ||
const { key: elementKey, value: elementValue, ...valueContext } = values[index]; | ||
const [keyType] = key.split(':'); | ||
const isUrl = keyType === 'url'; | ||
const isFileId = keyType === 'fileId'; | ||
return { | ||
type: key.split(':')[0], | ||
media: isURL.test(elementValue.toString()) ? elementValue : `attach://${key}`, | ||
type: (isUrl || isFileId) ? elementKey : keyType, | ||
media: (isUrl || isFileId) ? elementValue : `attach://${key}`, | ||
...valueContext | ||
@@ -174,0 +181,0 @@ }; |
@@ -184,2 +184,5 @@ "use strict"; | ||
} | ||
if (!this.telegram.options.token) { | ||
debug('Bot token is not set. Perhaps you forgot to set it?'); | ||
} | ||
debug('Fetching bot data...'); | ||
@@ -241,2 +244,3 @@ const bot = new user_1.User(await this.telegram.api.getMe()); | ||
let UpdateContext = events[type]; | ||
debug('Event type:', type); | ||
if (!UpdateContext) { | ||
@@ -246,5 +250,5 @@ debug(`Unsupported context type ${type}`); | ||
} | ||
let context = new UpdateContext(this.telegram, update[type]); | ||
let context = new UpdateContext(this.telegram, update[type], type); | ||
const isEvent = context.isEvent === true && context.eventType !== undefined; | ||
debug('is event?', isEvent); | ||
debug('Is event?', isEvent); | ||
if (isEvent) { | ||
@@ -277,3 +281,3 @@ UpdateContext = events[context.eventType]; | ||
try { | ||
update = typeof reqBody !== 'object' ? await helpers_1.parseRequestJSON(req) : reqBody; | ||
update = typeof reqBody === 'object' ? reqBody : await helpers_1.parseRequestJSON(req); | ||
} | ||
@@ -280,0 +284,0 @@ catch (error) { |
{ | ||
"name": "puregram", | ||
"version": "2.0.4-rc.1", | ||
"version": "2.0.4-rc.2", | ||
"description": "Powerful Node.js package written on TypeScript that allows you to work with Telegram API", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
@@ -54,3 +54,3 @@ <p align='center'> | ||
## Example usage | ||
## Polling example | ||
@@ -64,2 +64,3 @@ ```js | ||
// Message received | ||
telegram.updates.on( | ||
@@ -70,2 +71,3 @@ 'message', | ||
// Inline button pressed | ||
telegram.updates.on( | ||
@@ -83,4 +85,28 @@ 'callback_query', | ||
[🤖 Click to see more examples!](https://github.com/nitreojs/puregram/tree/master/docs/examples) | ||
## Webhook example (express) | ||
```js | ||
import express from 'express'; | ||
import { Telegram } from 'puregram'; | ||
const telegram = new Telegram({ | ||
token: process.env.TOKEN | ||
}); | ||
const app = express(); | ||
app.use(bodyParser.json()); | ||
app.use(telegram.updates.getWebhookMiddleware()); | ||
telegram.updates.on( | ||
'message', | ||
(context) => context.send('Hello, World!') | ||
); | ||
// Available ports: 80, 88, 443, 8443 | ||
app.listen(443, () => console.log('Webhook started handling!')); | ||
``` | ||
[**🤖 Click to see more examples!**](https://github.com/nitreojs/puregram/tree/master/docs/examples) | ||
## Community | ||
@@ -87,0 +113,0 @@ |
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
782681
20514
119