import { AxiosInstance } from 'axios'; import * as ViberTypes from './ViberTypes'; /** * @see https://developers.viber.com/docs/api/rest-bot-api/#viber-rest-api */ export default class ViberClient { /** * @deprecated Use `new ViberClient(...)` instead. */ static connect(config: ViberTypes.ClientConfig): ViberClient; /** * The underlying axios instance. */ readonly axios: AxiosInstance; /** * The access token used by the client. */ readonly accessToken: string; /** * The sender used by the client. */ private sender; /** * The callback to be called when receiving requests. */ private onRequest?; constructor(config: ViberTypes.ClientConfig); private callAPI; /** * Webhooks * * @see https://viber.github.io/docs/api/rest-bot-api/#webhooks */ /** * Sets a Webhook * * @param url - Account webhook URL to receive callbacks & messages from users. * @param options - The optional parameters. * @param options.eventTypes - Indicates the types of Viber events that the account owner would like to be notified about. Don’t include this parameter in your request to get all events. Possible values: `delivered`, `seen`, `failed`, `subscribed`, `unsubscribed` and `conversation_started`. * @param options.sendName - Indicates whether or not the bot should receive the user name. Default `false`. * @param options.sendPhoto - Indicates whether or not the bot should receive the user photo. Default `false`. * @returns Status * * @see https://developers.viber.com/docs/api/rest-bot-api/#setting-a-webhook * * @example * * ```js * await client.setWebhook('https://4a16faff.ngrok.io/'); * * // Or filter event types using optional parameter * await client.setWebhook('https://4a16faff.ngrok.io/', { * eventTypes: ['delivered', 'seen', 'conversation_started'], * }); * ``` */ setWebhook(url: string, optionsOrEventTypes?: ViberTypes.EventType[] | { eventTypes?: ViberTypes.EventType[]; sendName?: boolean; sendPhoto?: boolean; }): Promise>; /** * Removes your webhook * * @returns Status * * @see https://developers.viber.com/docs/api/rest-bot-api/#removing-your-webhook * * @example * * ```js * await client.removeWebhook(); * ``` */ removeWebhook(): Promise>; /** * Sends a message to the user. * * @param receiver - Unique Viber user id. * @param message - Message and options to be sent. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#send-message * * @example * * ```js * await client.sendMessage(USER_ID, { * type: 'text', * text: 'Hello', * }); * ``` * * @note Maximum total JSON size of the request is 30kb. */ sendMessage(receiver: string, message: ViberTypes.Message): Promise>; /** * Sends a text message to the user. * * * * @param receiver - Unique Viber user id. * @param text - The text of the message. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#text-message * * @example * * ```js * await client.sendText(USER_ID, 'Hello'); * ``` */ sendText(receiver: string, text: string, options?: ViberTypes.MessageOptions): Promise>; /** * Sends a picture message to the user. * * * * @param receiver - Unique Viber user id. * @param picture - The picture of the message. * @param picture.text - Description of the photo. Can be an empty string if irrelevant. Max 120 characters. * @param picture.media - URL of the image (JPEG). Max size 1 MB. Only JPEG format is supported. Other image formats as well as animated GIFs can be sent as URL messages or file messages. * @param picture.thumbnail - URL of a reduced size image (JPEG). Max size 100 kb. Recommended: 400x400. Only JPEG format is supported. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#picture-message * * @example * * ```js * await client.sendPicture(USER_ID, { * text: 'Photo description', * media: 'http://www.images.com/img.jpg', * thumbnail: 'http://www.images.com/thumb.jpg', * }); * ``` */ sendPicture(receiver: string, picture: ViberTypes.Picture, options?: ViberTypes.MessageOptions): Promise>; /** * Sends a video message to the user. * * * * @param receiver - Unique Viber user id. * @param video - The video of the message. * @param video.media - URL of the video (MP4, H264). Max size 50 MB. Only MP4 and H264 are supported. * @param video.size - Size of the video in bytes. * @param video.duration - Video duration in seconds; will be displayed to the receiver. Max 180 seconds. * @param video.thumbnail - URL of a reduced size image (JPEG). Max size 100 kb. Recommended: 400x400. Only JPEG format is supported. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#video-message * * @example * * ```js * await client.sendVideo(USER_ID, { * media: 'http://www.images.com/video.mp4', * size: 10000, * thumbnail: 'http://www.images.com/thumb.jpg', * duration: 10, * }); * ``` */ sendVideo(receiver: string, video: ViberTypes.Video, options?: ViberTypes.MessageOptions): Promise>; /** * Sends a file message to the user. * * * * @param receiver - Unique Viber user id. * @param file - The file of the message. * @param file.media - URL of the file. Max size 50 MB. See [forbidden file formats](https://developers.viber.com/docs/api/rest-bot-api/#forbiddenFileFormats) for unsupported file types. * @param file.size - Size of the file in bytes. * @param file.fileName - Name of the file. File name should include extension. Max 256 characters (including file extension). * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#file-message * * @example * * ```js * await client.sendFile(USER_ID, { * media: 'http://www.images.com/file.doc', * size: 10000, * fileName: 'name_of_file.doc', * }); * ``` */ sendFile(receiver: string, file: ViberTypes.File, options?: ViberTypes.MessageOptions): Promise>; /** * Sends a contact message to the user. * * * * @param receiver - Unique Viber user id. * @param contact - The contact of the message. * @param contact.name - Name of the contact. Max 28 characters. * @param contact.phoneNumber - Phone number of the contact. Max 18 characters. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#contact-message * * @example * * ```js * await client.sendContact(USER_ID, { * name: 'Itamar', * phoneNumber: '+972511123123', * }); * ``` */ sendContact(receiver: string, contact: ViberTypes.Contact, options?: ViberTypes.MessageOptions): Promise>; /** * Sends a location message to the user. * * * * @param receiver - Unique Viber user id. * @param location - The location of the message. * @param location.lat - Latitude (±90°) within valid ranges. * @param location.lon - Longitude (±180°) within valid ranges. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#location-message * * @example * * ```js * await client.sendLocation(USER_ID, { * lat: '37.7898', * lon: '-122.3942', * }); * ``` */ sendLocation(receiver: string, location: ViberTypes.Location, options?: ViberTypes.MessageOptions): Promise>; /** * Sends an URL message to the user. * * * * @param receiver - Unique Viber user id. * @param url - URL. Max 2,000 characters. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#url-message * * @example * * ```js * await client.sendURL(USER_ID, 'http://developers.viber.com'); * ``` */ sendURL(receiver: string, url: string, options?: ViberTypes.MessageOptions): Promise>; /** * Sends a sticker message to the user. * * * * @param receiver - Unique Viber user id. * @param stickerId - Unique Viber sticker ID. For examples visit the [sticker IDs](https://viber.github.io/docs/tools/sticker-ids/) page. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#sticker-message * * @example * * ```js * await client.sendSticker(USER_ID, 46105); * ``` */ sendSticker(receiver: string, stickerId: number, options?: ViberTypes.MessageOptions): Promise>; /** * Sends a carousel content message to the user. * * * * @param receiver - Unique Viber user id. * @param richMedia - The rich media of the message. * @param richMedia.buttonsGroupColumns - Number of columns per carousel content block. Default 6 columns. Possible values: 1 - 6. * @param richMedia.buttonsGroupRows - Number of rows per carousel content block. Default 7 rows. Possible values: 1 - 7. * @param richMedia.buttons - Array of buttons. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#carousel-content-message * * @example * * ```js * await client.sendCarouselContent(USER_ID, { * type: 'rich_media', * buttonsGroupColumns: 6, * buttonsGroupRows: 7, * bgColor: '#FFFFFF', * buttons: [ * { * columns: 6, * rows: 3, * actionType: 'open-url', * actionBody: 'https://www.google.com', * image: 'http://html-test:8080/myweb/guy/assets/imageRMsmall2.png', * }, * { * columns: 6, * rows: 2, * text: 'Headphones with Microphone, On-ear Wired earphones
Sound Intone
$17.99', * actionType: 'open-url', * actionBody: 'https://www.google.com', * textSize: 'medium', * textVAlign: 'middle', * textHAlign: 'left', * }, * { * columns: 6, * rows: 1, * actionType: 'reply', * actionBody: 'https://www.google.com', * text: 'Buy', * textSize: 'large', * textVAlign: 'middle', * textHAlign: 'middle', * image: 'https://s14.postimg.org/4mmt4rw1t/Button.png', * }, * { * columns: 6, * rows: 1, * actionType: 'reply', * actionBody: 'https://www.google.com', * text: 'MORE DETAILS', * textSize: 'small', * textVAlign: 'middle', * textHAlign: 'middle', * }, * { * columns: 6, * rows: 3, * actionType: 'open-url', * actionBody: 'https://www.google.com', * image: 'https://s16.postimg.org/wi8jx20wl/image_RMsmall2.png', * }, * { * columns: 6, * rows: 2, * text: "Hanes Men's Humor Graphic T-Shirt
Hanes
$10.99", * actionType: 'open-url', * actionBody: 'https://www.google.com', * textSize: 'medium', * textVAlign: 'middle', * textHAlign: 'left', * }, * { * columns: 6, * rows: 1, * actionType: 'reply', * actionBody: 'https://www.google.com', * text: 'Buy', * textSize: 'large', * textVAlign: 'middle', * textHAlign: 'middle', * image: 'https://s14.postimg.org/4mmt4rw1t/Button.png', * }, * { * columns: 6, * rows: 1, * actionType: 'reply', * actionBody: 'https://www.google.com', * text: 'MORE DETAILS', * textSize: 'small', * textVAlign: 'middle', * textHAlign: 'middle', * }, * ], * }); * ``` */ sendCarouselContent(receiver: string, richMedia: ViberTypes.RichMedia, options?: ViberTypes.MessageOptions): Promise>; /** * Broadcasts messages to the users. * * @param broadcastList - This mandatory parameter defines the recipients for the message. Every user must be subscribed and have a valid user id. The maximum list length is 300 receivers. * @param message - Message and options to be sent. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#broadcast-message * * @example * * ```js * await client.broadcastMessage( * ['pttm25kSGUo1919sBORWyA==', '2yBSIsbzs7sSrh4oLm2hdQ=='], * { * type: 'text', * text: 'Hello', * } * ); * ``` */ broadcastMessage(broadcastList: string[], message: ViberTypes.Message): Promise; /** * Broadcasts text messages to the users. * * * * @param broadcastList - This mandatory parameter defines the recipients for the message. Every user must be subscribed and have a valid user id. The maximum list length is 300 receivers. * @param text - The text of the message. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#text-message * * @example * * ```js * await client.broadcastText( * ['pttm25kSGUo1919sBORWyA==', '2yBSIsbzs7sSrh4oLm2hdQ=='], * 'Hello' * ); * ``` */ broadcastText(broadcastList: string[], text: string, options?: ViberTypes.MessageOptions): Promise; /** * Broadcasts picture messages to the users. * * * * @param broadcastList - This mandatory parameter defines the recipients for the message. Every user must be subscribed and have a valid user id. The maximum list length is 300 receivers. * @param picture - The picture of the message. * @param picture.text - Description of the photo. Can be an empty string if irrelevant. Max 120 characters. * @param picture.media - URL of the image (JPEG). Max size 1 MB. Only JPEG format is supported. Other image formats as well as animated GIFs can be sent as URL messages or file messages. * @param picture.thumbnail - URL of a reduced size image (JPEG). Max size 100 kb. Recommended: 400x400. Only JPEG format is supported. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#picture-message * * @example * * ```js * await client.broadcastPicture( * ['pttm25kSGUo1919sBORWyA==', '2yBSIsbzs7sSrh4oLm2hdQ=='], * { * text: 'Photo description', * media: 'http://www.images.com/img.jpg', * thumbnail: 'http://www.images.com/thumb.jpg', * } * ); * ``` */ broadcastPicture(broadcastList: string[], picture: ViberTypes.Picture, options?: ViberTypes.MessageOptions): Promise; /** * Broadcasts video messages to the users. * * * * @param broadcastList - This mandatory parameter defines the recipients for the message. Every user must be subscribed and have a valid user id. The maximum list length is 300 receivers. * @param video - The video of the message. * @param video.media - URL of the video (MP4, H264). Max size 50 MB. Only MP4 and H264 are supported. * @param video.size - Size of the video in bytes. * @param video.duration - Video duration in seconds; will be displayed to the receiver. Max 180 seconds. * @param video.thumbnail - URL of a reduced size image (JPEG). Max size 100 kb. Recommended: 400x400. Only JPEG format is supported. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#video-message * * @example * * ```js * await client.broadcastVideo( * ['pttm25kSGUo1919sBORWyA==', '2yBSIsbzs7sSrh4oLm2hdQ=='], * { * media: 'http://www.images.com/video.mp4', * size: 10000, * thumbnail: 'http://www.images.com/thumb.jpg', * duration: 10, * } * ); * ``` */ broadcastVideo(broadcastList: string[], video: ViberTypes.Video, options?: ViberTypes.MessageOptions): Promise; /** * Broadcasts file messages to the users. * * * * @param broadcastList - This mandatory parameter defines the recipients for the message. Every user must be subscribed and have a valid user id. The maximum list length is 300 receivers. * @param file - The file of the message. * @param file.media - URL of the file. Max size 50 MB. See [forbidden file formats](https://developers.viber.com/docs/api/rest-bot-api/#forbiddenFileFormats) for unsupported file types. * @param file.size - Size of the file in bytes. * @param file.fileName - Name of the file. File name should include extension. Max 256 characters (including file extension). * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#file-message * * @example * * ```js * await client.broadcastFile( * ['pttm25kSGUo1919sBORWyA==', '2yBSIsbzs7sSrh4oLm2hdQ=='], * { * media: 'http://www.images.com/file.doc', * size: 10000, * fileName: 'name_of_file.doc', * } * ); * ``` */ broadcastFile(broadcastList: string[], file: ViberTypes.File, options?: ViberTypes.MessageOptions): Promise; /** * Broadcasts contact messages to the users. * * * * @param broadcastList - This mandatory parameter defines the recipients for the message. Every user must be subscribed and have a valid user id. The maximum list length is 300 receivers. * @param contact - The contact of the message. * @param contact.name - Name of the contact. Max 28 characters. * @param contact.phoneNumber - Phone number of the contact. Max 18 characters. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#contact-message * * @example * * ```js * await client.broadcastContact( * ['pttm25kSGUo1919sBORWyA==', '2yBSIsbzs7sSrh4oLm2hdQ=='], * { * name: 'Itamar', * phoneNumber: '+972511123123', * } * ); * ``` */ broadcastContact(broadcastList: string[], contact: ViberTypes.Contact, options?: ViberTypes.MessageOptions): Promise; /** * Broadcasts location messages to the users. * * * * @param broadcastList - This mandatory parameter defines the recipients for the message. Every user must be subscribed and have a valid user id. The maximum list length is 300 receivers. * @param location - The location of the message. * @param location.lat - Latitude (±90°) within valid ranges. * @param location.lon - Longitude (±180°) within valid ranges. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#location-message * * @example * * ```js * await client.broadcastLocation( * ['pttm25kSGUo1919sBORWyA==', '2yBSIsbzs7sSrh4oLm2hdQ=='], * { * lat: '37.7898', * lon: '-122.3942', * } * ); * ``` */ broadcastLocation(broadcastList: string[], location: ViberTypes.Location, options?: ViberTypes.MessageOptions): Promise; /** * Broadcasts URL messages to the users. * * * * @param broadcastList - This mandatory parameter defines the recipients for the message. Every user must be subscribed and have a valid user id. The maximum list length is 300 receivers. * @param url - URL. Max 2,000 characters. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#url-message * * @example * * ```js * await client.broadcastURL( * ['pttm25kSGUo1919sBORWyA==', '2yBSIsbzs7sSrh4oLm2hdQ=='], * 'http://developers.viber.com' * ); * ``` */ broadcastURL(broadcastList: string[], url: string, options?: ViberTypes.MessageOptions): Promise; /** * Broadcasts sticker messages to the users. * * * * @param broadcastList - This mandatory parameter defines the recipients for the message. Every user must be subscribed and have a valid user id. The maximum list length is 300 receivers. * @param stickerId - Unique Viber sticker ID. For examples visit the [sticker IDs](https://viber.github.io/docs/tools/sticker-ids/) page. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#sticker-message * * @example * * ```js * await client.broadcastSticker( * ['pttm25kSGUo1919sBORWyA==', '2yBSIsbzs7sSrh4oLm2hdQ=='], * 46105 * ); * ``` */ broadcastSticker(broadcastList: string[], stickerId: number, options?: ViberTypes.MessageOptions): Promise; /** * Broadcasts carousel content messages to the users. * * * * @param broadcastList - This mandatory parameter defines the recipients for the message. Every user must be subscribed and have a valid user id. The maximum list length is 300 receivers. * @param richMedia - The rich media of the message. * @param richMedia.buttonsGroupColumns - Number of columns per carousel content block. Default 6 columns. Possible values: 1 - 6. * @param richMedia.buttonsGroupRows - Number of rows per carousel content block. Default 7 rows. Possible values: 1 - 7. * @param richMedia.buttons - Array of buttons. * @param options - Other optional parameters. * @returns Status and message token * * @see https://developers.viber.com/docs/api/rest-bot-api/#carousel-content-message * * @example * * ```js * await client.broadcastCarouselContent( * ['pttm25kSGUo1919sBORWyA==', '2yBSIsbzs7sSrh4oLm2hdQ=='], * { * type: 'rich_media', * buttonsGroupColumns: 6, * buttonsGroupRows: 7, * bgColor: '#FFFFFF', * buttons: [ * { * columns: 6, * rows: 3, * actionType: 'open-url', * actionBody: 'https://www.google.com', * image: 'http://html-test:8080/myweb/guy/assets/imageRMsmall2.png', * }, * { * columns: 6, * rows: 2, * text: 'Headphones with Microphone, On-ear Wired earphones
Sound Intone
$17.99', * actionType: 'open-url', * actionBody: 'https://www.google.com', * textSize: 'medium', * textVAlign: 'middle', * textHAlign: 'left', * }, * { * columns: 6, * rows: 1, * actionType: 'reply', * actionBody: 'https://www.google.com', * text: 'Buy', * textSize: 'large', * textVAlign: 'middle', * textHAlign: 'middle', * image: 'https://s14.postimg.org/4mmt4rw1t/Button.png', * }, * { * columns: 6, * rows: 1, * actionType: 'reply', * actionBody: 'https://www.google.com', * text: 'MORE DETAILS', * textSize: 'small', * textVAlign: 'middle', * textHAlign: 'middle', * }, * { * columns: 6, * rows: 3, * actionType: 'open-url', * actionBody: 'https://www.google.com', * image: 'https://s16.postimg.org/wi8jx20wl/image_RMsmall2.png', * }, * { * columns: 6, * rows: 2, * text: "Hanes Men's Humor Graphic T-Shirt
Hanes
$10.99", * actionType: 'open-url', * actionBody: 'https://www.google.com', * textSize: 'medium', * textVAlign: 'middle', * textHAlign: 'left', * }, * { * columns: 6, * rows: 1, * actionType: 'reply', * actionBody: 'https://www.google.com', * text: 'Buy', * textSize: 'large', * textVAlign: 'middle', * textHAlign: 'middle', * image: 'https://s14.postimg.org/4mmt4rw1t/Button.png', * }, * { * columns: 6, * rows: 1, * actionType: 'reply', * actionBody: 'https://www.google.com', * text: 'MORE DETAILS', * textSize: 'small', * textVAlign: 'middle', * textHAlign: 'middle', * }, * ], * } * ); * ``` */ broadcastCarouselContent(broadcastList: string[], richMedia: ViberTypes.RichMedia, options?: ViberTypes.MessageOptions): Promise; /** * Fetches the account’s details as registered in ViberTypes. * * @returns The account’s details * * @see https://developers.viber.com/docs/api/rest-bot-api/#get-account-info * * @example * * ```js * await client.getAccountInfo(); * // { * // status: 0, * // statusMessage: 'ok', * // id: 'pa:75346594275468546724', * // name: 'account name', * // uri: 'accountUri', * // icon: 'http://example.com', * // background: 'http://example.com', * // category: 'category', * // subcategory: 'sub category', * // location: { * // lon: 0.1, * // lat: 0.2, * // }, * // country: 'UK', * // webhook: 'https://my.site.com', * // eventTypes: ['delivered', 'seen'], * // subscribersCount: 35, * // members: [ * // { * // id: '01234567890A=', * // name: 'my name', * // avatar: 'http://example.com', * // role: 'admin', * // }, * // ], * // } * ``` */ getAccountInfo(): Promise>; /** * Fetches the details of a specific Viber user based on his unique user ID. * * @param id - Unique Viber user id. * @returns Details of the Viber user. * * @see https://developers.viber.com/docs/api/rest-bot-api/#get-user-details * * @example * * ```js * await client.getUserDetails('01234567890A='); * // { * // id: '01234567890A=', * // name: 'John McClane', * // avatar: 'http://avatar.example.com', * // country: 'UK', * // language: 'en', * // primaryDeviceOs: 'android 7.1', * // apiVersion: 1, * // viberVersion: '6.5.0', * // mcc: 1, * // mnc: 1, * // deviceType: 'iPhone9,4', * // }; * ``` */ getUserDetails(id: string): Promise; /** * Fetches the online status of a given subscribed account members. * * @param ids - Array of unique Viber user id. 100 ids per request. * @returns An array of online status. * * @see https://developers.viber.com/docs/api/rest-bot-api/#get-online * * @example * * ```js * await client.getOnlineStatus(['01234567890=', '01234567891=', '01234567893=']); * // [ * // { * // id: '01234567890=', * // onlineStatus: 0, * // onlineStatusMessage: 'online', * // }, * // { * // id: '01234567891=', * // onlineStatus: 1, * // onlineStatusMessage: 'offline', * // lastOnline: 1457764197627, * // }, * // { * // id: '01234567893=', * // onlineStatus: 3, * // onlineStatusMessage: 'tryLater', * // }, * // ]; * ``` */ getOnlineStatus(ids: string[]): Promise; } //# sourceMappingURL=ViberClient.d.ts.map