### Get Started Button Management Source: https://bottender.js.org/docs/api-messenger-client Manage the 'Get Started' button for your Messenger integration. This includes setting, retrieving, and deleting the button. ```APIDOC ## `getGetStarted()` ### Description Retrieves the current value of the 'Get Started' button. ### Response Example ```javascript client.getGetStarted().then((getStarted) => { console.log(getStarted); // { payload: 'GET_STARTED' } }); ``` ## `setGetStarted(payload)` ### Description Sets the value of the 'Get Started' button. ### Parameters #### Request Body - **payload** (String) - Required - Payload sent back to your webhook when the 'Get Started' button is tapped. ### Request Example ```javascript client.setGetStarted('GET_STARTED'); ``` ## `deleteGetStarted()` ### Description Deletes the 'Get Started' button. ### Request Example ```javascript client.deleteGetStarted(); ``` ``` -------------------------------- ### Get Get Started Button - JavaScript Source: https://bottender.js.org/docs/api-messenger-client Retrieves the configuration of the 'Get Started' button. This is often used to check if the button is set before configuring other features like the persistent menu. ```javascript client.getGetStarted().then((getStarted) => { console.log(getStarted); // { // payload: 'GET_STARTED', // } }); ``` -------------------------------- ### Set Get Started Button - JavaScript Source: https://bottender.js.org/docs/api-messenger-client Configures the 'Get Started' button for the Messenger chat. The provided payload is sent back to your webhook when the button is tapped. ```javascript client.setGetStarted('GET_STARTED'); ``` -------------------------------- ### Configure Get Started Button Source: https://bottender.js.org/docs/channel-messenger-profile Set the `getStarted` property within `channels.messenger.profile` in `bottender.config.js` to define the payload for the Get Started button. ```javascript // bottender.config.js module.exports = { channels: { messenger: { // Omission here... profile: { getStarted: { payload: 'GET_STARTED', }, }, }, }, }; ``` -------------------------------- ### Install QnA Maker Package with npm Source: https://bottender.js.org/docs/advanced-guides-nlu Install the @bottender/qna-maker package using npm to enable integration with QnA Maker. ```bash npm install @bottender/qna-maker ``` -------------------------------- ### Install QnA Maker Package with yarn Source: https://bottender.js.org/docs/advanced-guides-nlu Install the @bottender/qna-maker package using yarn to enable integration with QnA Maker. ```bash yarn add @bottender/qna-maker ``` -------------------------------- ### Install @bottender/luis with npm Source: https://bottender.js.org/docs/advanced-guides-nlu Install the LUIS integration package for Bottender using npm. ```bash npm install @bottender/luis ``` -------------------------------- ### Start Bottender Development Server Source: https://bottender.js.org/docs/channel-whatsapp-setup Run this command to start your Bottender application in development mode. You will need the ngrok URL for Twilio Sandbox configuration. ```bash npx bottender dev ``` -------------------------------- ### Start Bottender Bot Source: https://bottender.js.org/docs/channel-line-migrating-from-sdk This command starts the Bottender development server, making your bot accessible at the configured webhook endpoint. ```bash npx bottender start ``` -------------------------------- ### Start Bottender Server for Slack Webhook Source: https://bottender.js.org/docs/channel-slack-setup Run this command in production mode to start your Bottender server and enable it to listen for Slack webhook events. ```bash # in production mode npm start ``` -------------------------------- ### Install @bottender/luis with yarn Source: https://bottender.js.org/docs/advanced-guides-nlu Install the LUIS integration package for Bottender using yarn. ```bash yarn add @bottender/luis ``` -------------------------------- ### Install @bottender/dialogflow with yarn Source: https://bottender.js.org/docs/advanced-guides-nlu Install the Dialogflow integration package for Bottender using yarn. ```bash yarn add @bottender/dialogflow ``` -------------------------------- ### Install ZEIT Now CLI Source: https://bottender.js.org/docs/advanced-guides-deployment Installs the ZEIT Now CLI globally using npm. This tool is used for deploying applications to ZEIT Now. ```bash npm install -g now ``` -------------------------------- ### Install @bottender/dialogflow with npm Source: https://bottender.js.org/docs/advanced-guides-nlu Install the Dialogflow integration package for Bottender using npm. ```bash npm install @bottender/dialogflow ``` -------------------------------- ### Delete Get Started Button - JavaScript Source: https://bottender.js.org/docs/api-messenger-client Removes the 'Get Started' button from the Messenger chat interface. ```javascript client.deleteGetStarted(); ``` -------------------------------- ### Install @bottender/handlers package Source: https://bottender.js.org/docs/migrating-v1 Install the `@bottender/handlers` package to continue using the `middleware` function and `Handler` classes from Bottender v0.x. ```bash npm install @bottender/handlers ``` ```bash yarn add @bottender/handlers ``` -------------------------------- ### Start Bottender Server Source: https://bottender.js.org/docs/channel-line-setup Commands to start your Bottender application in production or development mode. In development, Bottender automatically sets up ngrok and provides a webhook URL. ```bash # in production mode npm start # or in development mode npm run dev ``` -------------------------------- ### Install Rasa Package for Bottender Source: https://bottender.js.org/docs/advanced-guides-nlu Install the `@bottender/rasa` package using npm or yarn to integrate Bottender with Rasa. ```bash npm install @bottender/rasa ``` ```bash yarn add @bottender/rasa ``` -------------------------------- ### Custom Restify Server Setup for Bottender Source: https://bottender.js.org/docs/advanced-guides-custom-server Delegate chatbot webhook requests to a Bottender app within a custom Restify server. Ensure Restify and nodemon are installed. ```javascript const restify = require('restify'); const { bottender } = require('bottender'); const app = bottender({ dev: process.env.NODE_ENV !== 'production', }); const port = Number(process.env.PORT) || 5000; const handle = app.getRequestHandler(); app.prepare().then(() => { const server = restify.createServer(); server.use(restify.plugins.queryParser()); server.use(restify.plugins.bodyParser()); server.get('/api', (req, res) => { res.send({ ok: true }); }); server.get('*', (req, res) => { return handle(req, res); }); server.post('*', (req, res) => { return handle(req, res); }); server.listen(port, (err) => { if (err) throw err; console.log(`> Ready on http://localhost:${port}`); }); }); ``` -------------------------------- ### Start Bottender in Console Mode Source: https://bottender.js.org/docs/the-basics-console-mode Use the `--console` option with npm start or npm run dev to enable Console Mode. This is recommended for faster development iterations. ```bash npm start -- --console ``` ```bash npm run dev -- --console ``` -------------------------------- ### Custom Koa Server Setup for Bottender Source: https://bottender.js.org/docs/advanced-guides-custom-server Delegate chatbot webhook requests to a Bottender app within a custom Koa server. Ensure Koa, koa-router, and koa-bodyparser are installed. ```javascript const Koa = require('koa'); const Router = require('koa-router'); const bodyParser = require('koa-bodyparser'); const { bottender } = require('bottender'); const app = bottender({ dev: process.env.NODE_ENV !== 'production', }); const port = Number(process.env.PORT) || 5000; const handle = app.getRequestHandler(); app.prepare().then(() => { const server = new Koa(); server.use(bodyParser()); server.use((ctx, next) => { ctx.req.body = ctx.request.body; ctx.req.rawBody = ctx.request.rawBody; return next(); }); const router = new Router(); router.get('/api', (ctx) => { ctx.response.body = { ok: true }; }); router.all('*', async (ctx) => { await handle(ctx.req, ctx.res); ctx.respond = false; }); server.use(router.routes()); server.listen(port, (err) => { if (err) throw err; console.log(`> Ready on http://localhost:${port}`); }); }); ``` -------------------------------- ### Install Bottender and Uninstall LINE SDK Source: https://bottender.js.org/docs/channel-line-migrating-from-sdk These commands update your project dependencies by installing the latest version of Bottender and removing the old LINE SDK. ```bash // Using npm npm install bottender@next npm uninstall @line/bot-sdk // Using yarn yarn add bottender@next yarn remove @line/bot-sdk ``` -------------------------------- ### Create New Bottender App Source: https://bottender.js.org/docs/channel-viber-setup Use this command to create a new Bottender project. Ensure you select the 'viber' option during setup. ```bash npx create-bottender-app my-app ``` -------------------------------- ### Run Bottender in Production Mode Source: https://bottender.js.org/docs/channel-telegram-setup This command starts the Bottender server for production deployment. ```bash # in production npm start ``` -------------------------------- ### Install Sentry SDK for Node.js Source: https://bottender.js.org/docs/the-basics-errors Install the Sentry SDK using npm or yarn to enable error tracking in your application. This is a prerequisite for sending errors to Sentry. ```bash # Using npm $ npm install @sentry/node # Using yarn $ yarn add @sentry/node ``` -------------------------------- ### Run Bottender App in Production Source: https://bottender.js.org/docs/channel-messenger-setup Use this command to start your Bottender project in production. This is typically used after deployment to a hosting environment. ```bash npm start ``` -------------------------------- ### Run Bottender App in Development Source: https://bottender.js.org/docs/channel-messenger-setup Use this command to start your Bottender project in development mode. This allows for live testing and debugging. ```bash npm run dev ``` -------------------------------- ### v0.x Bottender Initialization (`index.js`) Source: https://bottender.js.org/docs/migrating-v1 This v0.x example shows how to manually construct the session store and bot instance in `index.js` using settings from `bottender.config.js`. ```javascript // index.js const { MessengerBot } = require('bottender'); const { createServer } = require('bottender/express'); const config = require('./bottender.config').messenger; const maxSize = 500; // The maximum size of the cache, default is 500. const bot = new MessengerBot({ accessToken: config.accessToken, appSecret: config.appSecret, verifyToken: config.verifyToken, sessionStore: new MemorySessionStore(maxSize), }); bot.onEvent(async (context) => { await context.sendText('Hello World'); }); const server = createServer(bot); server.listen(5000, () => { console.log('server is running on 5000 port...'); }); ``` -------------------------------- ### Get Messenger Profile using CLI Source: https://bottender.js.org/docs/channel-messenger-profile Retrieve all currently set Messenger Profile configurations for your Page by running the `npx bottender messenger profile get` command. ```bash npx bottender messenger profile get ``` -------------------------------- ### Set Viber Webhook Source: https://bottender.js.org/docs/channel-viber-setup Execute this command after starting your server to register the Viber webhook with your bot. ```bash npx bottender viber webhook set ``` -------------------------------- ### Environment Variables (`.env`) Source: https://bottender.js.org/docs/migrating-v1 Example `.env` file for storing environment variables required for channel configurations, such as Messenger API credentials. ```dotenv # .env MESSENGER_PAGE_ID= MESSENGER_ACCESS_TOKEN= MESSENGER_APP_ID= MESSENGER_APP_SECRET= MESSENGER_VERIFY_TOKEN= ``` -------------------------------- ### Get LINE Notify Authorization Link Source: https://bottender.js.org/docs/channel-line-notify Generate the authorization URL to guide users to the LINE Notify authorization page. This is typically used when initiating the subscription process. ```javascript const lineNotify = require('../lineNotify'); module.exports = async function App(context) { const url = lineNotify.getAuthLink('test'); await context.sendText(url); }; ``` -------------------------------- ### Initialize Git and Commit Source: https://bottender.js.org/docs/advanced-guides-deployment Initialize a Git repository and make your first commit. Heroku deployment relies on Git, so this step is essential before pushing your code. ```bash git init git add . git commit -am "first commit" ``` -------------------------------- ### Set Persistent Menu - JavaScript Source: https://bottender.js.org/docs/api-messenger-client Configures the persistent menu for the Messenger chat interface. Requires a 'Get Started' button to be set. The menu can contain nested items and web URLs. ```javascript client.setPersistentMenu([ { locale: 'default', callToActions: [ { title: 'Play Again', type: 'postback', payload: 'RESTART', }, { title: 'Language Setting', type: 'nested', callToActions: [ { title: '中文', type: 'postback', payload: 'CHINESE', }, { title: 'English', type: 'postback', payload: 'ENGLISH', }, ], }, { title: 'Explore D', type: 'nested', callToActions: [ { title: 'Explore', type: 'web_url', url: 'https://www.youtube.com/watch?v=v', webviewHeightRatio: 'tall', }, { title: 'W', type: 'web_url', url: 'https://www.facebook.com/w', webviewHeightRatio: 'tall', }, { title: 'Powered by YOCTOL', type: 'web_url', url: 'https://www.yoctol.com/', webviewHeightRatio: 'tall', }, ], }, ], }, ]); ``` -------------------------------- ### Setting Messenger Ice Breakers Source: https://bottender.js.org/docs/channel-messenger-profile Configure Ice Breakers in bottender.config.js to provide users with frequently asked questions to start a conversation. The 'question' appears as user input, and 'payload' is returned as a postback webhook event. Note that API Ice Breakers have higher priority than Get Started buttons or custom questions set via the Page Inbox UI. ```javascript // bottender.config.js module.exports = { channels: { messenger: { // Omission here... profile: { iceBreakers: [ { question: '', payload: '', }, { question: '', payload: '', }, ], }, }, }, }; ``` -------------------------------- ### Set Messenger Webhook and Subscriptions (Development) Source: https://bottender.js.org/docs/channel-messenger-setup After starting your development server, run this command to set up the Messenger webhook and enable necessary subscriptions. This command automatically configures the webhook for your local environment. ```bash npx bottender messenger webhook set ``` -------------------------------- ### Conversation Started Payload Source: https://bottender.js.org/docs/api-viber-event Access the payload data for a conversation started event. ```APIDOC ## conversationStarted ### Description The conversation started payload from Viber raw event. ### Code Example ```javascript event.conversationStarted; // { // event: 'conversation_started', // timestamp: 1457764197627, // message_token: 4912661846655238145, // type: 'open', // context: 'context information', // user: { // id: '01234567890A=', // name: 'John McClane', // avatar: 'http://avatar.example.com', // country: 'UK', // language: 'en', // api_version: 1, // }, // subscribed: false, // } ``` ``` -------------------------------- ### Create Bottender App Source: https://bottender.js.org/docs/channel-line-migrating-from-sdk This command-line instruction creates a new Bottender bot project. It sets up the necessary files and configurations for a Bottender application. ```bash npx create-bottender-app my-app ``` -------------------------------- ### Conversation Started Event Check Source: https://bottender.js.org/docs/api-viber-event Determine if the event signifies the start of a conversation. ```APIDOC ## isConversationStarted ### Description Determine if the event is a conversation_started event. ### Code Example ```javascript event.isConversationStarted; // true ``` ``` -------------------------------- ### Create Bottender Server Entry Point for ZEIT Now Source: https://bottender.js.org/docs/advanced-guides-deployment Sets up an Express server to handle requests for a Bottender application, as ZEIT Now 2.0 does not support npm scripts directly. ```javascript // server.js const bodyParser = require('body-parser'); const express = require('express'); const { bottender } = require('bottender'); const app = bottender({ dev: process.env.NODE_ENV !== 'production', }); const port = Number(process.env.PORT) || 5000; const handle = app.getRequestHandler(); app.prepare().then(() => { const server = express(); server.use( bodyParser.json({ verify: (req, _, buf) => { req.rawBody = buf.toString(); }, }) ); server.all('*', (req, res) => { return handle(req, res); }); server.listen(port, (err) => { if (err) throw err; console.log(`> Ready on http://localhost:${port}`); }); }); ``` -------------------------------- ### Composing Actions in Bottender Source: https://bottender.js.org/docs/the-basics-actions Demonstrates how actions can be composed by returning other actions. This example switches between 'SayHi' and 'Unknown' actions based on user input. ```javascript async function SayHi(context) { await context.sendText('Hi!'); } async function Unknown(context) { await context.sendText('Sorry.'); } async function App(context) { if (context.event.text == 'hi') { return SayHi; } return Unknown; } ``` -------------------------------- ### Set up Messenger Webhook Source: https://bottender.js.org/docs/channel-messenger-handling-events After configuring `bottender.config.js`, run this command to set up the Messenger webhook for your bot. ```bash bottender messenger webhook set ``` -------------------------------- ### Check for Conversation Started Event Source: https://bottender.js.org/docs/api-viber-event Use `isConversationStarted` to determine if the event signifies the start of a conversation. This is a boolean check. ```javascript event.isConversationStarted; // true ``` -------------------------------- ### Get File Info - JavaScript Source: https://bottender.js.org/docs/api-telegram-client Retrieves basic information about a file, preparing it for download. This includes file ID, size, and its path on the server. ```javascript client .getFile('UtAqweADGTo4Gz8cZAeR-ouu4XBx78EeqRkABPL_pM4A1UpI0koD65K2') .then((file) => { console.log(file); // { // fileId: 'UtAqweADGTo4Gz8cZAeR-ouu4XBx78EeqRkABPL_pM4A1UpI0koD65K2', // fileSize: 106356, // filePath: 'photos/1068230105874016297.jpg', // } ``` -------------------------------- ### v1 Bottender Initialization (`index.js`) Source: https://bottender.js.org/docs/migrating-v1 In v1, the `index.js` file is simplified to focus on the bot's core logic, with configuration handled in `bottender.config.js`. ```javascript // index.js module.exports = async function App(context) { await context.sendText('Hello World'); }; ``` -------------------------------- ### Get Channel Info - Slack API Source: https://bottender.js.org/docs/api-slack-client Gets information about a specific channel by its ID. Requires the channel ID as a parameter. ```javascript client.getChannelInfo(channelId).then((res) => { console.log(res); // { // id: 'C8763', // name: 'fun', // ... // } }); ``` -------------------------------- ### Get Channel List - Slack API Source: https://bottender.js.org/docs/api-slack-client Lists all channels in a Slack team. Use this to get an overview of available channels. ```javascript client.getChannelList().then((res) => { console.log(res); // [ // { ... }, // { ... }, // ] }); ``` -------------------------------- ### Get User Info - Slack API Source: https://bottender.js.org/docs/api-slack-client Gets information about a specific user by their ID. Requires the user ID as a parameter. ```javascript client.getUserInfo(userId).then((res) => { console.log(res); // { // id: 'U123456', // name: 'bobby', // ... // } }); ``` -------------------------------- ### Deploy to ZEIT Now 2.0 Source: https://bottender.js.org/docs/advanced-guides-deployment Execute the `now` command in your project directory to deploy your Bottender application to ZEIT Now 2.0. ```bash now ``` -------------------------------- ### Configure QnA Maker Environment Variables Source: https://bottender.js.org/docs/advanced-guides-nlu Set up your QnA Maker resource name, knowledge base ID, and endpoint key in the .env file for integration. ```dotenv # .env RESOURCE_NAME= KNOWLEDGE_BASE_ID= ENDPOINT_KEY= ``` -------------------------------- ### Create New Bottender App Source: https://bottender.js.org/docs/channel-line-setup Use this command to create a new Bottender application. Ensure you select the 'line' option during setup for LINE channel integration. ```bash npx create-bottender-app my-app ``` -------------------------------- ### Integrate Bottender with QnA Maker Source: https://bottender.js.org/docs/advanced-guides-nlu Connect Bottender with QnA Maker by providing your environment variables and a score threshold. This setup uses answers from QnA Maker as responses. ```javascript const { chain } = require('bottender'); const qnaMaker = require('@bottender/qna-maker'); async function Unknown(context) { await context.sendText('Sorry, I don’t know what you say.'); } const QnaMaker = qnaMaker({ resourceName: process.env.RESOURCE_NAME, knowledgeBaseId: process.env.KNOWLEDGE_BASE_ID, endpointKey: process.env.ENDPOINT_KEY, scoreThreshold: 70, }); module.exports = async function App() { return chain([ QnaMaker, // Unknown, ]); }; ``` -------------------------------- ### Get All Conversation Members - Slack API Source: https://bottender.js.org/docs/api-slack-client Recursively retrieves all members of a conversation using cursor-based pagination. Useful for getting a complete list of members. ```javascript client.getAllConversationMembers(channelId).then((res) => { console.log(res); // ['U061F7AUR', 'U0C0NS9HN', ...] }); ``` -------------------------------- ### Set Up WhatsApp Environment Variables Source: https://bottender.js.org/docs/channel-whatsapp-setup Define your Twilio Account SID, Auth Token, and WhatsApp phone number in the .env file. The phone number must be in E.164 format prefixed with 'whatsapp:'. ```dotenv # .env WHATSAPP_ACCOUNT_SID= WHATSAPP_AUTH_TOKEN= WHATSAPP_PHONE_NUMBER= ``` -------------------------------- ### Configure Session Drivers and Stores Source: https://bottender.js.org/docs/the-basics-session Set the session driver and configure various storage options like memory, file, Redis, and MongoDB. ```javascript // bottender.config.js module.exports = { session: { driver: 'memory', stores: { memory: { maxSize: 500, }, file: { dirname: '.sessions', }, redis: { port: 6379, host: '127.0.0.1', password: 'auth', db: 0, }, mongo: { url: 'mongodb://localhost:27017', collectionName: 'sessions', }, }, }, }; ``` -------------------------------- ### Run Bottender in Development Mode Source: https://bottender.js.org/docs/channel-telegram-setup This command starts the Bottender development server, which includes running an ngrok client to make your local bot accessible. The console output will provide the Telegram webhook URL. ```bash # in development npm run dev ``` -------------------------------- ### Access Conversation Started Event Payload Source: https://bottender.js.org/docs/api-viber-event The `conversationStarted` property provides the payload for a conversation started event. This includes event type, user details, and context. ```javascript event.conversationStarted; ``` -------------------------------- ### Create a Heroku App Source: https://bottender.js.org/docs/advanced-guides-deployment Create a new Heroku application. Replace `` with your desired app name. Note the app name regulations mentioned. ```bash heroku create ``` -------------------------------- ### ref Source: https://bottender.js.org/docs/api-messenger-event Get the ref string from a Messenger event. ```APIDOC ## ref ### Description The ref string from Messenger event. ### Example ```javascript event.ref; // 'PASS_THROUGH_PARAM' ``` ``` -------------------------------- ### URL Source: https://bottender.js.org/docs/api-viber-event Get the URL from a Viber raw event. ```APIDOC ## url ### Description The URL from Viber raw event. ### Code Example ```javascript event.url; // 'http://example.com' ``` ``` -------------------------------- ### LINE Event Routing Example Source: https://bottender.js.org/docs/channel-line-routing Use this router configuration to handle various LINE events within your application. Ensure all handler functions are implemented. ```javascript const { router, line } = require('bottender/router'); function App() { return router([ line.message(HandleMessage), line.follow(HandleFollow), line.unfollow(HandleUnfollow), line.join(HandleJoin), line.leave(HandleLeave), line.memberJoined(HandleMemberJoined), line.memberLeft(HandleMemberLeft), line.postback(HandlePostback), line.beacon.enter(HandleBeaconEnter), line.beacon.banner(HandleBeaconBanner), line.beacon.stay(HandleBeaconStay), line.accountLink(HandleAccountLink), line.things.link(HandleThingsLink), line.things.unlink(HandleThingsUnlink), line.things.scenarioResult(HandleThingsScenarioResult), line.any(HandleLine), ]); } /* Note: You need to implement those functions */ async function HandleMessage(context) {} async function HandleFollow(context) {} async function HandleUnfollow(context) {} async function HandleJoin(context) {} async function HandleLeave(context) {} async function HandleMemberJoined(context) {} async function HandleMemberLeft(context) {} async function HandlePostback(context) {} async function HandleBeaconEnter(context) {} async function HandleBeaconBanner(context) {} async function HandleBeaconStay(context) {} async function HandleAccountLink(context) {} async function HandleThingsLink(context) {} async function HandleThingsUnlink(context) {} async function HandleThingsScenarioResult(context) {} async function HandleLine(context) {} ``` -------------------------------- ### getGameHighScores() Source: https://bottender.js.org/docs/api-telegram-context Gets data for high score tables for a game. ```APIDOC ## getGameHighScores() ### Description Gets data for high score tables for a game. ### Parameters #### Request Body - **options** (Object) - Optional - Additional Telegram query options. ### Example ```javascript context.getGameHighScores(); ``` ``` -------------------------------- ### Payload String Source: https://bottender.js.org/docs/api-line-event Get the payload string from a postback event. ```APIDOC ## payload ### Description The payload string from LINE raw event. ### Example ```javascript event.payload; // 'action=buyItem&itemId=123123&color=red' ``` ``` -------------------------------- ### Usage Source: https://bottender.js.org/docs/api-slack-client Demonstrates how to obtain a SlackOAuthClient instance and use it to retrieve account information. ```APIDOC ## Usage Get the `SlackOAuthClient` instance using the `getClient` function: ```javascript const { getClient } = require('bottender'); const client = getClient('slack'); // `client` is a `SlackOAuthClient` instance const accountInfo = await context.client.getAccountInfo(); ``` Or, get the `SlackOAuthClient` instance from the `context`: ```javascript async function MyAction(context) { if (context.platform === 'slack') { // `context.client` is a `SlackOAuthClient` instance const accountInfo = await context.client.getAccountInfo(); } } ``` ``` -------------------------------- ### isGridMigrationStarted Source: https://bottender.js.org/docs/api-slack-event Check if the event indicates that a grid migration has started. ```APIDOC ## isGridMigrationStarted ### Description Determine if the event is a grid_migration_started event. ### Example ```javascript event.isGridMigrationStarted; // true ``` ``` -------------------------------- ### Initial Bottender App Entry Point Source: https://bottender.js.org/docs This is the default code in src/index.js for a new Bottender app, which sends a welcome message. ```javascript module.exports = async function App(context) { await context.sendText('Welcome to Bottender'); }; ``` -------------------------------- ### Sticker ID Source: https://bottender.js.org/docs/api-viber-event Get the sticker ID from a Viber raw event. ```APIDOC ## sticker ### Description The sticker id from Viber raw event. ### Code Example ```javascript event.sticker; // 46105 ``` ``` -------------------------------- ### Respond to a pre-checkout query Source: https://bottender.js.org/docs/api-telegram-context Use `answerPreCheckoutQuery()` to respond to a pre-checkout query, confirming if the product can be delivered. ```javascript context.answerPreCheckoutQuery(true); ``` -------------------------------- ### File URL Source: https://bottender.js.org/docs/api-viber-event Get the URL of the file from a Viber raw event. ```APIDOC ## file ### Description The file URL from Viber raw event. ### Code Example ```javascript event.file; // 'http://example.com/doc.pdf' ``` ``` -------------------------------- ### Video URL Source: https://bottender.js.org/docs/api-viber-event Get the URL of the video from a Viber raw event. ```APIDOC ## video ### Description The video URL from Viber raw event. ### Code Example ```javascript event.video; // 'http://example.com/video.mp4' ``` ``` -------------------------------- ### Send a Minimum Flex Message (Hello World) Source: https://bottender.js.org/docs/channel-line-flex Use `context.sendFlex()` to send a basic flex message. This example creates a 'bubble' with two text components arranged horizontally. ```javascript async function App(context) { await context.sendFlex('This is a hello world flex', { type: 'bubble', body: { type: 'box', layout: 'horizontal', contents: [ { type: 'text', text: 'Hello,' }, { type: 'text', text: 'World!' }, ], }, }); } ``` -------------------------------- ### Picture URL Source: https://bottender.js.org/docs/api-viber-event Get the URL of the picture from a Viber raw event. ```APIDOC ## picture ### Description The picture URL from Viber raw event. ### Code Example ```javascript event.picture; // 'http://example.com/img.jpg' ``` ``` -------------------------------- ### v0.x Bottender Configuration (`bottender.config.js`) Source: https://bottender.js.org/docs/migrating-v1 In v0.x, the configuration file only contained partial channel settings. You had to construct the session store and bot instance manually in `index.js`. ```javascript // bottender.config.js module.exports = { messenger: { accessToken: '__FILL_YOUR_TOKEN_HERE__', appSecret: '__FILL_YOUR_SECRET_HERE__', verifyToken: '__FILL_YOUR_VERIFYTOKEN_HERE__', }, }; ``` -------------------------------- ### Run Bottender in Development Mode Source: https://bottender.js.org/docs/channel-slack-setup Use this command to run Bottender in development mode. This automatically starts an ngrok client to provide a public URL for your webhook. ```bash npm run dev ``` -------------------------------- ### Time from Postback Source: https://bottender.js.org/docs/api-line-event Get the time string from a LINE postback event. ```APIDOC ## time ### Description The time string from LINE postback event. ### Example ```javascript event.time; // '12:30' ``` ``` -------------------------------- ### Run Rasa NLU server Source: https://bottender.js.org/docs/advanced-guides-nlu Start a local server with your trained Rasa NLU model on port 5005 using the `rasa run --enable-api` command. Specify the path to your model file. ```bash rasa run --enable-api -m models/nlu-your-model-id.tar.gz ``` -------------------------------- ### Date from Postback Source: https://bottender.js.org/docs/api-line-event Get the date string from a LINE postback event. ```APIDOC ## date ### Description The date string from LINE postback event. ### Example ```javascript event.date; // '2017-09-06' ``` ``` -------------------------------- ### Send an invoice for a product Source: https://bottender.js.org/docs/api-telegram-context Use `sendInvoice()` to send a product invoice. Ensure all required product details and currency are provided. ```javascript context.sendInvoice({ title: 'product name', description: 'product description', payload: 'bot-defined invoice payload', providerToken: 'PROVIDER_TOKEN', startParameter: 'pay', currency: 'USD', prices: [ { label: 'product', amount: 11000 }, { label: 'tax', amount: 11000 }, ], }); ``` -------------------------------- ### Text Content Source: https://bottender.js.org/docs/api-line-event Get the text content from a text message event. ```APIDOC ## text ### Description The text string from LINE raw event. ### Example ```javascript event.text; // 'Hello, world' ``` ``` -------------------------------- ### Getting a List of Scheduled Messages Source: https://bottender.js.org/docs/channel-slack-sending-messages Retrieves a list of all currently scheduled messages. ```APIDOC ## Getting a List of Scheduled Messages ### Description You can get a list of scheduled messages. ### Method `context.chat.scheduledMessages.list()` ### Request Example ```javascript await context.chat.scheduledMessages.list(); ``` ### More Information Refer to Slack's official doc, `chat.scheduledMessages.list`. ``` -------------------------------- ### Configure now.json for Bottender Deployment Source: https://bottender.js.org/docs/advanced-guides-deployment Configures ZEIT Now 2.0 settings, including build process, file inclusions, routing, and environment variables for a Bottender application. ```json // now.json { "version": 2, "builds": [ { "src": "server.js", "use": "@now/node", "config": { "includeFiles": [ "bottender.config.js", "index.js" ], "bundle": true } } ], "routes": [ { "src": "/.*", "dest": "/server.js" } ], "env": { "MESSENGER_PAGE_ID": "xxxxxx", "MESSENGER_ACCESS_TOKEN": "xxxxxx", "MESSENGER_APP_ID": "xxxxxx", "MESSENGER_APP_SECRET": "xxxxxx", "MESSENGER_VERIFY_TOKEN": "xxxxxx", "DEBUG": "bottender*,messaging-api*" } } ``` -------------------------------- ### Get Chat Members Count Source: https://bottender.js.org/docs/api-telegram-context Fetches the total number of members in the chat. ```javascript context.getChatMembersCount().then((result) => { console.log(result); // '6' ``` -------------------------------- ### Access Session ID Source: https://bottender.js.org/docs/api-context Get the unique identifier for the current session from the session instance. ```javascript context.session.id; ``` -------------------------------- ### Set Up Messenger Event Router Source: https://bottender.js.org/docs/channel-messenger-routing Use this router to define handlers for different Messenger events. Ensure you implement the handler functions for each event type. ```javascript const { router, messenger } = require('bottender/router'); function App() { return router([ messenger.message(HandleMessage), messenger.accountLinking.linked(HandleAccountLinkingLinked), messenger.accountLinking.unlinked(HandleAccountLinkingUnlinked), messenger.accountLinking(HandleAccountLinking), messenger.delivery(HandleDelivery), messenger.echo(HandleEcho), messenger.gamePlay(HandleGamePlay), messenger.passThreadControl(HandlePassThreadControl), messenger.takeThreadControl(HandleTakeThreadControl), messenger.requestThreadControl(HandleRequestThreadControl), messenger.appRoles(HandleAppRoles), messenger.optin(HandleOptin), messenger.policyEnforcement(HandlePolicyEnforcement), messenger.postback(HandlePostback), messenger.reaction.react(HandleReactionReact), messenger.reaction.unreact(HandleReactionUnreact), messenger.reaction(HandleReaction), messenger.read(HandleRead), messenger.referral(HandleReferral), messenger.standby(HandleStandby), messenger.any(HandleMessenger), ]); } /* Note: You need to implement those functions */ async function HandleMessage(context) {} async function HandleAccountLinkingLinked(context) {} async function HandleAccountLinkingUnlinked(context) {} async function HandleAccountLinking(context) {} async function HandleDelivery(context) {} async function HandleEcho(context) {} async function HandleGamePlay(context) {} async function HandlePassThreadControl(context) {} async function HandleTakeThreadControl(context) {} async function HandleRequestThreadControl(context) {} async function HandleAppRoles(context) {} async function HandleOptin(context) {} async function HandlePolicyEnforcement(context) {} async function HandlePostback(context) {} async function HandleReactionReact(context) {} async function HandleReactionUnreact(context) {} async function HandleReaction(context) {} async function HandleRead(context) {} async function HandleReferral(context) {} async function HandleStandby(context) {} async function HandleMessenger(context) {} ``` -------------------------------- ### Set Telegram Webhook for Development Source: https://bottender.js.org/docs/channel-telegram-setup After running `npm run dev`, use this command to set up the webhook for your Telegram bot using the ngrok URL provided. ```bash npx bottender telegram webhook set ``` -------------------------------- ### Configure Heroku Procfile for Bottender Source: https://bottender.js.org/docs/advanced-guides-deployment Defines web and release process types for Heroku deployment. The release process sets up the webhook automatically. ```bash // Procfile web: npm start release: echo "Y" | npx bottender messenger webhook set -w https://.com/webhooks/messenger ``` -------------------------------- ### Get Thread Owner Source: https://bottender.js.org/docs/api-messenger-client Retrieves the current owner of a conversation thread. Requires the user ID. ```javascript client.getThreadOwner(USER_ID).then((threadOwner) => { console.log(threadOwner); // { // appId: '12345678910' // } }); ``` -------------------------------- ### Configure Dummy Server for Testing Source: https://bottender.js.org/docs/api-messenger-client Configure the 'origin' option in `bottender.js.config` to send requests to a dummy server during testing, avoiding actual Messenger server interactions. This is not recommended for production environments. ```javascript module.exports = { channels: { messenger: { enabled: true, path: '/webhooks/messenger', pageId: process.env.MESSENGER_PAGE_ID, accessToken: process.env.MESSENGER_ACCESS_TOKEN, appId: process.env.MESSENGER_APP_ID, appSecret: process.env.MESSENGER_APP_SECRET, verifyToken: process.env.MESSENGER_VERIFY_TOKEN, origin: process.env.NODE_ENV === 'test' ? 'https://mydummytestserver.com' : undefined, }, }, }; ``` -------------------------------- ### getChannelInfo Source: https://bottender.js.org/docs/api-slack-client Gets information about a specific channel by its ID. Accepts optional parameters like accessToken. ```APIDOC ## getChannelInfo(channelId, options?) ### Description Gets information about a channel. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **channelId** (`String`) - Required - The ID of the channel to get information on. - **options** (`Object`) - Optional. Other optional parameters. - **options.accessToken** (`String`) - Custom access token of the request. ### Request Example ```javascript client.getChannelInfo(channelId).then((res) => { console.log(res); // { // id: 'C8763', // name: 'fun', // ... // } }); ``` ### Response #### Success Response (200) - **Object** - An object containing the channel's information. ``` -------------------------------- ### Configure LUIS environment variables Source: https://bottender.js.org/docs/advanced-guides-nlu Set up your LUIS application ID, key, and endpoint in the .env file for Bottender integration. ```dotenv # .env LUIS_APP_ID= LUIS_APP_KEY= LUIS_APP_ENDPOINT= ``` -------------------------------- ### getUserInfo Source: https://bottender.js.org/docs/api-slack-client Gets information about a specific user by their ID. Accepts optional parameters like accessToken. ```APIDOC ## getUserInfo(userId, options?) ### Description Gets information about a user. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **userId** (`String`) - Required - The ID of the user to get information on. - **options** (`Object`) - Optional. Other optional parameters. - **options.accessToken** (`String`) - Custom access token of the request. ### Request Example ```javascript client.getUserInfo(userId).then((res) => { console.log(res); // { // id: 'U123456', // name: 'bobby', // ... // } }); ``` ### Response #### Success Response (200) - **Object** - An object containing the user's information. ``` -------------------------------- ### Set LINE Environment Variables Source: https://bottender.js.org/docs/channel-line-setup Configure your `.env` file with your LINE Access Token and Channel Secret. These are essential for your bot to authenticate with the LINE platform. ```dotenv # .env LINE_ACCESS_TOKEN= LINE_CHANNEL_SECRET= ``` -------------------------------- ### context.client Source: https://bottender.js.org/docs/api-context Get the client instance for interacting with messaging APIs. The type of client depends on the platform. ```APIDOC ## `client` ### Description The client instance used for sending messages and interacting with the messaging platform. The specific client type varies based on the platform. ### Example ```javascript context.client; // Returns: client from [Messaging APIs](https://github.com/Yoctol/messaging-apis) ``` ``` -------------------------------- ### Handle Cross-Platform Events with context.platform Source: https://bottender.js.org/docs/advanced-guides-multi-channel Use `context.platform` within your bot actions to identify the incoming message's platform and respond accordingly. This example sends a greeting including the detected platform. ```javascript module.exports = async function App(context) { await context.sendText(`Hello World. Platform: ${context.platform}`); }; ``` -------------------------------- ### Connect Bottender with Rasa Source: https://bottender.js.org/docs/advanced-guides-nlu Integrate Bottender with Rasa by configuring the Rasa package with your Rasa server's origin URL, confidence threshold, and a map between intents and functions. This example shows how to set up the Rasa middleware and a fallback handler. ```javascript const { chain } = require('bottender'); const rasa = require('@bottender/rasa'); async function SayHello(context) { await context.sendText('Hello!'); } async function Unknown(context) { await context.sendText('Sorry, I don’t know what you say.'); } const Rasa = rasa({ origin: 'http://localhost:5005', actions: { greeting: SayHello, }, confidenceThreshold: 0.7, }); module.exports = async function App() { return chain([ Rasa, // Unknown, ]); }; ``` -------------------------------- ### getWebhookInfo Source: https://bottender.js.org/docs/api-telegram-client Gets the current webhook status. This method is useful for checking if a webhook is configured and its current state. ```APIDOC ## getWebhookInfo ### Description Gets current webhook status. ### Method `getWebhookInfo()` ### Endpoint Not applicable (SDK method) ### Parameters None ### Request Example ```javascript client.getWebhookInfo().then((info) => { console.log(info); // { // url: 'https://4a16faff.ngrok.io/', // hasCustomCertificate: false, // pendingUpdateCount: 0, // maxConnections: 40, // } }); ``` ### Response #### Success Response - **info** (Object) - An object containing webhook information. ``` -------------------------------- ### Get User Details Source: https://bottender.js.org/docs/api-viber-client Fetches the details of a specific Viber user based on their unique user ID. ```APIDOC ## Get User Details ### Method Signature `getUserDetails(id)` ### Description It will fetch the details of a specific Viber user based on his unique user ID. ### Parameters #### Path Parameters - **id** (`String`) - Required - Unique Viber user id. ### Request Example ```javascript client.getUserDetails('01234567890A=').then((user) => { console.log(user); }); ``` ### Response Example ```json { "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", } ``` ``` -------------------------------- ### Configure Dummy Server Origin for Slack Client Source: https://bottender.js.org/docs/api-slack-client Provide the `origin` option in your `bottender.js.config` to direct requests to a dummy server when `NODE_ENV` is 'test'. This is useful for testing purposes and should not be used on production servers. ```javascript module.exports = { channels: { viber: { enabled: true, path: '/webhooks/slack', accessToken: process.env.SLACK_ACCESS_TOKEN, signingSecret: process.env.SLACK_SIGNING_SECRET, origin: process.env.NODE_ENV === 'test' ? 'https://mydummytestserver.com' : undefined, }, }, }; ``` -------------------------------- ### Get Account Info Source: https://bottender.js.org/docs/api-viber-client Fetches the account's details as registered in Viber. This method does not require any parameters. ```APIDOC ## Get Account Info ### Method Signature `getAccountInfo()` ### Description It will fetch the account’s details as registered in Viber. ### Request Example ```javascript client.getAccountInfo().then((info) => { console.log(info); }); ``` ### Response Example ```json { "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", }, ], } ``` ``` -------------------------------- ### Get game high scores Source: https://bottender.js.org/docs/api-telegram-context Use `getGameHighScores()` to retrieve data for game high score tables. ```javascript context.getGameHighScores(); ``` -------------------------------- ### answerPreCheckoutQuery(ok [, options]) Source: https://bottender.js.org/docs/api-telegram-context Responds to a pre-checkout query, indicating if delivery is possible. ```APIDOC ## answerPreCheckoutQuery(ok [, options]) ### Description Responds to a pre-checkout query, indicating if delivery is possible. ### Parameters #### Request Body - **ok** (Boolean) - Required - Specify if delivery of the product is possible. - **options** (Object) - Optional - Additional Telegram query options. ### Example ```javascript context.answerPreCheckoutQuery(true); ``` ``` -------------------------------- ### Configure Bottender Source: https://bottender.js.org/docs/channel-line-migrating-from-sdk This configuration file sets up Bottender for LINE integration. It specifies the webhook path, access token, and channel secret using environment variables. ```javascript module.exports = { enabled: true, path: '/webhooks/line', accessToken: process.env.LINE_ACCESS_TOKEN, channelSecret: process.env.LINE_CHANNEL_SECRET, }; ``` -------------------------------- ### Get Chat Information Source: https://bottender.js.org/docs/api-telegram-context Fetches up-to-date information about the chat, including user details and chat type. ```javascript context.getChat().then((result) => { console.log(result); // { // id: 313534466, // firstName: 'first', // lastName: 'last', // username: 'username', // type: 'private', // } ``` -------------------------------- ### Extract Text Content Source: https://bottender.js.org/docs/api-messenger-event Get the text string from a Messenger raw event. Only available if `isText` is true. ```javascript event.text; // 'Awesome.' ```