{"_id":"563417a488703521008ec96d","parentDoc":null,"version":{"_id":"552829408962f339009a6790","project":"552829408962f339009a678d","__v":26,"createdAt":"2015-04-10T19:49:20.516Z","releaseDate":"2015-04-10T19:49:20.516Z","categories":["552829418962f339009a6791","55284ed68962f339009a67e1","55286c73391a362500d9b3f4","552918f6b316811900149f59","5529b255d739240d00a3483e","553287590a578a0d008d4ff5","55329385e7d1fa0d003fc946","5550b55200420e0d00d1312f","55525fca953c9c0d00f507d7","559199695631432f002d358a","559d8d96980b801700d5ec7e","55c5e833cccdeb2d004e24b9","55d76504f662951900fc0e7d","55ea213cc62aa02f008229cd","56157b750f5ed00d00483dd8","561981fbac0924170069f4e8","561b8b1ea430930d0037ea67","563417428b86331700b488ca","56cd785bface161300dae0ec","56cdcc6e70db8a15006395f4","56cdf1b749abf10b0036a34a","56cedc8ce50c9c1b00830423","56e97ba8d825061900d1ac83","570d505228e6900e00477229","573614ca2ab52e1700c8e851","57d556a2496a3117004d70cf"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"project":"552829408962f339009a678d","category":{"_id":"563417428b86331700b488ca","version":"552829408962f339009a6790","__v":3,"pages":["563417a488703521008ec96d","563672d550be720d0042c554","5640a9c32b14f70d0039b89b"],"project":"552829408962f339009a678d","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-10-31T01:20:02.021Z","from_sync":false,"order":3,"slug":"bot-platform","title":"Bot Platform"},"user":"55282916d9e1db2d00cd923c","__v":8,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-10-31T01:21:40.379Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"Bots Platform is a powerful toolkit for creating automated Actor accounts that can do various things: remind you tasks, integrate various services, building business processes or even control your automated office or home.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Creating a new Bot\"\n}\n[/block]\nFor creating new Bot, you need to send command to main bot: :::at:::botfather. Send him */start* message to begin bot configuration.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Quick Start\"\n}\n[/block]\nActor Bots are implemented in Java-compatable language using our Bot Kit. Bot Kit is implemented on top of Akka Actors. And your bot is an Akka Actor.\n\nWe will provide example with plain Java and Gradle build system.\n\nYou can find full example in our [GitHub](https://github.com/actorapp/actor-platform/tree/master/actor-sdk/sdk-bot/bot-example).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Sample: HelloBot.java\"\n}\n[/block]\nExample of bot that uses built-in key-value storage for persisting data across bot launches.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"package im.actor;\\n\\nimport java.util.Optional;\\n\\nimport im.actor.botkit.RemoteBot;\\nimport im.actor.bots.BotMessages;\\nimport shardakka.ShardakkaExtension;\\nimport shardakka.keyvalue.SimpleKeyValueJava;\\n\\n/**\\n * Example Hello Bot: Entry point of development bots for Actor Platform\\n */\\npublic class HelloBot extends RemoteBot {\\n\\n    /**\\n     * Local persistent key-value. Useful for storing bot's data.\\n     */\\n    private SimpleKeyValueJava<String> localKeyValue;\\n\\n    public HelloBot(String token, String endpoint) {\\n        super(token, endpoint);\\n\\n        // Creating KeyValue. Don't try to understand this, this is not necessary.\\n        // We will improve this in future versions\\n        // \\\"msgs\\\" is name of storage, asJava is required for better Java API.\\n        localKeyValue = ShardakkaExtension.get(context().system()).simpleKeyValue(\\\"msgs\\\").asJava();\\n    }\\n\\n\\n    @Override\\n    public void onMessage(BotMessages.Message message) {\\n        if (message.message() instanceof BotMessages.TextMessage) {\\n            // If Message is Text Message\\n            BotMessages.TextMessage text = (BotMessages.TextMessage) message.message();\\n\\n\\n            if (text.text().trim().toLowerCase().startsWith(\\\"hello\\\")) {\\n                // If Message starts from hello: Sending response\\n\\n                // Get User of sender\\n                BotMessages.User user = getUser(message.sender().id());\\n\\n                // Sending welcome message\\n                requestSendMessage(message.peer(),\\n                        nextRandomId(), \\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\tnew BotMessages.TextMessage(\\\"Hi, \\\" + user.name() + \\\"!\\\"));\\n            } else if (text.text().trim().toLowerCase().startsWith(\\\"last\\\")) {\\n                // If Message starts from last: Sending last sent message\\n\\n                // Reading last_message from disc\\n                Optional<String> res = localKeyValue.syncGet(\\\"last_message\\\");\\n\\n                if (res.isPresent()) {\\n\\n                    // If present: send it back\\n                    requestSendMessage(message.peer(),\\n                            nextRandomId(), new BotMessages.TextMessage(\\\"Last message:  \\\" + res.get()));\\n                } else {\\n\\n                    requestSendMessage(message.peer(),\\n                            nextRandomId(), new BotMessages.TextMessage(\\\"I'm alone :'(\\\"));\\n                }\\n            } else {\\n\\n                // Else ask person about saying hello\\n                requestSendMessage(message.peer(), nextRandomId(), new BotMessages.TextMessage(\\\"Please, say hello\\\"));\\n            }\\n\\n            // Store last message\\n            localKeyValue.syncUpsert(\\\"last_message\\\", text.text());\\n        }\\n    }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Sample: Main.java\"\n}\n[/block]\nExample of launching bot\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"package im.actor;\\n\\nimport akka.actor.ActorSystem;\\nimport akka.actor.Props;\\nimport im.actor.botkit.RemoteBot;\\n\\nimport java.util.Scanner;\\n\\npublic class Main {\\n\\n    public static void main(String[] args) {\\n\\n        // Reading Bot's token from console\\n        Scanner scanner = new Scanner(System.in);\\n        System.out.print(\\\"Enter bot token: \\\");\\n        System.out.flush();\\n        String token = scanner.nextLine();\\n        scanner.close();\\n\\n        // Creating Akka Actor system: soup where Bots live\\n        ActorSystem system = ActorSystem.create();\\n\\n        // Creating Actor of our Hello Bot\\n        // Information about creating bot\\n        // 1) Bot Class 2) Bot Token 3) Server Endpoint\\n        Props botProps = Props.create(HelloBot.class, token, RemoteBot.DefaultEndpoint());\\n        // Create Bot in ActorSystem\\n        system.actorOf(botProps);\\n\\n        // Infinite loop\\n        system.awaitTermination();\\n    }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"Getting Started with Bots","slug":"bots-getting-started","type":"basic","title":"Getting Started"}

Getting Started

Getting Started with Bots

Bots Platform is a powerful toolkit for creating automated Actor accounts that can do various things: remind you tasks, integrate various services, building business processes or even control your automated office or home. [block:api-header] { "type": "basic", "title": "Creating a new Bot" } [/block] For creating new Bot, you need to send command to main bot: @botfather. Send him */start* message to begin bot configuration. [block:api-header] { "type": "basic", "title": "Quick Start" } [/block] Actor Bots are implemented in Java-compatable language using our Bot Kit. Bot Kit is implemented on top of Akka Actors. And your bot is an Akka Actor. We will provide example with plain Java and Gradle build system. You can find full example in our [GitHub](https://github.com/actorapp/actor-platform/tree/master/actor-sdk/sdk-bot/bot-example). [block:api-header] { "type": "basic", "title": "Sample: HelloBot.java" } [/block] Example of bot that uses built-in key-value storage for persisting data across bot launches. [block:code] { "codes": [ { "code": "package im.actor;\n\nimport java.util.Optional;\n\nimport im.actor.botkit.RemoteBot;\nimport im.actor.bots.BotMessages;\nimport shardakka.ShardakkaExtension;\nimport shardakka.keyvalue.SimpleKeyValueJava;\n\n/**\n * Example Hello Bot: Entry point of development bots for Actor Platform\n */\npublic class HelloBot extends RemoteBot {\n\n /**\n * Local persistent key-value. Useful for storing bot's data.\n */\n private SimpleKeyValueJava<String> localKeyValue;\n\n public HelloBot(String token, String endpoint) {\n super(token, endpoint);\n\n // Creating KeyValue. Don't try to understand this, this is not necessary.\n // We will improve this in future versions\n // \"msgs\" is name of storage, asJava is required for better Java API.\n localKeyValue = ShardakkaExtension.get(context().system()).simpleKeyValue(\"msgs\").asJava();\n }\n\n\n @Override\n public void onMessage(BotMessages.Message message) {\n if (message.message() instanceof BotMessages.TextMessage) {\n // If Message is Text Message\n BotMessages.TextMessage text = (BotMessages.TextMessage) message.message();\n\n\n if (text.text().trim().toLowerCase().startsWith(\"hello\")) {\n // If Message starts from hello: Sending response\n\n // Get User of sender\n BotMessages.User user = getUser(message.sender().id());\n\n // Sending welcome message\n requestSendMessage(message.peer(),\n nextRandomId(), \n\t\t\t\t\t\t\t\t\t\t\t\tnew BotMessages.TextMessage(\"Hi, \" + user.name() + \"!\"));\n } else if (text.text().trim().toLowerCase().startsWith(\"last\")) {\n // If Message starts from last: Sending last sent message\n\n // Reading last_message from disc\n Optional<String> res = localKeyValue.syncGet(\"last_message\");\n\n if (res.isPresent()) {\n\n // If present: send it back\n requestSendMessage(message.peer(),\n nextRandomId(), new BotMessages.TextMessage(\"Last message: \" + res.get()));\n } else {\n\n requestSendMessage(message.peer(),\n nextRandomId(), new BotMessages.TextMessage(\"I'm alone :'(\"));\n }\n } else {\n\n // Else ask person about saying hello\n requestSendMessage(message.peer(), nextRandomId(), new BotMessages.TextMessage(\"Please, say hello\"));\n }\n\n // Store last message\n localKeyValue.syncUpsert(\"last_message\", text.text());\n }\n }\n}", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Sample: Main.java" } [/block] Example of launching bot [block:code] { "codes": [ { "code": "package im.actor;\n\nimport akka.actor.ActorSystem;\nimport akka.actor.Props;\nimport im.actor.botkit.RemoteBot;\n\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n // Reading Bot's token from console\n Scanner scanner = new Scanner(System.in);\n System.out.print(\"Enter bot token: \");\n System.out.flush();\n String token = scanner.nextLine();\n scanner.close();\n\n // Creating Akka Actor system: soup where Bots live\n ActorSystem system = ActorSystem.create();\n\n // Creating Actor of our Hello Bot\n // Information about creating bot\n // 1) Bot Class 2) Bot Token 3) Server Endpoint\n Props botProps = Props.create(HelloBot.class, token, RemoteBot.DefaultEndpoint());\n // Create Bot in ActorSystem\n system.actorOf(botProps);\n\n // Infinite loop\n system.awaitTermination();\n }\n}", "language": "java" } ] } [/block]