Skip to content

Commit

Permalink
Fix webhook server certificate
Browse files Browse the repository at this point in the history
Ref #12
  • Loading branch information
kosmodrey committed May 26, 2016
1 parent a7e053c commit d2df45d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions lib/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,17 @@ const methods = {
},

setWebhook(url, certificate) {
let args = !certificate ? [{ url }] :
[null, { url, certificate: fs.readFileSync(certificate) }];
args.unshift('/setWebhook');
return this.request.apply(this, args);
if (certificate) {
const form = {
url,
certificate: {
value: fs.readFileSync(certificate),
options: { filename: 'cert.pem' }
}
};
return this.request('/setWebhook', null, form);
}
return this.request('/setWebhook', { url });
}

};
Expand Down
4 changes: 2 additions & 2 deletions lib/telebot.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class TeleBot {

// Set webhook
if (this.webhook) {
let { url, key } = this.webhook;
let { url, cert } = this.webhook;
if (url) url = `${ url }/${ this.token }`;
return this.setWebhook(url, key).then(x => {
return this.setWebhook(url, cert).then(x => {
console.log(`[bot.webhook] set to "${url}"`);
return webhook.call(this, this, this.webhook);
}).catch(error => {
Expand Down

0 comments on commit d2df45d

Please sign in to comment.