Comparing version 1.0.61 to 1.1.0
@@ -11,5 +11,17 @@ 'use strict' | ||
if (type[0] === 'image') { | ||
const isMedia = (s) => { | ||
switch (s) { | ||
case 'image': | ||
case 'video': | ||
case 'audio': | ||
case 'file': | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
if (isMedia(type[0])) { | ||
att = { | ||
type: 'image', | ||
type: type[0], | ||
payload: { | ||
@@ -70,2 +82,18 @@ url: text | ||
const phone_number = function (title, url) { | ||
if (typeof title !== 'string') { | ||
throw TypeError(`[smsg#phone_number] 'title' must be a string.`) | ||
} | ||
if (typeof url !== 'string') { | ||
throw TypeError(`[smsg#phone_number] 'payload' must be a string.`) | ||
} | ||
return { | ||
title: title, | ||
url: url, | ||
type: 'phone_number' | ||
} | ||
} | ||
const postback = function (title, payload) { | ||
@@ -105,2 +133,26 @@ if (typeof title !== 'string') { | ||
const video = function (url) { | ||
if (typeof url !== 'string') { | ||
throw TypeError(`[smsg#video] 'url' must be a string.`) | ||
} | ||
return _attachment('video', url) | ||
} | ||
const audio = function (url) { | ||
if (typeof url !== 'string') { | ||
throw TypeError(`[smsg#audio] 'url' must be a string.`) | ||
} | ||
return _attachment('audio', url) | ||
} | ||
const file = function (url) { | ||
if (typeof url !== 'string') { | ||
throw TypeError(`[smsg#file] 'url' must be a string.`) | ||
} | ||
return _attachment('file', url) | ||
} | ||
const button_template = function (text, buttons) { | ||
@@ -132,8 +184,12 @@ if (typeof text !== 'string') { | ||
_attachment: _attachment, | ||
audio: audio, | ||
button_template: button_template, | ||
file: file, | ||
generic_template: generic_template, | ||
image: image, | ||
phone_number: phone_number, | ||
postback: postback, | ||
text: text, | ||
video: video, | ||
web_url: web_url | ||
} |
{ | ||
"name": "smsg", | ||
"version": "1.0.61", | ||
"version": "1.1.0", | ||
"description": "A simple library for constructing structured messages for the Messenger Platform Send API.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
16706
389