├── CHANGELOG.md ├── Procfile ├── lib ├── telegrambot.dart └── src │ ├── env.dart │ └── bot_configuration.dart ├── .gitignore ├── pubspec.yaml ├── analysis_options.yaml ├── README.md ├── test └── telegrambot_test.dart ├── bin └── telegrambot.dart └── pubspec.lock /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | - Initial version. 4 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | commandline: ./dart-sdk/bin/dart ./bin/telegrambot.dart -------------------------------------------------------------------------------- /lib/telegrambot.dart: -------------------------------------------------------------------------------- 1 | export 'src/bot_configuration.dart'; 2 | export 'src/env.dart'; 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub. 2 | .dart_tool/ 3 | .packages 4 | 5 | # Conventional directory for build output. 6 | build/ 7 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: telegrambot 2 | description: A sample command-line application. 3 | version: 1.0.0 4 | # homepage: https://www.example.com 5 | environment: 6 | sdk: ">=2.14.4 <3.0.0" 7 | 8 | # dependencies: 9 | # path: ^1.8.0 10 | dev_dependencies: 11 | lints: ^1.0.0 12 | test: ^1.16.0 13 | dependencies: 14 | http: ^0.13.4 15 | teledart: ^0.2.1 16 | -------------------------------------------------------------------------------- /lib/src/env.dart: -------------------------------------------------------------------------------- 1 | Map envVars = { 2 | 'BOT_TOKEN': '5087574877:AAFZY7KMa5gd9Dm9F01jtwTrMB5px0qZKkI', 3 | 'BIBLE': 'https://bible-api.com', 4 | 'FACT': 'https://axoltlapi.herokuapp.com/', 5 | 'JOKES': 'http://api.icndb.com/jokes/random', 6 | 'AGE': 'https://api.agify.io?name=michael', 7 | 'INSULT': 'https://evilinsult.com/generate_insult.php?lang=en&type=json', 8 | 'ADVICE': 'https://api.adviceslip.com/advice', 9 | 'HOST_URL': 'https://enigmatic-waters-04315.herokuapp.com/', 10 | 'BOT_PORT': 8443 11 | }; 12 | 13 | String help = ''' 14 | I can help you do simple task and have fun😂. 15 | I was built with Dart.💙 16 | 17 | /jokes - get a random joke 😬 18 | /insult - get a random insult 🥵 19 | /facts - get a random fact 🍕 20 | /advice - get a random advice 😪 21 | 22 | Command with Param 23 | bible - get a random bible verse[param: book]💫 24 | Eg. Bible James 10:2 25 | 26 | '''; 27 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:lints/recommended.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | # linter: 19 | # rules: 20 | # - camel_case_types 21 | 22 | # analyzer: 23 | # exclude: 24 | # - path/to/excluded/files/** 25 | 26 | # For more information about the core and recommended set of lints, see 27 | # https://dart.dev/go/core-lints 28 | 29 | # For additional information about configuring this file, see 30 | # https://dart.dev/guides/language/analysis-options 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TeleBot 2 | 3 | This is a bot built with Dart lang which helps you people a simple task and have fun 4 | 5 | ## Command supported 6 | 7 | - /jokes - get a random joke 😬 8 | - /insult - get a random insult 🥵 9 | - /facts - get a random fact 🍕 10 | - /advice - get a random advice 😪 11 | 12 | ## 💌 Author 13 | 14 | 👤 **Rexford Asamoah** 15 | 16 | - Twitter: [@Rexthedev](https://twitter.com/Rexthedev) 17 | - Github: [@Rexfordasamoah51](https://github.com/Rexfordasamoah51) 18 | - LinkedIn: [@rexfordasamoah](https://linkedin.com/in/rexfordasamoah) 19 | 20 | ## License 21 | 22 | Copyright 2021 Rexford Asamoah 23 | 24 | Licensed under the Apache License, Version 2.0 (the "License"); 25 | you may not use this file except in compliance with the License. 26 | You may obtain a copy of the License at 27 | 28 | http://www.apache.org/licenses/LICENSE-2.0 29 | 30 | Unless required by applicable law or agreed to in writing, software 31 | distributed under the License is distributed on an "AS IS" BASIS, 32 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 33 | See the License for the specific language governing permissions and 34 | limitations under the License. 35 | 36 | ## Show your support 37 | 38 | Give a ⭐️ if this project helped you! 39 | -------------------------------------------------------------------------------- /test/telegrambot_test.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Rexford Asamoah Agyapong 3 | * Use of this source code is governed by an MIT-style 4 | * license that can be found in the LICENSE file or at 5 | * https://opensource.org/licenses/MIT. 6 | * 7 | */ 8 | 9 | import 'package:telegrambot/telegrambot.dart'; 10 | import 'package:test/test.dart'; 11 | 12 | void main() { 13 | group('Bot Configuration Test', () { 14 | test('should return a facts when valid', () async { 15 | final expected = await BotConfiguration.facts(); 16 | expect(expected['facts'], isA()); 17 | }); 18 | test('should return a jokes when valid', () async { 19 | final expected = await BotConfiguration.jokes(); 20 | expect(expected['value']['joke'], isA()); 21 | }); 22 | 23 | test('should return an insult when valid', () async { 24 | final expected = await BotConfiguration.insult(); 25 | expect(expected['insult'], isA()); 26 | }); 27 | test('should return an advice when valid', () async { 28 | final expected = await BotConfiguration.advice(); 29 | expect(expected['slip']['advice'], isA()); 30 | }); 31 | 32 | test('should return a bible verse when valid', () async { 33 | final expected = await BotConfiguration.bible('James 1:1'); 34 | expect(expected['text'], isA()); 35 | }); 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /lib/src/bot_configuration.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Rexford Asamoah Agyapong 3 | * Use of this source code is governed by an MIT-style 4 | * license that can be found in the LICENSE file or at 5 | * https://opensource.org/licenses/MIT. 6 | * 7 | */ 8 | 9 | import 'dart:convert'; 10 | 11 | import 'package:http/http.dart' as http; 12 | 13 | import 'env.dart'; 14 | 15 | class BotConfiguration { 16 | /// Mange http request 17 | static Future> getData(String variable) async { 18 | http.Response response = await http.get( 19 | Uri.parse(variable), 20 | ); 21 | Map data = json.decode(response.body); 22 | return data; 23 | } 24 | 25 | /// Random Facts 26 | static Future> facts() async { 27 | try { 28 | Map data = await getData(envVars['FACT']!); 29 | return data; 30 | } catch (e) { 31 | return {'facts': 'Something went wrong'}; 32 | } 33 | } 34 | 35 | /// Random Jokes 36 | static Future> jokes() async { 37 | try { 38 | Map data = await getData(envVars['JOKES']!); 39 | return data; 40 | } catch (e) { 41 | return { 42 | 'value': {'joke': 'Something went wrong'} 43 | }; 44 | } 45 | } 46 | 47 | /// Random Insult 48 | static Future> insult() async { 49 | try { 50 | Map data = await getData(envVars['INSULT']!); 51 | return data; 52 | } catch (e) { 53 | return {'insult': 'Something went wrong'}; 54 | } 55 | } 56 | 57 | /// Random Advice 58 | static Future> advice() async { 59 | try { 60 | Map data = await getData(envVars['ADVICE']!); 61 | return data; 62 | } catch (e) { 63 | return { 64 | 'slip': {'advice': 'Something went wrong'} 65 | }; 66 | } 67 | } 68 | 69 | /// Read bible verse 70 | static Future> bible(String book) async { 71 | try { 72 | Map data = await getData('${envVars['BIBLE']!}/$book'); 73 | return data; 74 | } catch (e) { 75 | return {'text': 'Book not found'}; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /bin/telegrambot.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Rexford Asamoah Agyapong 3 | * Use of this source code is governed by an MIT-style 4 | * license that can be found in the LICENSE file or at 5 | * https://opensource.org/licenses/MIT. 6 | * 7 | */ 8 | 9 | import 'package:teledart/teledart.dart'; 10 | import 'package:teledart/telegram.dart'; 11 | import 'package:telegrambot/telegrambot.dart'; 12 | 13 | Future main() async { 14 | // variable to store the bot 15 | var telegram = Telegram(envVars['BOT_TOKEN']!); 16 | var event = Event((await telegram.getMe()).username!); 17 | telegram.deleteWebhook(); 18 | var teledart = TeleDart(telegram, event); 19 | 20 | // Initialize the telegram bot 21 | teledart.start(); 22 | print("::::::::::::::Telegram bot started🎉"); 23 | // welcome message 24 | teledart.onMessage(entityType: 'bot_command', keyword: 'start').listen( 25 | (message) => teledart.telegram.sendMessage( 26 | message.chat.id, 27 | 'Hello Flutter Hero!', 28 | ), 29 | ); 30 | 31 | // hekp messages 32 | teledart.onCommand('help').listen( 33 | (message) => teledart.telegram.sendMessage( 34 | message.chat.id, 35 | help, 36 | ), 37 | ); 38 | 39 | // send a facts message to the user 40 | teledart.onMessage(entityType: 'bot_command', keyword: 'facts').listen( 41 | (message) async { 42 | var response = await BotConfiguration.facts(); 43 | teledart.telegram.sendMessage( 44 | message.chat.id, 45 | "${response['facts']}💙\n${response['url']}", 46 | ); 47 | }, 48 | ); 49 | 50 | // send a random jokes message 51 | teledart.onMessage(entityType: 'bot_command', keyword: 'jokes').listen( 52 | (message) async { 53 | var response = await BotConfiguration.jokes(); 54 | teledart.telegram.sendMessage( 55 | message.chat.id, 56 | "${response['value']['joke']}🤣", 57 | ); 58 | }, 59 | ); 60 | 61 | /// Send random insult messages 62 | teledart.onMessage(entityType: 'bot_command', keyword: 'insult').listen( 63 | (message) async { 64 | var response = await BotConfiguration.insult(); 65 | teledart.telegram.sendMessage( 66 | message.chat.id, 67 | "${response['insult']}😜", 68 | ); 69 | }, 70 | ); 71 | 72 | /// send random advice 73 | teledart.onMessage(entityType: 'bot_command', keyword: 'advice').listen( 74 | (message) async { 75 | var response = await BotConfiguration.advice(); 76 | teledart.telegram.sendMessage( 77 | message.chat.id, 78 | "${response['slip']['advice']}", 79 | ); 80 | }, 81 | ); 82 | 83 | /// Send random bible based on the verse 84 | teledart.onMessage(keyword: RegExp('bible', caseSensitive: false)).listen( 85 | (message) async { 86 | var result = message.text!.replaceAll( 87 | RegExp('bible', caseSensitive: false), 88 | '', 89 | ); 90 | var response = await BotConfiguration.bible(result.trim()); 91 | teledart.telegram.sendMessage( 92 | message.chat.id, 93 | "$result\n${response['text']}", 94 | ); 95 | }, 96 | ); 97 | } 98 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | _fe_analyzer_shared: 5 | dependency: transitive 6 | description: 7 | name: _fe_analyzer_shared 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "31.0.0" 11 | analyzer: 12 | dependency: transitive 13 | description: 14 | name: analyzer 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "2.8.0" 18 | args: 19 | dependency: transitive 20 | description: 21 | name: args 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.3.0" 25 | async: 26 | dependency: transitive 27 | description: 28 | name: async 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "2.8.2" 32 | boolean_selector: 33 | dependency: transitive 34 | description: 35 | name: boolean_selector 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "2.1.0" 39 | charcode: 40 | dependency: transitive 41 | description: 42 | name: charcode 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.3.1" 46 | cli_util: 47 | dependency: transitive 48 | description: 49 | name: cli_util 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "0.3.5" 53 | collection: 54 | dependency: transitive 55 | description: 56 | name: collection 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "1.15.0" 60 | convert: 61 | dependency: transitive 62 | description: 63 | name: convert 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "3.0.1" 67 | coverage: 68 | dependency: transitive 69 | description: 70 | name: coverage 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "1.0.3" 74 | crypto: 75 | dependency: transitive 76 | description: 77 | name: crypto 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "3.0.1" 81 | file: 82 | dependency: transitive 83 | description: 84 | name: file 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "6.1.2" 88 | frontend_server_client: 89 | dependency: transitive 90 | description: 91 | name: frontend_server_client 92 | url: "https://pub.dartlang.org" 93 | source: hosted 94 | version: "2.1.2" 95 | glob: 96 | dependency: transitive 97 | description: 98 | name: glob 99 | url: "https://pub.dartlang.org" 100 | source: hosted 101 | version: "2.0.2" 102 | http: 103 | dependency: "direct main" 104 | description: 105 | name: http 106 | url: "https://pub.dartlang.org" 107 | source: hosted 108 | version: "0.13.4" 109 | http_multi_server: 110 | dependency: transitive 111 | description: 112 | name: http_multi_server 113 | url: "https://pub.dartlang.org" 114 | source: hosted 115 | version: "3.0.1" 116 | http_parser: 117 | dependency: transitive 118 | description: 119 | name: http_parser 120 | url: "https://pub.dartlang.org" 121 | source: hosted 122 | version: "4.0.0" 123 | io: 124 | dependency: transitive 125 | description: 126 | name: io 127 | url: "https://pub.dartlang.org" 128 | source: hosted 129 | version: "1.0.3" 130 | js: 131 | dependency: transitive 132 | description: 133 | name: js 134 | url: "https://pub.dartlang.org" 135 | source: hosted 136 | version: "0.6.3" 137 | json_annotation: 138 | dependency: transitive 139 | description: 140 | name: json_annotation 141 | url: "https://pub.dartlang.org" 142 | source: hosted 143 | version: "4.4.0" 144 | lints: 145 | dependency: "direct dev" 146 | description: 147 | name: lints 148 | url: "https://pub.dartlang.org" 149 | source: hosted 150 | version: "1.0.1" 151 | logging: 152 | dependency: transitive 153 | description: 154 | name: logging 155 | url: "https://pub.dartlang.org" 156 | source: hosted 157 | version: "1.0.2" 158 | matcher: 159 | dependency: transitive 160 | description: 161 | name: matcher 162 | url: "https://pub.dartlang.org" 163 | source: hosted 164 | version: "0.12.11" 165 | meta: 166 | dependency: transitive 167 | description: 168 | name: meta 169 | url: "https://pub.dartlang.org" 170 | source: hosted 171 | version: "1.7.0" 172 | mime: 173 | dependency: transitive 174 | description: 175 | name: mime 176 | url: "https://pub.dartlang.org" 177 | source: hosted 178 | version: "1.0.1" 179 | node_preamble: 180 | dependency: transitive 181 | description: 182 | name: node_preamble 183 | url: "https://pub.dartlang.org" 184 | source: hosted 185 | version: "2.0.1" 186 | package_config: 187 | dependency: transitive 188 | description: 189 | name: package_config 190 | url: "https://pub.dartlang.org" 191 | source: hosted 192 | version: "2.0.2" 193 | path: 194 | dependency: transitive 195 | description: 196 | name: path 197 | url: "https://pub.dartlang.org" 198 | source: hosted 199 | version: "1.8.0" 200 | pool: 201 | dependency: transitive 202 | description: 203 | name: pool 204 | url: "https://pub.dartlang.org" 205 | source: hosted 206 | version: "1.5.0" 207 | pub_semver: 208 | dependency: transitive 209 | description: 210 | name: pub_semver 211 | url: "https://pub.dartlang.org" 212 | source: hosted 213 | version: "2.1.0" 214 | shelf: 215 | dependency: transitive 216 | description: 217 | name: shelf 218 | url: "https://pub.dartlang.org" 219 | source: hosted 220 | version: "1.2.0" 221 | shelf_packages_handler: 222 | dependency: transitive 223 | description: 224 | name: shelf_packages_handler 225 | url: "https://pub.dartlang.org" 226 | source: hosted 227 | version: "3.0.0" 228 | shelf_static: 229 | dependency: transitive 230 | description: 231 | name: shelf_static 232 | url: "https://pub.dartlang.org" 233 | source: hosted 234 | version: "1.1.0" 235 | shelf_web_socket: 236 | dependency: transitive 237 | description: 238 | name: shelf_web_socket 239 | url: "https://pub.dartlang.org" 240 | source: hosted 241 | version: "1.0.1" 242 | source_map_stack_trace: 243 | dependency: transitive 244 | description: 245 | name: source_map_stack_trace 246 | url: "https://pub.dartlang.org" 247 | source: hosted 248 | version: "2.1.0" 249 | source_maps: 250 | dependency: transitive 251 | description: 252 | name: source_maps 253 | url: "https://pub.dartlang.org" 254 | source: hosted 255 | version: "0.10.10" 256 | source_span: 257 | dependency: transitive 258 | description: 259 | name: source_span 260 | url: "https://pub.dartlang.org" 261 | source: hosted 262 | version: "1.8.1" 263 | stack_trace: 264 | dependency: transitive 265 | description: 266 | name: stack_trace 267 | url: "https://pub.dartlang.org" 268 | source: hosted 269 | version: "1.10.0" 270 | stream_channel: 271 | dependency: transitive 272 | description: 273 | name: stream_channel 274 | url: "https://pub.dartlang.org" 275 | source: hosted 276 | version: "2.1.0" 277 | string_scanner: 278 | dependency: transitive 279 | description: 280 | name: string_scanner 281 | url: "https://pub.dartlang.org" 282 | source: hosted 283 | version: "1.1.0" 284 | teledart: 285 | dependency: "direct main" 286 | description: 287 | name: teledart 288 | url: "https://pub.dartlang.org" 289 | source: hosted 290 | version: "0.2.1" 291 | term_glyph: 292 | dependency: transitive 293 | description: 294 | name: term_glyph 295 | url: "https://pub.dartlang.org" 296 | source: hosted 297 | version: "1.2.0" 298 | test: 299 | dependency: "direct dev" 300 | description: 301 | name: test 302 | url: "https://pub.dartlang.org" 303 | source: hosted 304 | version: "1.19.5" 305 | test_api: 306 | dependency: transitive 307 | description: 308 | name: test_api 309 | url: "https://pub.dartlang.org" 310 | source: hosted 311 | version: "0.4.8" 312 | test_core: 313 | dependency: transitive 314 | description: 315 | name: test_core 316 | url: "https://pub.dartlang.org" 317 | source: hosted 318 | version: "0.4.9" 319 | typed_data: 320 | dependency: transitive 321 | description: 322 | name: typed_data 323 | url: "https://pub.dartlang.org" 324 | source: hosted 325 | version: "1.3.0" 326 | vm_service: 327 | dependency: transitive 328 | description: 329 | name: vm_service 330 | url: "https://pub.dartlang.org" 331 | source: hosted 332 | version: "7.5.0" 333 | watcher: 334 | dependency: transitive 335 | description: 336 | name: watcher 337 | url: "https://pub.dartlang.org" 338 | source: hosted 339 | version: "1.0.1" 340 | web_socket_channel: 341 | dependency: transitive 342 | description: 343 | name: web_socket_channel 344 | url: "https://pub.dartlang.org" 345 | source: hosted 346 | version: "2.1.0" 347 | webkit_inspection_protocol: 348 | dependency: transitive 349 | description: 350 | name: webkit_inspection_protocol 351 | url: "https://pub.dartlang.org" 352 | source: hosted 353 | version: "1.0.0" 354 | yaml: 355 | dependency: transitive 356 | description: 357 | name: yaml 358 | url: "https://pub.dartlang.org" 359 | source: hosted 360 | version: "3.1.0" 361 | sdks: 362 | dart: ">=2.14.4 <3.0.0" 363 | --------------------------------------------------------------------------------