{"__v":0,"_id":"5845a4a99f6fbb1b00430804","category":{"version":"5845a4a89f6fbb1b004307b7","project":"54d3007669578e0d002730c9","_id":"5845a4a89f6fbb1b004307bd","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-07-08T18:48:02.369Z","from_sync":false,"order":5,"slug":"integrations","title":"Integrations"},"parentDoc":null,"project":"54d3007669578e0d002730c9","user":"55bf6cdcad601c2b00762d13","version":{"__v":1,"_id":"5845a4a89f6fbb1b004307b7","project":"54d3007669578e0d002730c9","createdAt":"2016-12-05T17:32:24.708Z","releaseDate":"2016-12-05T17:32:24.708Z","categories":["5845a4a89f6fbb1b004307b8","5845a4a89f6fbb1b004307b9","5845a4a89f6fbb1b004307ba","5845a4a89f6fbb1b004307bb","5845a4a89f6fbb1b004307bc","5845a4a89f6fbb1b004307bd","5845a4a89f6fbb1b004307be","5845a4a89f6fbb1b004307bf","5845a4a89f6fbb1b004307c0"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"25.0.0","version":"25"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-05-15T22:26:06.296Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":9,"body":"* [Overview](#overview)\n* [Video](#video)\n* [Creating a Bot in Telegram](#creating-a-bot-in-telegram)\n* [Integrating API.AI Agent with Telegram Bot](#integrating-apiai-agent-with-telegram-bot)\n* [Testing Your Bot ](#testing-your-bot)\n* [Hosting Your Telegram Bot with Heroku](#hosting-your-telegram-bot-with-heroku)\n * [Creating a Bot in Telegram](#hosting-your-telegram-bot-with-heroku)\n * [Integrating API.AI Agent with Telegram Bot and Heroku Hosting](#section-integrating-api-ai-agent-with-telegram-bot-and-heroku-hosting)\n * [Testing Your Bot](#section-testing-your-bot)\n* [Hosting Bots on Your Server](#hosting-bots-on-your-server) \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Overview\"\n}\n[/block]\n**API.AI Telegram Integration** allows you to easily create <a href=\"https://core.telegram.org/bots\" target=\"_blank\">Telegram bots</a> with natural language understanding based on the API.AI technology.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Video\"\n}\n[/block]\nWatch this video on how to integrate your API.AI agent with Telegram. Or you can follow the steps described in the documentation [below](#creating-a-bot-in-telegram).\n[block:embed]\n{\n  \"html\": \"<iframe class=\\\"embedly-embed\\\" src=\\\"//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fcjhcdi61Ugw%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dcjhcdi61Ugw&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fcjhcdi61Ugw%2Fhqdefault.jpg&key=02466f963b9b4bb8845a05b53d3235d7&type=text%2Fhtml&schema=youtube\\\" width=\\\"640\\\" height=\\\"480\\\" scrolling=\\\"no\\\" frameborder=\\\"0\\\" allowfullscreen></iframe>\",\n  \"url\": \"https://www.youtube.com/watch?v=cjhcdi61Ugw&feature=youtu.be\",\n  \"title\": \"Build Telegram bots with Api.ai\",\n  \"favicon\": \"https://s.ytimg.com/yts/img/favicon-vflz7uhzw.ico\",\n  \"image\": \"https://i.ytimg.com/vi/cjhcdi61Ugw/hqdefault.jpg\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Creating a Bot in Telegram\"\n}\n[/block]\nLog in to your Telegram account and go to <a href=\"https://telegram.me/botfather\" target=\"_blank\">https://telegram.me/botfather</a>. You’ll be redirected to the Telegram application. Here’s how it may look like in the Telegram desktop version:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/966mIJlzSQmXVIYXpPGI_Telegram-BotFather-step1.png\",\n        \"Telegram-BotFather-step1.png\",\n        \"1592\",\n        \"1246\",\n        \"#6a8eac\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\nAfter clicking on 'Start', a list of commands appears. Select **/newbot**. \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/sI0y7agdT1CKHuYN9wzI_Telegram-BotFather-newbot.png\",\n        \"Telegram-BotFather-newbot.png\",\n        \"1602\",\n        \"1244\",\n        \"#688dab\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\nType in your **bot name** and click 'Send'. For this example, we've chosen the name \"WeatherBot\" because we want our bot to provide weather forecast.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/Cs7hwzomQhaxvIZDzKHk_Telegram-BotFather-botname.png\",\n        \"Telegram-BotFather-botname.png\",\n        \"1598\",\n        \"1242\",\n        \"#688dac\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\nYou’ll be prompted to choose a **username** for your bot. Note that it must end in ‘bot’.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/ZoLS3OyS2WoeDuMwCbIc_Telegram-BotFather-username.png\",\n        \"Telegram-BotFather-username.png\",\n        \"1592\",\n        \"1244\",\n        \"#0f414f\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\nCopy the Telegram **access token**:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/TwY5hhyQcWJRKBudD340_Telegram-BotFather-token.png\",\n        \"Telegram-BotFather-token.png\",\n        \"1592\",\n        \"1238\",\n        \"#698eac\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Integrating API.AI Agent with Telegram Bot\"\n}\n[/block]\n<a href=\"https://console.api.ai/api-client/#/newAgent\" target=\"_blank\">Create an API.AI agent</a> with the help of the <a href=\"https://docs.api.ai/docs/key-concepts\" target=\"_blank\">API.AI NLU technology tools</a>.\n\nTo enable Telegram integration, click ‘Integrations’ from the left side menu and turn Telegram integration on.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/hyAnTCcoSvegVtjvDYnL_Telegram-integration-enable.png\",\n        \"Telegram-integration-enable.png\",\n        \"2076\",\n        \"1322\",\n        \"#2c9be0\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\nThen, insert your Telegram access token to the ‘Telegram token’ field and click ‘Start’.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/YGKd6QxHTCYWCJwO6M0d_Telegram-integration-access-token.png\",\n        \"Telegram-integration-access-token.png\",\n        \"2216\",\n        \"1224\",\n        \"#5f65ca\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\nIf you are using a free plan, you can create your own <a href=\"https://docs.api.ai/docs/concept-intents\" target=\"_blank\">intents</a>, integrate your agent with a web service via a <a href=\"https://docs.api.ai/docs/webhook\" target=\"_blank\">webhook</a>, and also use our built-in <a href=\"https://docs.api.ai/docs/small-talk\" target=\"_blank\">Small Talk domain</a>. \n\nIf you upgraded to one of our <a href=\"https://api.ai/pricing/\" target=\"_blank\">paid plans</a>, you can also use other <a href=\"https://docs.api.ai/docs/domains\" target=\"_blank\">built-in domains</a>. For our WeatherBot example, we'll be using the <a href=\"https://docs.api.ai/docs/weather\" target=\"_blank\">Weather domain</a>. Let's enable it on the Domains tab.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/2WzIHhJQSiTqSZ5yFenJ_Telegram-weather-domain.png\",\n        \"Telegram-weather-domain.png\",\n        \"2116\",\n        \"1428\",\n        \"#319fd9\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Testing Your Bot\"\n}\n[/block]\nGo to the Telegram app and search your bot by username.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/hTpZqvzgRHaZwUqR71Ty_Telegram-search-username.png\",\n        \"Telegram-search-username.png\",\n        \"1598\",\n        \"1356\",\n        \"#123842\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\nSelect the bot from the search results and click 'Start'.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/DhuXrx1MREeKKR68j0el_Telegram-bot-select-start.png\",\n        \"Telegram-bot-select-start.png\",\n        \"1598\",\n        \"1240\",\n        \"#6b8eac\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\nTest your bot. In our WeatherBot example, we test it by asking questions about weather in specific locations:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/S4QIYaZdSIC7n9KW5VEe_Telegram-bot-chat.png\",\n        \"Telegram-bot-chat.png\",\n        \"1604\",\n        \"1240\",\n        \"#688dab\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Hosting Your Telegram Bot with Heroku\"\n}\n[/block]\nInstead of hosting your bot with API.AI, you can host it with Heroku or any other service. Here’s an example of hosting a bot with Heroku.\n\n## Creating a Bot in Telegram\n\nCreate a new bot in Telegram as described [here](#creating-a-bot-in-telegram).\n\n## Integrating API.AI Agent with Telegram Bot and Heroku Hosting\n\n<a href=\"https://console.api.ai/api-client/#/newAgent\" target=\"_blank\">Create an API.AI agent</a> with the help of the <a href=\"https://docs.api.ai/docs/key-concepts\" target=\"_blank\">API.AI NLU technology tools</a>.\n\nTo enable Telegram integration, click ‘Integrations’ from the left side menu and turn Telegram integration on.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/CG5RH5a2TRCUjl6hoKCO_Telegram-integration-enable.png\",\n        \"Telegram-integration-enable.png\",\n        \"2076\",\n        \"1322\",\n        \"#2c9be0\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\nThen, click 'Deploy to Heroku'.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/WwNk2JeS6mixbkCkB2Cw_Telegram-integrarion-Heroku.png\",\n        \"Telegram-integrarion-Heroku.png\",\n        \"2210\",\n        \"1216\",\n        \"#5f65ca\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\nYou’ll be redirected to a Heroku page (you need to be logged in to your Heroku account). \n\nOn the Heroku page do the following:\n\n* Create a name for your Heroku app, type it in the App Name field and copy to the APP_NAME field in the Config Variable section. \n\n* Go back to your Telegram BotFather, copy the Telegram access token and insert it to the TELEGRAM_TOKEN field.\n\n* Make sure that the language of your app is the same as the language of your API.AI agent.\n\n* Click ‘Deploy for Free’.\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/LIHpMhoKSPO2fuzbgV0T_Telegram-Heroku-2.png\",\n        \"Telegram-Heroku-2.png\",\n        \"1882\",\n        \"1584\",\n        \"#5e458f\",\n        \"\"\n      ],\n      \"sizing\": \"80\"\n    }\n  ]\n}\n[/block]\n## Testing Your Bot\n\nAfter your Heroku app has been successfully deployed, you can test your Telegram as described [here](#testing-your-bot).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Hosting Bots on Your Server\"\n}\n[/block]\nYou can use our source code from <a href=\"https://github.com/api-ai/apiai-telegram-bot\" target=\"_blank\">https://github.com/api-ai/apiai-telegram-bot</a> to create your custom Telegram bots.","excerpt":"","slug":"telegram-integration","type":"basic","title":"Telegram Integration"}

Telegram Integration


* [Overview](#overview) * [Video](#video) * [Creating a Bot in Telegram](#creating-a-bot-in-telegram) * [Integrating API.AI Agent with Telegram Bot](#integrating-apiai-agent-with-telegram-bot) * [Testing Your Bot ](#testing-your-bot) * [Hosting Your Telegram Bot with Heroku](#hosting-your-telegram-bot-with-heroku) * [Creating a Bot in Telegram](#hosting-your-telegram-bot-with-heroku) * [Integrating API.AI Agent with Telegram Bot and Heroku Hosting](#section-integrating-api-ai-agent-with-telegram-bot-and-heroku-hosting) * [Testing Your Bot](#section-testing-your-bot) * [Hosting Bots on Your Server](#hosting-bots-on-your-server) [block:api-header] { "type": "basic", "title": "Overview" } [/block] **API.AI Telegram Integration** allows you to easily create <a href="https://core.telegram.org/bots" target="_blank">Telegram bots</a> with natural language understanding based on the API.AI technology. [block:api-header] { "type": "basic", "title": "Video" } [/block] Watch this video on how to integrate your API.AI agent with Telegram. Or you can follow the steps described in the documentation [below](#creating-a-bot-in-telegram). [block:embed] { "html": "<iframe class=\"embedly-embed\" src=\"//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fcjhcdi61Ugw%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dcjhcdi61Ugw&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fcjhcdi61Ugw%2Fhqdefault.jpg&key=02466f963b9b4bb8845a05b53d3235d7&type=text%2Fhtml&schema=youtube\" width=\"640\" height=\"480\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "url": "https://www.youtube.com/watch?v=cjhcdi61Ugw&feature=youtu.be", "title": "Build Telegram bots with Api.ai", "favicon": "https://s.ytimg.com/yts/img/favicon-vflz7uhzw.ico", "image": "https://i.ytimg.com/vi/cjhcdi61Ugw/hqdefault.jpg" } [/block] [block:api-header] { "type": "basic", "title": "Creating a Bot in Telegram" } [/block] Log in to your Telegram account and go to <a href="https://telegram.me/botfather" target="_blank">https://telegram.me/botfather</a>. You’ll be redirected to the Telegram application. Here’s how it may look like in the Telegram desktop version: [block:image] { "images": [ { "image": [ "https://files.readme.io/966mIJlzSQmXVIYXpPGI_Telegram-BotFather-step1.png", "Telegram-BotFather-step1.png", "1592", "1246", "#6a8eac", "" ], "sizing": "80" } ] } [/block] After clicking on 'Start', a list of commands appears. Select **/newbot**. [block:image] { "images": [ { "image": [ "https://files.readme.io/sI0y7agdT1CKHuYN9wzI_Telegram-BotFather-newbot.png", "Telegram-BotFather-newbot.png", "1602", "1244", "#688dab", "" ], "sizing": "80" } ] } [/block] Type in your **bot name** and click 'Send'. For this example, we've chosen the name "WeatherBot" because we want our bot to provide weather forecast. [block:image] { "images": [ { "image": [ "https://files.readme.io/Cs7hwzomQhaxvIZDzKHk_Telegram-BotFather-botname.png", "Telegram-BotFather-botname.png", "1598", "1242", "#688dac", "" ], "sizing": "80" } ] } [/block] You’ll be prompted to choose a **username** for your bot. Note that it must end in ‘bot’. [block:image] { "images": [ { "image": [ "https://files.readme.io/ZoLS3OyS2WoeDuMwCbIc_Telegram-BotFather-username.png", "Telegram-BotFather-username.png", "1592", "1244", "#0f414f", "" ], "sizing": "80" } ] } [/block] Copy the Telegram **access token**: [block:image] { "images": [ { "image": [ "https://files.readme.io/TwY5hhyQcWJRKBudD340_Telegram-BotFather-token.png", "Telegram-BotFather-token.png", "1592", "1238", "#698eac", "" ], "sizing": "80" } ] } [/block] [block:api-header] { "type": "basic", "title": "Integrating API.AI Agent with Telegram Bot" } [/block] <a href="https://console.api.ai/api-client/#/newAgent" target="_blank">Create an API.AI agent</a> with the help of the <a href="https://docs.api.ai/docs/key-concepts" target="_blank">API.AI NLU technology tools</a>. To enable Telegram integration, click ‘Integrations’ from the left side menu and turn Telegram integration on. [block:image] { "images": [ { "image": [ "https://files.readme.io/hyAnTCcoSvegVtjvDYnL_Telegram-integration-enable.png", "Telegram-integration-enable.png", "2076", "1322", "#2c9be0", "" ], "sizing": "80" } ] } [/block] Then, insert your Telegram access token to the ‘Telegram token’ field and click ‘Start’. [block:image] { "images": [ { "image": [ "https://files.readme.io/YGKd6QxHTCYWCJwO6M0d_Telegram-integration-access-token.png", "Telegram-integration-access-token.png", "2216", "1224", "#5f65ca", "" ], "sizing": "80" } ] } [/block] If you are using a free plan, you can create your own <a href="https://docs.api.ai/docs/concept-intents" target="_blank">intents</a>, integrate your agent with a web service via a <a href="https://docs.api.ai/docs/webhook" target="_blank">webhook</a>, and also use our built-in <a href="https://docs.api.ai/docs/small-talk" target="_blank">Small Talk domain</a>. If you upgraded to one of our <a href="https://api.ai/pricing/" target="_blank">paid plans</a>, you can also use other <a href="https://docs.api.ai/docs/domains" target="_blank">built-in domains</a>. For our WeatherBot example, we'll be using the <a href="https://docs.api.ai/docs/weather" target="_blank">Weather domain</a>. Let's enable it on the Domains tab. [block:image] { "images": [ { "image": [ "https://files.readme.io/2WzIHhJQSiTqSZ5yFenJ_Telegram-weather-domain.png", "Telegram-weather-domain.png", "2116", "1428", "#319fd9", "" ], "sizing": "80" } ] } [/block] [block:api-header] { "type": "basic", "title": "Testing Your Bot" } [/block] Go to the Telegram app and search your bot by username. [block:image] { "images": [ { "image": [ "https://files.readme.io/hTpZqvzgRHaZwUqR71Ty_Telegram-search-username.png", "Telegram-search-username.png", "1598", "1356", "#123842", "" ], "sizing": "80" } ] } [/block] Select the bot from the search results and click 'Start'. [block:image] { "images": [ { "image": [ "https://files.readme.io/DhuXrx1MREeKKR68j0el_Telegram-bot-select-start.png", "Telegram-bot-select-start.png", "1598", "1240", "#6b8eac", "" ], "sizing": "80" } ] } [/block] Test your bot. In our WeatherBot example, we test it by asking questions about weather in specific locations: [block:image] { "images": [ { "image": [ "https://files.readme.io/S4QIYaZdSIC7n9KW5VEe_Telegram-bot-chat.png", "Telegram-bot-chat.png", "1604", "1240", "#688dab", "" ], "sizing": "80" } ] } [/block] [block:api-header] { "type": "basic", "title": "Hosting Your Telegram Bot with Heroku" } [/block] Instead of hosting your bot with API.AI, you can host it with Heroku or any other service. Here’s an example of hosting a bot with Heroku. ## Creating a Bot in Telegram Create a new bot in Telegram as described [here](#creating-a-bot-in-telegram). ## Integrating API.AI Agent with Telegram Bot and Heroku Hosting <a href="https://console.api.ai/api-client/#/newAgent" target="_blank">Create an API.AI agent</a> with the help of the <a href="https://docs.api.ai/docs/key-concepts" target="_blank">API.AI NLU technology tools</a>. To enable Telegram integration, click ‘Integrations’ from the left side menu and turn Telegram integration on. [block:image] { "images": [ { "image": [ "https://files.readme.io/CG5RH5a2TRCUjl6hoKCO_Telegram-integration-enable.png", "Telegram-integration-enable.png", "2076", "1322", "#2c9be0", "" ], "sizing": "80" } ] } [/block] Then, click 'Deploy to Heroku'. [block:image] { "images": [ { "image": [ "https://files.readme.io/WwNk2JeS6mixbkCkB2Cw_Telegram-integrarion-Heroku.png", "Telegram-integrarion-Heroku.png", "2210", "1216", "#5f65ca", "" ], "sizing": "80" } ] } [/block] You’ll be redirected to a Heroku page (you need to be logged in to your Heroku account). On the Heroku page do the following: * Create a name for your Heroku app, type it in the App Name field and copy to the APP_NAME field in the Config Variable section. * Go back to your Telegram BotFather, copy the Telegram access token and insert it to the TELEGRAM_TOKEN field. * Make sure that the language of your app is the same as the language of your API.AI agent. * Click ‘Deploy for Free’. [block:image] { "images": [ { "image": [ "https://files.readme.io/LIHpMhoKSPO2fuzbgV0T_Telegram-Heroku-2.png", "Telegram-Heroku-2.png", "1882", "1584", "#5e458f", "" ], "sizing": "80" } ] } [/block] ## Testing Your Bot After your Heroku app has been successfully deployed, you can test your Telegram as described [here](#testing-your-bot). [block:api-header] { "type": "basic", "title": "Hosting Bots on Your Server" } [/block] You can use our source code from <a href="https://github.com/api-ai/apiai-telegram-bot" target="_blank">https://github.com/api-ai/apiai-telegram-bot</a> to create your custom Telegram bots.