mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2026-06-19 15:45:13 +00:00
Compare commits
1046 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c49058dbb4 | |||
| 8e80a8d273 | |||
| cbe057083f | |||
| 5f6138b06b | |||
| 1b99caa2f9 | |||
| e16c1da6b1 | |||
| e1242b3b4a | |||
| 93dde1ac1d | |||
| 05fb9d161a | |||
| a91fe5f8f6 | |||
| 5116a77221 | |||
| 1f597c6b4a | |||
| 1efd330e59 | |||
| af3e8c6440 | |||
| f34c09dd72 | |||
| 97bb04cd38 | |||
| 7ab007d8d4 | |||
| f7b497c1b4 | |||
| 4e60008086 | |||
| 5285f63e4a | |||
| 6647ae3c25 | |||
| e4a132c0e4 | |||
| ca81a75f29 | |||
| da87d4ba78 | |||
| 4753d27bd5 | |||
| eabfc0b06b | |||
| fcda567f8c | |||
| 1c36ff46ad | |||
| ffff0938f4 | |||
| ab2d6eb494 | |||
| fe14000515 | |||
| 5d27059631 | |||
| 00bba73673 | |||
| e9c5ee7ad6 | |||
| f2f62423ba | |||
| 26a0a173f4 | |||
| b736e1e855 | |||
| bd3fa3bb64 | |||
| c252042ddf | |||
| 8475c322af | |||
| dd4c0f0f1d | |||
| 555e36ee80 | |||
| 5134f71380 | |||
| 32268597d9 | |||
| 4feb2553ff | |||
| cd2f956e56 | |||
| 18fdb5ed13 | |||
| 8c698caa12 | |||
| 587908457e | |||
| 4375820863 | |||
| 171c70b4c2 | |||
| f1ee54fa73 | |||
| 90913724ca | |||
| 9d4691e50d | |||
| c4928229d6 | |||
| 2f2337cac1 | |||
| f5c57cd6c6 | |||
| c51c2224da | |||
| 834bf192b9 | |||
| d5486433e5 | |||
| c9ec436d68 | |||
| ad3eec2af8 | |||
| e3fe1d2632 | |||
| 52bd3daa39 | |||
| b4e8209f2c | |||
| f5f95ef8c9 | |||
| 04a871aff5 | |||
| 81a755a7d8 | |||
| 6016aca0ba | |||
| 7c908db901 | |||
| d192b385ea | |||
| f0b2028e3f | |||
| f443003408 | |||
| afc36a235b | |||
| b76337de87 | |||
| 6afee6e0bd | |||
| 27e57bbf58 | |||
| 4990d664bb | |||
| b3e42c3e20 | |||
| c2cce40299 | |||
| a2ed7b26f1 | |||
| 89a3dc8372 | |||
| 9fd298a393 | |||
| ecbc268781 | |||
| c7c21c94ea | |||
| 57efde5e0f | |||
| 31073101a3 | |||
| 1e0ebe89f3 | |||
| 35872d7a8b | |||
| f65b6911ea | |||
| 02af1ea803 | |||
| c4a8ee5175 | |||
| e0539d5992 | |||
| 738e3213a7 | |||
| b41f7e3e79 | |||
| caf72ca490 | |||
| 7635bc0eec | |||
| 703bece155 | |||
| 949f4a4fbd | |||
| 05522e4321 | |||
| 4f101a79bb | |||
| 5b91194cc7 | |||
| 494a7ec1e4 | |||
| fc05d3a626 | |||
| bc77c845ea | |||
| a814e9de6b | |||
| d37b6d6735 | |||
| e479c7f25e | |||
| a30411c9fa | |||
| 881d1d0e25 | |||
| cb6ddfded5 | |||
| bda0244ed8 | |||
| 9338f93d24 | |||
| e10fa66286 | |||
| deb9de0ba0 | |||
| 94fd6851ab | |||
| 897f9615f0 | |||
| 86676d59f1 | |||
| f0b91ecf46 | |||
| bbbc622517 | |||
| 1f5601dae2 | |||
| 3608c2bbe5 | |||
| c28763c5be | |||
| dd8b6219b9 | |||
| 78f9bdcac9 | |||
| da95341d5b | |||
| 98be6abc11 | |||
| b08d41d0ff | |||
| de2d732135 | |||
| 1ff348adbb | |||
| 6b457bada5 | |||
| 74283bd414 | |||
| 41f6591ac6 | |||
| 6d08e1bc7f | |||
| 073d7949dc | |||
| dd91ce1f39 | |||
| 57759d8e6d | |||
| 574fc8cddf | |||
| b040568b07 | |||
| 3076dfc086 | |||
| f8a9722573 | |||
| 527daaf93d | |||
| 986add59ab | |||
| bc62a1813a | |||
| 41432f5b02 | |||
| f737ab780a | |||
| e0e8f6b085 | |||
| 17abf0274e | |||
| 8fab7ad302 | |||
| f31bd91673 | |||
| 32ac617e2e | |||
| 7e7acdeb23 | |||
| 792ad62fe8 | |||
| 25bcfa9b35 | |||
| ff00e211d7 | |||
| d40f0a8309 | |||
| 783f9c375c | |||
| 406303d6bb | |||
| 2534e0df9b | |||
| b06983a94a | |||
| 2f408ab767 | |||
| c8497424b7 | |||
| 80fbe98b44 | |||
| 22e9326610 | |||
| a0bb5730c6 | |||
| 748cc3a35f | |||
| 9a13de4a96 | |||
| 561f1c3f02 | |||
| 3907e64966 | |||
| 1abbca3324 | |||
| e7f4a07b7a | |||
| bb165b6acf | |||
| 20067ff178 | |||
| 41daccce07 | |||
| 786216305c | |||
| 86571bc75d | |||
| 663fa0013d | |||
| 37c7af2e14 | |||
| e70625772c | |||
| 1e398821a0 | |||
| b3142d2974 | |||
| 8278779a23 | |||
| 3aedd78e29 | |||
| 6b90ac9f1c | |||
| 386b91f708 | |||
| 76b9a7d328 | |||
| d90b0f495d | |||
| c4d5eff9f3 | |||
| f45ecee820 | |||
| c340585f33 | |||
| 75490ac757 | |||
| 046e69b1c1 | |||
| 7e0be09c58 | |||
| 18f3f43026 | |||
| 0b2fd120d8 | |||
| 408959e91c | |||
| ab2f6e13c9 | |||
| 108e4264fc | |||
| 68b5562c49 | |||
| e50a3622e1 | |||
| d7e226ec0f | |||
| 7c84516d2b | |||
| 53a91be21f | |||
| 2471eaa778 | |||
| 6bfdff8892 | |||
| 2389b07382 | |||
| c7db9a96cd | |||
| af89cbecf3 | |||
| b987c8937c | |||
| 5a0696b181 | |||
| eb303903ef | |||
| a00f409992 | |||
| dc27ff41ef | |||
| 68ec73afb6 | |||
| 0ace0aa016 | |||
| f5847be8ca | |||
| ba26a8ba5d | |||
| d028d4edd0 | |||
| 4d770843cc | |||
| 53de38f6c9 | |||
| be105a2d4a | |||
| ac55ba007e | |||
| 6bdca1e4f8 | |||
| fd7b571e92 | |||
| 9243cd3507 | |||
| 1b09738191 | |||
| 836c50965a | |||
| 1d9d0fc764 | |||
| e57e6dd645 | |||
| 49122d6a99 | |||
| d445d35ceb | |||
| 703b8d1301 | |||
| 46993d5f2d | |||
| 880746baed | |||
| 8ad1f330ea | |||
| 56b1d4f5ce | |||
| df16846d80 | |||
| 3ac9a1cd71 | |||
| 4d8174edc3 | |||
| 235bb72702 | |||
| 9a5ccb1c2d | |||
| a18640a8d3 | |||
| fdc3ac0cc5 | |||
| d881fa6a5f | |||
| c551d71735 | |||
| bee3d881d1 | |||
| 6ec81dd552 | |||
| 6e9f30ca6e | |||
| 252cafb04c | |||
| d4f7b7165c | |||
| 0ed5e8e1a3 | |||
| 335813a11a | |||
| 10a98211f8 | |||
| b5570ddfa5 | |||
| 99c9544a27 | |||
| 0e0611767a | |||
| 4ba5fbf4f5 | |||
| 4b0be65a76 | |||
| 5971cb35f8 | |||
| 6e5302c089 | |||
| 5aab4525c2 | |||
| 62c651d167 | |||
| 41e457f5ed | |||
| 4ce0ab53d0 | |||
| d940afa718 | |||
| a327e9d6ff | |||
| 5e5510d42b | |||
| 73c60ee817 | |||
| 474d5f0c9f | |||
| 74a2baf03d | |||
| 0612385233 | |||
| c0489db17c | |||
| 592352c849 | |||
| 9d367e9f2c | |||
| d86ca30601 | |||
| ec15e866be | |||
| 998040da92 | |||
| 0c74b3cfb9 | |||
| 0ca3ef7a38 | |||
| e160355190 | |||
| d80e0b4b8c | |||
| 96d98084c7 | |||
| 865bba3f3e | |||
| 2745023854 | |||
| fd15e51e28 | |||
| d093506ef2 | |||
| 7f463131aa | |||
| a79f636345 | |||
| 4a4dbcdbf8 | |||
| 7b13adb34b | |||
| e905f310c4 | |||
| 631c825c1d | |||
| ed7ecddb8d | |||
| a3dae1f112 | |||
| 1d33c39a1b | |||
| 14d3f62e44 | |||
| 931b22f49e | |||
| f0aafda1b9 | |||
| ecb6ddd83d | |||
| cb46b0373f | |||
| 35f6de326b | |||
| a686db2c6f | |||
| 1f29093027 | |||
| 0e34c0395f | |||
| 49385493f4 | |||
| f107070db2 | |||
| 3f28633e79 | |||
| 8ff8d57998 | |||
| e9a782a3c8 | |||
| 1f83e7ae4e | |||
| 856f4460fc | |||
| c5ad34b074 | |||
| 78d1faa21e | |||
| 4ac8f86156 | |||
| 8a087dce69 | |||
| 82282ae125 | |||
| 02243f6fda | |||
| 05a90dc3bc | |||
| 1425533871 | |||
| 186db99565 | |||
| 835c4d04c1 | |||
| 5b867b2290 | |||
| ff66a9fa21 | |||
| 3189d4d339 | |||
| d66493b038 | |||
| eca5f66cd6 | |||
| f7aec236e7 | |||
| fc7c161018 | |||
| c0d63deae3 | |||
| f152195a68 | |||
| b2fd2ba697 | |||
| d21ee819b7 | |||
| d3cec77e78 | |||
| 94e35d5b1c | |||
| 39ba575a4d | |||
| 87ac962805 | |||
| 01cca924ca | |||
| 14cb13acfd | |||
| 4ecb4911db | |||
| d47787876a | |||
| 4b173bfd52 | |||
| bfbad1625e | |||
| 564baea8c3 | |||
| adc3104214 | |||
| 2f7cccfc9f | |||
| 5a7a62c3d8 | |||
| ca1fff25f7 | |||
| 0d6b3a5411 | |||
| 6cacea96f7 | |||
| 4775107af0 | |||
| fe06708d34 | |||
| 6390b7fd9b | |||
| 2160ce70a6 | |||
| 5e5125444c | |||
| f86e6f97db | |||
| 325d8131ee | |||
| f68b8c3a4a | |||
| 7c8a0e00c0 | |||
| 4c0737d7c1 | |||
| 5dd95f1968 | |||
| b30417681b | |||
| 37e48b4707 | |||
| 9e306dce16 | |||
| 9b1a55f9e9 | |||
| 252abb138d | |||
| 203364d939 | |||
| 1450478d27 | |||
| 5b36a85e63 | |||
| 7daf26198e | |||
| 8c0de59d46 | |||
| d46d9a711d | |||
| b444cd7bce | |||
| 93e15fa9f8 | |||
| d383c10d4e | |||
| 012bbe1307 | |||
| 4faa4774bd | |||
| cb79317354 | |||
| cfdfdeb4fc | |||
| 67a2d31edf | |||
| 0669c72fe3 | |||
| 185c40da79 | |||
| 5315e072cb | |||
| a8255e4f51 | |||
| e56c6dfab6 | |||
| 263310be36 | |||
| 720c4d22d8 | |||
| 3be8b9ecb9 | |||
| bb36c725af | |||
| ba7e1cada7 | |||
| 9bf5da5ed3 | |||
| c0dd9c6ffc | |||
| 10a96481f5 | |||
| 9a96ad8efd | |||
| fc277d7393 | |||
| 48eb623f15 | |||
| 9a340d2ea9 | |||
| 693df6dc2c | |||
| a98919a86e | |||
| 9790d6d8dc | |||
| 7913d09295 | |||
| 1db337fe2b | |||
| b40a59f509 | |||
| 0d9d5032ef | |||
| de5619f3ca | |||
| b6fceefc80 | |||
| 687a3b0ba1 | |||
| bf5ba9a369 | |||
| d879a0d018 | |||
| ad211655ea | |||
| 3a0eb588cb | |||
| c9bfa71ff9 | |||
| 5f19452dd7 | |||
| 5cccf2603b | |||
| 185b080daa | |||
| cb99341848 | |||
| 1544f612ae | |||
| 53d1d5f589 | |||
| 6992a7a369 | |||
| a846c8fd86 | |||
| 0e5129e59f | |||
| 90576de9e2 | |||
| 79ca07f839 | |||
| 63c793aad4 | |||
| 5e80efaa54 | |||
| a114f70249 | |||
| 31fba47829 | |||
| 360c3077ea | |||
| f2a92ccf46 | |||
| dd8f94885a | |||
| 06ec465c5f | |||
| 79228b0655 | |||
| b2045717d6 | |||
| 15cc410c10 | |||
| f6524b0207 | |||
| ecc86d4bcd | |||
| 56b17f2a17 | |||
| 8bf4a6fdda | |||
| 109af62425 | |||
| ec27edef58 | |||
| 7231eaa349 | |||
| 1876867ec7 | |||
| 17509fc24f | |||
| 2d2b269932 | |||
| 802a74c606 | |||
| c4074f740e | |||
| 1e0ee0694f | |||
| 6a7c0bb584 | |||
| fb2fc3842b | |||
| c794c3520b | |||
| 0fd013feec | |||
| 1834d6c754 | |||
| f51564f7cd | |||
| 624160e1db | |||
| d2f2b74bdb | |||
| 85f1b1af0c | |||
| 6cb177d2a7 | |||
| b5cbf17ef5 | |||
| 0d0ad1334c | |||
| b9305ca7ac | |||
| 0e21609382 | |||
| 95fde0c6c4 | |||
| 884bb41d4a | |||
| a9b305edd0 | |||
| 1e19084a0d | |||
| e179b27f57 | |||
| 8b95f9cbeb | |||
| 390184f605 | |||
| 086fa1251c | |||
| 60f9aede07 | |||
| c411ef7822 | |||
| e1de7220df | |||
| 429ea92254 | |||
| 751402a0d3 | |||
| 2af15cadd6 | |||
| 93e19dc2ae | |||
| c2f5309cbf | |||
| 1657e43904 | |||
| 23eba8a24e | |||
| ed170e1595 | |||
| 46ca28f01c | |||
| b99518e8b8 | |||
| 62045316fe | |||
| 736d62e20d | |||
| 68dca31f15 | |||
| 9a523dbc40 | |||
| 0342a5b30b | |||
| b7f83cf375 | |||
| d9d48f5c91 | |||
| 01b90e7ede | |||
| ba0ea4f268 | |||
| a0788788da | |||
| a264530540 | |||
| 33f047a3dc | |||
| 88eb332c99 | |||
| eb6bafc003 | |||
| f4603831b8 | |||
| b41e1ab127 | |||
| 5c71ebce52 | |||
| 6db377d56d | |||
| da193711b1 | |||
| 4f26bdd18f | |||
| 808945b623 | |||
| 63a83d4cc2 | |||
| c43b348117 | |||
| 45a47d54bd | |||
| 5e7f2688be | |||
| 7199d2894f | |||
| d9a58fd904 | |||
| cf9897e74b | |||
| 30308bdcc6 | |||
| af62c5be8e | |||
| cd7bc8dfac | |||
| 150914cf25 | |||
| 19390b9659 | |||
| fac4eb6438 | |||
| 2939885c5b | |||
| f07f33e160 | |||
| 0ddcb16889 | |||
| 594b81e463 | |||
| 41d0d45e2f | |||
| 1e4ae6546f | |||
| fd170773e2 | |||
| d1516f66ac | |||
| 739e218eb7 | |||
| dcea2c8015 | |||
| 98112d3987 | |||
| 45a4689fd0 | |||
| 82030c4109 | |||
| 25595e6d9e | |||
| 9637a8748c | |||
| 00e2b4815a | |||
| fb34f81533 | |||
| 3d89f6b284 | |||
| 7a8e84b46f | |||
| 8ad34fc3c0 | |||
| 00f4328bab | |||
| 8b196ce71f | |||
| 196d1fcc3d | |||
| 7ff7397d0f | |||
| 0c676b1a75 | |||
| dc9b77e02c | |||
| e7b339d527 | |||
| 5958da0031 | |||
| 0600b2634e | |||
| f8f16f0fe9 | |||
| 433110abe9 | |||
| 793437fec7 | |||
| a0a040a9c2 | |||
| f0e7a3316c | |||
| 218e22631c | |||
| 75c6662f35 | |||
| cd42524fd4 | |||
| b5875a3abd | |||
| 139cbc657d | |||
| 4aca4d1d1f | |||
| 2e6db1330f | |||
| ccb24d1288 | |||
| 26f87c4873 | |||
| fc618274ae | |||
| d2623d2671 | |||
| ec8cd37345 | |||
| ee56ffc9a5 | |||
| ca8404adb7 | |||
| d5b35e7e1d | |||
| df8e388189 | |||
| a2632b777a | |||
| e0cf0abb1b | |||
| ec13a36bdd | |||
| d05fa1275a | |||
| e189e8ad05 | |||
| efd10507d0 | |||
| 2338377eda | |||
| ca526fba73 | |||
| e2cc8db992 | |||
| 04c86813b3 | |||
| 7d39e1bdef | |||
| d415a60ebf | |||
| fd7baa2236 | |||
| 4945d99de6 | |||
| c103c05679 | |||
| 8afea8cd69 | |||
| 9d77a3b503 | |||
| 3e978277b3 | |||
| d02e656700 | |||
| edf4e8abbe | |||
| c55c5408b1 | |||
| d1dc32d849 | |||
| fc73948c82 | |||
| 70dfb88eb5 | |||
| 2a01292a64 | |||
| 5b9ec7ff40 | |||
| bec81b5c3b | |||
| f5a1e00af9 | |||
| eac3d8842d | |||
| 17ac73c3c4 | |||
| 4a5001668d | |||
| 7ebbc60694 | |||
| 9c81b810f2 | |||
| e8363f2440 | |||
| e82ae432f7 | |||
| d4beb94059 | |||
| 029705e0af | |||
| 2859a8873f | |||
| e5df2072e4 | |||
| 034d0054ea | |||
| 0edb2e0a0f | |||
| 2436cab2e5 | |||
| 3e7dc705db | |||
| cabbef8780 | |||
| 08836c60ca | |||
| 6d2e159d75 | |||
| 8d94c14504 | |||
| 69183d85f7 | |||
| 142cc6e6ad | |||
| d4370e49e5 | |||
| df1d639144 | |||
| c13af4d61d | |||
| 516d41eac0 | |||
| 702544f709 | |||
| 713f0d1335 | |||
| a383cee558 | |||
| 44645d2cc6 | |||
| 77f00e386c | |||
| 1000a56e0d | |||
| c3bca9af48 | |||
| 9eec34edd1 | |||
| 383a2d3742 | |||
| d1e4eeaf30 | |||
| 80b53f1ab7 | |||
| 0faa38b8af | |||
| 5a2a541ae0 | |||
| 7508c2f8bf | |||
| bb2cce56a3 | |||
| 2c12bd6775 | |||
| 5b05bcc8f2 | |||
| adb446abf6 | |||
| 545767ea40 | |||
| 7931045bf3 | |||
| 17c2857622 | |||
| cbcbfab45f | |||
| 1dc9907a70 | |||
| b8c9992eff | |||
| fe26c94440 | |||
| a6650de93d | |||
| dc032b349c | |||
| 5c2458bfd8 | |||
| 6166e7f07a | |||
| 2a7b03e7c2 | |||
| da97c1741c | |||
| 70445dc054 | |||
| d3a02405b2 | |||
| dfc75cc64e | |||
| 332667c98b | |||
| f71c40e0b8 | |||
| 9f55c15cc7 | |||
| a32ae8b895 | |||
| a539a0c3a5 | |||
| b4abf75524 | |||
| 12d71d5a91 | |||
| 48bf6bfab0 | |||
| 7227ca3aab | |||
| 307d2621d7 | |||
| 831a0a31e5 | |||
| d10b657521 | |||
| ef1012b722 | |||
| 5fd7a4fe0d | |||
| 85d20ba549 | |||
| 48c1673d7c | |||
| af6eb457c1 | |||
| 6ece89bc56 | |||
| c69cdfd184 | |||
| 6dab7068c3 | |||
| fd90c16265 | |||
| 77ca036d02 | |||
| e2e98e86db | |||
| 71f82d57d9 | |||
| 6a3d514ed1 | |||
| 6aa2e510a3 | |||
| 099deabf4e | |||
| b78ceeed10 | |||
| a8240dca1f | |||
| 7e207433cc | |||
| fc6d0f4f07 | |||
| 4fef5bcceb | |||
| fc64cc0a4a | |||
| 14a9962296 | |||
| 4197400853 | |||
| aa8966832b | |||
| e27427676d | |||
| 8175fd7b53 | |||
| 2875bae881 | |||
| c756aa1c02 | |||
| 6d5c3187fc | |||
| c2f04331f3 | |||
| 5293ec49ff | |||
| 9319903343 | |||
| 95e2aad9bd | |||
| 73f4f26da5 | |||
| 24b2bf335c | |||
| fc3fa0f515 | |||
| 87657bcd70 | |||
| 81b58c7d00 | |||
| dd7d1255d1 | |||
| f813d4f5ec | |||
| 623863cee1 | |||
| aa125e59fb | |||
| 68c844df0c | |||
| 3779d454f3 | |||
| 5d168bd479 | |||
| 1c8bb21790 | |||
| 054c976ad6 | |||
| bc2679f2ae | |||
| 17dae68654 | |||
| 7734c1d6a6 | |||
| aeca3ca174 | |||
| 21fdaa4ff7 | |||
| 79f29c4b9e | |||
| a2d8ca3663 | |||
| 6f76bfc2de | |||
| 97ebebefc1 | |||
| 119743433d | |||
| b0ad07f30f | |||
| 114cb787ea | |||
| 5d1ef673a3 | |||
| 3e1cb08567 | |||
| 29a4062945 | |||
| 2ff6fe9901 | |||
| 34b91f5062 | |||
| cc6c4a6eb9 | |||
| fc9456e1a8 | |||
| 41ba57f064 | |||
| b205751aee | |||
| c4f13bd1bb | |||
| 7d7397317e | |||
| 631954e5d9 | |||
| 90ed128a61 | |||
| 2a2b679362 | |||
| f75e329225 | |||
| ea7c54ba07 | |||
| 3c7b037eaa | |||
| c15a1bc151 | |||
| 9e7314134e | |||
| 37271e4a02 | |||
| 0e78606d37 | |||
| cb0736fb3d | |||
| e0233a59a0 | |||
| 6e158042e1 | |||
| d791a6ee89 | |||
| 5a3e142358 | |||
| 37a58fe1ad | |||
| 80281cc66d | |||
| fffa9d8a7c | |||
| 806b71030f | |||
| 764c5dac53 | |||
| 007dc5807a | |||
| 16534872a7 | |||
| a13245dfbf | |||
| 6622ea3ec0 | |||
| bcadfc5398 | |||
| 89ecb04a85 | |||
| 56ab40d94f | |||
| f5ac1ae067 | |||
| 23507202e8 | |||
| 185bff7117 | |||
| 9f07900d99 | |||
| 809fe4b74f | |||
| 8a4d5c5de7 | |||
| 1976822dd0 | |||
| e60694a8cc | |||
| 14b4c1ac62 | |||
| d5890d403b | |||
| ef569b68c6 | |||
| 628a4c4eac | |||
| 83d2ca3aa7 | |||
| 29cdfe671e | |||
| f21b6046c5 | |||
| 8090658ab4 | |||
| f49f592f0d | |||
| c2853fa1ef | |||
| e1f3f346bc | |||
| 1005ad57ce | |||
| 0b72acc7c8 | |||
| 8d267ed896 | |||
| 83812f3af6 | |||
| 658b5ff1c0 | |||
| 593153128c | |||
| d91f210f7c | |||
| 65177e791f | |||
| 15501e185b | |||
| 1782d0d19b | |||
| 88fbf3b5cf | |||
| c7a1d8dca3 | |||
| 3e732a0736 | |||
| 628e1b743a | |||
| e4de3f00b8 | |||
| 32c021fdd5 | |||
| a6e5a71e05 | |||
| 4d87e236be | |||
| 29ab0556f0 | |||
| fca8aee177 | |||
| 6a80a33aef | |||
| 7c9928c58f | |||
| 0cd7aa92ae | |||
| 6626d4534e | |||
| 6b309397e8 | |||
| 618df51811 | |||
| d38add1a1c | |||
| 1c7e784662 | |||
| 0006294f29 | |||
| c1f194a310 | |||
| cccd6e5baf | |||
| a0baa68cf3 | |||
| 62b79df0a4 | |||
| 1246039872 | |||
| ed6dd76ae8 | |||
| 70de2bd3f1 | |||
| 8bde310ec7 | |||
| be368f7d74 | |||
| 9defc41774 | |||
| ee8b78aa0d | |||
| 0b8fd24771 | |||
| 396dc6cd3c | |||
| ba3d174fde | |||
| ab313488ad | |||
| d808462fb6 | |||
| 71e73c3999 | |||
| a55df8b5e1 | |||
| f59efe0f4b | |||
| 1b79a57673 | |||
| ae59a18e2d | |||
| 12201f392d | |||
| 8f3fe123e3 | |||
| 04050ca883 | |||
| c3b3d51286 | |||
| 10451509f1 | |||
| ff0d724f32 | |||
| c64e577049 | |||
| f08dca0af6 | |||
| 8c0bcbf5bb | |||
| 596fc2aeda | |||
| 968b19e8b7 | |||
| 7993328ff7 | |||
| 16349ac69a | |||
| 45712c52f1 | |||
| 235dcd2ad2 | |||
| ed92d1c254 | |||
| 0b4c23f50e | |||
| 63c895c0a0 | |||
| 3162bc60e9 | |||
| 206802cf4d | |||
| 5eb4f8e5cd | |||
| 0a27e3927b | |||
| 401add78d3 | |||
| af375eb402 | |||
| 2797111ced | |||
| d7d4889c50 | |||
| bf356e124f | |||
| d7fd43ca79 | |||
| 42e11d169e | |||
| c1fae0b5ee | |||
| ef99bab435 | |||
| 93afd3eabe | |||
| 61dac76bee | |||
| 245f5abc45 | |||
| 0f8f6584ce | |||
| dd498ded00 | |||
| 5d2999818b | |||
| eb1f197ff4 | |||
| 4bc03ed56a | |||
| 9191d333ca | |||
| c6533a2d69 | |||
| 6c13762c93 | |||
| 06c09b96cf | |||
| 8a5ec3b2a1 | |||
| 21c26aed2f | |||
| 5fe1481ae9 | |||
| 1879cff82d | |||
| cd5e805692 | |||
| 90a77ab7a1 | |||
| 3928e27cf4 | |||
| 45b1124553 | |||
| 252b43dcb7 | |||
| c19a84ac05 | |||
| 404fdc2dd7 | |||
| 2ec56abe7e | |||
| 63a8700258 | |||
| d363185031 | |||
| aabaaa9049 | |||
| eb2be61eac | |||
| 0688691974 | |||
| d3d5c1e907 | |||
| cbf66d411d | |||
| 0e5b48f3b4 | |||
| df7cfdc8d0 | |||
| 89015e5ecc | |||
| 025d4c9a75 | |||
| d3bea4c3b4 | |||
| a6c12adda2 | |||
| dcb9129809 | |||
| bd1f171f51 | |||
| 54efb034a4 | |||
| fe94f146bb | |||
| 22b492762b | |||
| fea0c5cc2b | |||
| 688d6af541 | |||
| bcbd32cdd3 | |||
| 3fa8b97ed2 | |||
| 7cd4e2e205 | |||
| f2b0cb46a2 | |||
| cf5d184766 | |||
| 5738dc553f | |||
| 386accab80 | |||
| e7686db759 | |||
| 6c9490f2c6 | |||
| 855ab19dea | |||
| 797a3e6ea4 | |||
| bbd443d397 | |||
| 4e1597c614 | |||
| 75e338d5df | |||
| 1919f873c0 | |||
| a1f35355f6 | |||
| c4c17e8036 | |||
| 3024c1ce3d | |||
| b79530b10c | |||
| 778c63a6d3 | |||
| f623db06ea | |||
| 026673dc05 | |||
| 6893da5dd3 | |||
| d5a9c185f0 | |||
| cbdeacd22d | |||
| 1e2fdedc45 | |||
| c1c0e66233 | |||
| eb557e0eba | |||
| a7ac4193fe | |||
| 354bfcad79 | |||
| a1e12d424c | |||
| 38c6d002c8 | |||
| c8a14bf34d | |||
| 53c44f14bd | |||
| e75deea25c | |||
| 17b8bb4881 | |||
| 009862593b | |||
| e2fa052f54 | |||
| dcfe08dbda | |||
| dc2dfa24ad | |||
| ce58f45c4f | |||
| 7059930b5d | |||
| 77977b99b1 | |||
| ed77afaab9 | |||
| c7f2add463 | |||
| 8a074fd719 | |||
| cfa5e8a6fe | |||
| c6bf13e407 | |||
| 6237bb636c | |||
| 0496781501 | |||
| 4a761d0611 | |||
| 714adc13ee | |||
| fa387d1821 | |||
| 073d43fd75 | |||
| 5c0eeac036 | |||
| 64ca4d7b82 | |||
| 6d7542ce50 | |||
| 0cfaaa590c | |||
| 48bb8a2413 | |||
| 36dc1633f5 | |||
| e1edeb7bec | |||
| a409fc511d | |||
| 69d705a99f | |||
| cdcf2481ba | |||
| 5c4f0f152a | |||
| f29a6f0e36 | |||
| 1b0c3731de | |||
| 4be946d116 | |||
| 73e36e3b73 | |||
| 6141e76693 | |||
| 61ef876532 | |||
| 060442e0ae | |||
| 2254440671 | |||
| 65a224884f | |||
| 0218aa2f4e | |||
| 28e81ee9f6 | |||
| 6ffcdcf2fe | |||
| 89bab207b6 | |||
| 69aa1c252b | |||
| 5b8f41b3c1 | |||
| ea5c690e7a | |||
| 9145f24efa | |||
| c590d9c2fd | |||
| cfd401f22b | |||
| 7f790c3cb2 | |||
| 30749c3b66 | |||
| 8f0447156b | |||
| df000f8086 | |||
| 3d835527e0 | |||
| 323052a6c9 | |||
| ef4871cce1 | |||
| f355af1d2b | |||
| 121e365348 | |||
| 82f1d18f4b | |||
| 79cdb6cafe | |||
| 49ff02dcf4 | |||
| be23ff5d29 | |||
| 72a7355c2f | |||
| 64cf9ed941 | |||
| bb84113272 | |||
| d740ce89cf | |||
| 245238b3a2 | |||
| e693922fe8 | |||
| 62f06da897 | |||
| 05b7fda4a1 | |||
| 910959b672 | |||
| 881b0b3d06 | |||
| 95ecd44c0e | |||
| 9241534ba6 | |||
| 256d219862 | |||
| 8fddd3b027 | |||
| 3f3cb1edc5 | |||
| f037a8c776 | |||
| 98c489c44f | |||
| a86fc6c2ac | |||
| 1c4595123c | |||
| 942706e20f | |||
| 6837bef9bb | |||
| 6132e65dc3 | |||
| 0f924508f7 | |||
| b20f5af1e1 | |||
| ce58f72566 | |||
| f4839a3afe | |||
| 25f9eb7898 | |||
| c625b9a449 | |||
| e239315cca | |||
| ccdb999e37 | |||
| 2f99b785b2 | |||
| 41eb45918c | |||
| d43e292499 | |||
| fdb5f2339c | |||
| d03a394075 | |||
| 3658b4231c | |||
| 1d6e9502cb | |||
| 92ca92341a | |||
| 0691b1e971 | |||
| 8746222cf6 | |||
| 32dc05ed36 | |||
| ba5902c1d4 | |||
| 80371c9f6e | |||
| a8fd6b5061 |
@@ -0,0 +1,5 @@
|
||||
languages:
|
||||
Python: true
|
||||
exclude_paths:
|
||||
- "telegram/emoji.py"
|
||||
- "tests/*"
|
||||
@@ -0,0 +1,5 @@
|
||||
[run]
|
||||
source = telegram
|
||||
|
||||
[report]
|
||||
omit = tests/
|
||||
@@ -0,0 +1,201 @@
|
||||
How To Contribute
|
||||
===================
|
||||
|
||||
Every open source project lives from the generous help by contributors that sacrifice their time and ``python-telegram-bot`` is no different. To make participation as pleasant as possible, this project adheres to the `Code of Conduct`_ by the Python Software Foundation.
|
||||
|
||||
Setting things up
|
||||
-------------------
|
||||
|
||||
1. Fork the ``python-telegram-bot`` repository to your GitHub account.
|
||||
|
||||
2. Clone your forked repository of ``python-telegram-bot`` to your computer:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ git clone https://github.com/<your username>/python-telegram-bot
|
||||
$ cd python-telegram-bot
|
||||
|
||||
3. Add a track to the original repository:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ git remote add upstream https://github.com/python-telegram-bot/python-telegram-bot
|
||||
|
||||
4. Install dependencies:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ sudo pip install -r requirements.txt -r requirements-dev.txt
|
||||
|
||||
|
||||
5. Install pre-commit hooks:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ pre-commit install
|
||||
|
||||
Finding something to do
|
||||
###################
|
||||
|
||||
If you already know what you'd like to work on, you can skip this section.
|
||||
|
||||
If you have an idea for something to do, first check if it's already been filed on the `issue tracker`_. If so, add a comment to the issue saying you'd like to work on it, and we'll help you get started! Otherwise, please file a new issue and assign yourself to it.
|
||||
|
||||
Another great way to start contributing is by writing tests. Tests are really important because they help prevent developers from accidentally breaking existing code, allowing them to build cool things faster. If you're interested in helping out, let the development team know by posting to the `developers' mailing list`_, and we'll help you get started.
|
||||
|
||||
Instructions for making a code change
|
||||
####################
|
||||
|
||||
The central development branch is ``master``, which should be clean and ready for release at any time. In general, all changes should be done as feature branches based off of ``master``.
|
||||
|
||||
Here's how to make a one-off code change.
|
||||
|
||||
1. **Choose a descriptive branch name.** It should be lowercase, hyphen-separated, and a noun describing the change (so, ``fuzzy-rules``, but not ``implement-fuzzy-rules``). Also, it shouldn't start with ``hotfix`` or ``release``.
|
||||
|
||||
2. **Create a new branch with this name, starting from** ``master``. In other words, run:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ git fetch upstream
|
||||
$ git checkout master
|
||||
$ git merge upstream/master
|
||||
$ git checkout -b your-branch-name
|
||||
|
||||
3. **Make a commit to your feature branch**. Each commit should be self-contained and have a descriptive commit message that helps other developers understand why the changes were made.
|
||||
|
||||
- You can refer to relevant issues in the commit message by writing, e.g., "#105".
|
||||
|
||||
- Your code should adhere to the `PEP 8 Style Guide`_, with the exception that we have a maximum line length of 99.
|
||||
|
||||
- For consistency, please conform to `Google Python Style Guide`_ and `Google Python Style Docstrings`_. In addition, code should be formatted consistently with other code around it.
|
||||
|
||||
- The following exceptions to the above (Google's) style guides applies:
|
||||
|
||||
- Documenting types of global variables and complex types of class members can be done using the Sphinx docstring convention.
|
||||
|
||||
- Please ensure that the code you write is well-tested.
|
||||
|
||||
- Don’t break backward compatibility.
|
||||
|
||||
- Add yourself to the AUTHORS.rst_ file in an alphabetical fashion.
|
||||
|
||||
- Before making a commit ensure that all automated tests still pass:
|
||||
|
||||
.. code-block::
|
||||
|
||||
$ make test
|
||||
|
||||
- To actually make the commit (this will trigger tests for yapf, lint and pep8 automatically):
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ git add your-file-changed.py
|
||||
|
||||
- yapf may change code formatting, make sure to re-add them to your commit.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ git commit -a -m "your-commit-message-here"
|
||||
|
||||
- Finally, push it to your GitHub fork, run:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ git push origin your-branch-name
|
||||
|
||||
4. **When your feature is ready to merge, create a pull request.**
|
||||
|
||||
- Go to your fork on GitHub, select your branch from the dropdown menu, and click "New pull request".
|
||||
|
||||
- Add a descriptive comment explaining the purpose of the branch (e.g. "Add the new API feature to create inline bot queries."). This will tell the reviewer what the purpose of the branch is.
|
||||
|
||||
- Click "Create pull request". An admin will assign a reviewer to your commit.
|
||||
|
||||
5. **Address review comments until all reviewers give LGTM ('looks good to me').**
|
||||
|
||||
- When your reviewer has reviewed the code, you'll get an email. You'll need to respond in two ways:
|
||||
|
||||
- Make a new commit addressing the comments you agree with, and push it to the same branch. Ideally, the commit message would explain what the commit does (e.g. "Fix lint error"), but if there are lots of disparate review comments, it's fine to refer to the original commit message and add something like "(address review comments)".
|
||||
|
||||
- In addition, please reply to each comment. Each reply should be either "Done" or a response explaining why the corresponding suggestion wasn't implemented. All comments must be resolved before LGTM can be given.
|
||||
|
||||
- Resolve any merge conflicts that arise. To resolve conflicts between 'your-branch-name' (in your fork) and 'master' (in the ``python-telegram-bot`` repository), run:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ git checkout your-branch-name
|
||||
$ git fetch upstream
|
||||
$ git merge upstream/master
|
||||
$ ...[fix the conflicts]...
|
||||
$ ...[make sure the tests pass before committing]...
|
||||
$ git commit -a
|
||||
$ git push origin your-branch-name
|
||||
|
||||
- At the end, the reviewer will merge the pull request.
|
||||
|
||||
6. **Tidy up!** Delete the feature branch from both your local clone and the GitHub repository:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ git branch -D your-branch-name
|
||||
$ git push origin --delete your-branch-name
|
||||
|
||||
7. **Celebrate.** Congratulations, you have contributed to ``python-telegram-bot``!
|
||||
|
||||
Style commandments
|
||||
---------------------
|
||||
|
||||
Specific commandments
|
||||
#####################
|
||||
|
||||
- Avoid using "double quotes" where you can reasonably use 'single quotes'.
|
||||
|
||||
AssertEqual argument order
|
||||
######################
|
||||
|
||||
- assertEqual method's arguments should be in ('actual', 'expected') order.
|
||||
|
||||
Properly calling callables
|
||||
#######################
|
||||
|
||||
Methods, functions and classes can specify optional parameters (with default
|
||||
values) using Python's keyword arg syntax. When providing a value to such a
|
||||
callable we prefer that the call also uses keyword arg syntax. For example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# GOOD
|
||||
f(0, optional=True)
|
||||
|
||||
# BAD
|
||||
f(0, True)
|
||||
|
||||
This gives us the flexibility to re-order arguments and more importantly
|
||||
to add new required arguments. It's also more explicit and easier to read.
|
||||
|
||||
Properly defining optional arguments
|
||||
########################
|
||||
|
||||
It's always good to not initialize optional arguments at class creation,
|
||||
instead use ``**kwargs`` to get them. It's well known Telegram API can
|
||||
change without notice, in that case if a new argument is added it won't
|
||||
break the API classes. For example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# GOOD
|
||||
def __init__(self, id, name, **kwargs):
|
||||
self.last_name = kwargs.get('last_name', '')
|
||||
|
||||
# BAD
|
||||
def __init__(self, id, name, last_name=''):
|
||||
self.last_name = last_name
|
||||
|
||||
|
||||
.. _`Code of Conduct`: https://www.python.org/psf/codeofconduct/
|
||||
.. _`issue tracker`: https://github.com/python-telegram-bot/python-telegram-bot/issues
|
||||
.. _`developers' mailing list`: mailto:devs@python-telegram-bot.org
|
||||
.. _`PEP 8 Style Guide`: https://www.python.org/dev/peps/pep-0008/
|
||||
.. _`Google Python Style Guide`: https://google-styleguide.googlecode.com/svn/trunk/pyguide.html
|
||||
.. _`Google Python Style Docstrings`: http://sphinx-doc.org/latest/ext/example_google.html
|
||||
.. _AUTHORS.rst: ../AUTHORS.rst
|
||||
@@ -0,0 +1,31 @@
|
||||
<!--
|
||||
Thanks for reporting issues of python-telegram-bot!
|
||||
To make it easier for us to help you please enter detailed information below.
|
||||
|
||||
Please note, we only support the latest version of python-telegram-bot and
|
||||
master branch. Please make sure to upgrade & recreate the issue on the latest
|
||||
version prior to opening an issue.
|
||||
-->
|
||||
### Steps to reproduce
|
||||
1.
|
||||
|
||||
2.
|
||||
|
||||
3.
|
||||
|
||||
### Expected behaviour
|
||||
Tell us what should happen
|
||||
|
||||
### Actual behaviour
|
||||
Tell us what happens instead
|
||||
|
||||
### Configuration
|
||||
**Operating System:**
|
||||
|
||||
|
||||
**Version of Python, python-telegram-bot & dependencies:**
|
||||
|
||||
``$ python -m telegram``
|
||||
|
||||
### Logs
|
||||
Insert logs here (if necessary)
|
||||
+11
@@ -43,6 +43,7 @@ htmlcov/
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
.coveralls.yml
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
@@ -57,3 +58,13 @@ docs/_build/
|
||||
# PyBuilder
|
||||
target/
|
||||
.idea/
|
||||
|
||||
# Sublime Text 2
|
||||
*.sublime*
|
||||
|
||||
# unitests files
|
||||
telegram.mp3
|
||||
telegram.mp4
|
||||
telegram.ogg
|
||||
telegram.png
|
||||
telegram.webp
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
- repo: git://github.com/pre-commit/mirrors-yapf
|
||||
sha: v0.11.0
|
||||
hooks:
|
||||
- id: yapf
|
||||
files: ^(telegram|tests)/.*\.py$
|
||||
- repo: git://github.com/pre-commit/pre-commit-hooks
|
||||
sha: 18d7035de5388cc7775be57f529c154bf541aab9
|
||||
hooks:
|
||||
- id: flake8
|
||||
files: ^telegram/.*\.py$
|
||||
- repo: git://github.com/pre-commit/mirrors-pylint
|
||||
sha: v1.5.5
|
||||
hooks:
|
||||
- id: pylint
|
||||
files: ^telegram/.*\.py$
|
||||
args:
|
||||
- --errors-only
|
||||
- --disable=no-name-in-module,import-error
|
||||
+8
-2
@@ -1,12 +1,18 @@
|
||||
language: python
|
||||
python:
|
||||
- "2.6"
|
||||
- "2.7"
|
||||
- "3.3"
|
||||
- "3.4"
|
||||
- "3.5"
|
||||
- "pypy"
|
||||
- "pypy3"
|
||||
install:
|
||||
- pip install coveralls
|
||||
- pip install -r requirements.txt
|
||||
- pip install -r requirements-dev.txt
|
||||
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then pip install ujson; fi
|
||||
script:
|
||||
coverage run telegram_test.py
|
||||
- nosetests -v --with-flaky --no-flaky-report --with-coverage --cover-package=telegram/
|
||||
- if [ $TRAVIS_PYTHON_VERSION != 3.3 ] && [ $TRAVIS_PYTHON_VERSION != pypy3 ]; then pre-commit run --all-files; fi
|
||||
after_success:
|
||||
coveralls
|
||||
|
||||
+15
@@ -9,12 +9,27 @@ Contributors
|
||||
The following wonderful people contributed directly or indirectly to this project:
|
||||
|
||||
- `Avanatiker <https://github.com/Avanatiker>`_
|
||||
- `Balduro <https://github.com/Balduro>`_
|
||||
- `bimmlerd <https://github.com/bimmlerd>`_
|
||||
- `Eli Gao <https://github.com/eligao>`_
|
||||
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
|
||||
- `franciscod <https://github.com/franciscod>`_
|
||||
- `Jacob Bom <https://github.com/bomjacob>`_
|
||||
- `JASON0916 <https://github.com/JASON0916>`_
|
||||
- `jh0ker <https://github.com/jh0ker>`_
|
||||
- `JRoot3D <https://github.com/JRoot3D>`_
|
||||
- `jlmadurga <https://github.com/jlmadurga>`_
|
||||
- `Li-aung Yip <https://github.com/LiaungYip>`_
|
||||
- `macrojames <https://github.com/macrojames>`_
|
||||
- `naveenvhegde <https://github.com/naveenvhegde>`_
|
||||
- `njittam <https://github.com/njittam>`_
|
||||
- `Noam Meltzer <https://github.com/tsnoam>`_
|
||||
- `Oleg Shlyazhko <https://github.com/ollmer>`_
|
||||
- `overquota <https://github.com/overquota>`_
|
||||
- `Rahiel Kasim <https://github.com/rahiel>`_
|
||||
- `Shelomentsev D <https://github.com/shelomentsevd>`_
|
||||
- `sooyhwang <https://github.com/sooyhwang>`_
|
||||
- `Valentijn <https://github.com/Faalentijn>`_
|
||||
- `wjt <https://github.com/wjt>`_
|
||||
|
||||
Please add yourself here alphabetically when you submit your first pull request.
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
2015-08-15
|
||||
Released 2.6.1
|
||||
Fixed parsing image header issue on < Python 2.7.3
|
||||
|
||||
|
||||
2015-08-14
|
||||
Released 2.6.0
|
||||
Depreciation of require_authentication and clearCredentials methods
|
||||
Giving AUTHORS the proper credits for their contribution for this project
|
||||
Message.date and Message.forward_date are now datetime objects
|
||||
|
||||
|
||||
2015-08-12
|
||||
Released 2.5.3
|
||||
telegram.Bot now supports to be unpickled
|
||||
|
||||
|
||||
2015-08-11
|
||||
Released 2.5.2
|
||||
New changes from Telegram Bot API have been applied
|
||||
telegram.Bot now supports to be pickled
|
||||
Return empty str instead None when message.text is empty
|
||||
|
||||
|
||||
2015-08-10
|
||||
Released 2.5.1
|
||||
Moved from GPLv2 to LGPLv3
|
||||
|
||||
|
||||
2015-08-09
|
||||
Released 2.5
|
||||
Fixes logging calls in API
|
||||
|
||||
|
||||
2015-08-08
|
||||
Released 2.4
|
||||
Fixes Emoji class for Python 3
|
||||
PEP8 improvements
|
||||
|
||||
|
||||
2015-08-08
|
||||
Released 2.3
|
||||
Fixes ForceReply class
|
||||
Remove logging.basicConfig from library
|
||||
|
||||
|
||||
2015-07-25
|
||||
Released 2.2
|
||||
Allows debug=True when initializing telegram.Bot
|
||||
|
||||
|
||||
2015-07-20
|
||||
Released 2.1
|
||||
Fix to_dict for Document and Video
|
||||
|
||||
|
||||
2015-07-19
|
||||
|
||||
Released 2.0
|
||||
Fixes bugs
|
||||
Improves __str__ over to_json()
|
||||
Creates abstractclass TelegramObject
|
||||
|
||||
|
||||
2015-07-15
|
||||
|
||||
Released 1.9
|
||||
Python 3 officially supported
|
||||
PEP8 improvements
|
||||
|
||||
|
||||
2015-07-12
|
||||
|
||||
Released 1.8
|
||||
Fixes crash when replying an unicode text message (special thanks to JRoot3D)
|
||||
|
||||
|
||||
2015-07-11
|
||||
|
||||
Released 1.7
|
||||
Fixes crash when username is not defined on chat (special thanks to JRoot3D)
|
||||
|
||||
|
||||
2015-07-10
|
||||
|
||||
Released 1.6
|
||||
Improvements for GAE support
|
||||
|
||||
|
||||
2015-07-10
|
||||
|
||||
Released 1.5
|
||||
Fixes randomly unicode issues when using InputFile
|
||||
|
||||
|
||||
2015-07-10
|
||||
|
||||
Released 1.4
|
||||
requests lib is no longer required
|
||||
Google App Engine (GAE) is supported
|
||||
|
||||
|
||||
2015-07-10
|
||||
|
||||
Released 1.3
|
||||
Added support to setWebhook (special thanks to macrojames)
|
||||
|
||||
|
||||
2015-07-09
|
||||
|
||||
Released 1.2
|
||||
CustomKeyboard classes now available
|
||||
Emojis available
|
||||
PEP8 improvements
|
||||
|
||||
|
||||
2015-07-08
|
||||
|
||||
Released 1.1
|
||||
PyPi package now available
|
||||
|
||||
|
||||
2015-07-08
|
||||
|
||||
Released 1.0
|
||||
Initial checkin of python-telegram-bot
|
||||
+459
@@ -0,0 +1,459 @@
|
||||
=======
|
||||
Changes
|
||||
=======
|
||||
|
||||
**2016-09-24**
|
||||
|
||||
*Released 5.1*
|
||||
|
||||
- Drop Python 2.6 support
|
||||
- Deprecate ``telegram.Emoji``
|
||||
|
||||
- Use ``ujson`` if available
|
||||
- Add instance methods to ``Message``, ``Chat``, ``User``, ``InlineQuery`` and ``CallbackQuery``
|
||||
- RegEx filtering for ``CallbackQueryHandler`` and ``InlineQueryHandler``
|
||||
- New ``MessageHandler`` filters: ``forwarded`` and ``entity``
|
||||
- Add ``Message.get_entity`` to correctly handle UTF-16 codepoints and ``MessageEntity`` offsets
|
||||
- Fix bug in ``ConversationHandler`` when first handler ends the conversation
|
||||
- Allow multiple ``Dispatcher`` instances
|
||||
- Add ``ChatMigrated`` Exception
|
||||
- Properly split and handle arguments in ``CommandHandler``
|
||||
|
||||
**2016-07-15**
|
||||
|
||||
*Released 5.0*
|
||||
|
||||
- Rework ``JobQueue``
|
||||
- Introduce ``ConversationHandler``
|
||||
|
||||
**2016-07-12**
|
||||
|
||||
*Released 4.3.4*
|
||||
|
||||
- Fix proxy support with ``urllib3`` when proxy requires auth
|
||||
|
||||
**2016-07-08**
|
||||
|
||||
*Released 4.3.3*
|
||||
|
||||
- Fix proxy support with ``urllib3``
|
||||
|
||||
**2016-07-04**
|
||||
|
||||
*Released 4.3.2*
|
||||
|
||||
- Fix: Use ``timeout`` parameter in all API methods
|
||||
|
||||
**2016-06-29**
|
||||
|
||||
*Released 4.3.1*
|
||||
|
||||
- Update wrong requirement: ``urllib3>=1.10``
|
||||
|
||||
**2016-06-28**
|
||||
|
||||
*Released 4.3*
|
||||
|
||||
- Use ``urllib3.PoolManager`` for connection re-use
|
||||
- Rewrite ``run_async`` decorator to re-use threads
|
||||
- New requirements: ``urllib3`` and ``certifi``
|
||||
|
||||
**2016-06-10**
|
||||
|
||||
*Released 4.2.1*
|
||||
|
||||
- Fix ``CallbackQuery.to_dict()`` bug (thanks to @jlmadurga)
|
||||
- Fix ``editMessageText`` exception when receiving a ``CallbackQuery``
|
||||
|
||||
**2016-05-28**
|
||||
|
||||
*Released 4.2*
|
||||
|
||||
- Implement Bot API 2.1
|
||||
- Move ``botan`` module to ``telegram.contrib``
|
||||
- New exception type: ``BadRequest``
|
||||
|
||||
**2016-05-22**
|
||||
|
||||
*Released 4.1.2*
|
||||
|
||||
- Fix ``MessageEntity`` decoding with Bot API 2.1 changes
|
||||
|
||||
**2016-05-16**
|
||||
|
||||
*Released 4.1.1*
|
||||
|
||||
- Fix deprecation warning in ``Dispatcher``
|
||||
|
||||
**2016-05-15**
|
||||
|
||||
*Released 4.1*
|
||||
|
||||
- Implement API changes from May 6, 2016
|
||||
- Fix bug when ``start_polling`` with ``clean=True``
|
||||
- Methods now have snake_case equivalent, for example ``telegram.Bot.send_message`` is the same as ``telegram.Bot.sendMessage``
|
||||
|
||||
**2016-05-01**
|
||||
|
||||
*Released 4.0.3*
|
||||
|
||||
- Add missing attribute ``location`` to ``InlineQuery``
|
||||
|
||||
**2016-04-29**
|
||||
|
||||
*Released 4.0.2*
|
||||
|
||||
- Bugfixes
|
||||
- ``KeyboardReplyMarkup`` now accepts ``str`` again
|
||||
|
||||
**2016-04-27**
|
||||
|
||||
*Released 4.0.1*
|
||||
|
||||
- Implement Bot API 2.0
|
||||
- Almost complete recode of ``Dispatcher``
|
||||
- Please read the `Transition Guide to 4.0 <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Transition-guide-to-Version-4.0>`_
|
||||
- **Changes from 4.0rc1**
|
||||
- The syntax of filters for ``MessageHandler`` (upper/lower cases)
|
||||
- Handler groups are now identified by ``int`` only, and ordered
|
||||
- **Note:** v4.0 has been skipped due to a PyPI accident
|
||||
|
||||
**2016-04-22**
|
||||
|
||||
*Released 4.0rc1*
|
||||
|
||||
- Implement Bot API 2.0
|
||||
- Almost complete recode of ``Dispatcher``
|
||||
- Please read the `Transistion Guide to 4.0 <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Transistion-guide-to-Version-4.0>`_
|
||||
|
||||
**2016-03-22**
|
||||
|
||||
*Released 3.4*
|
||||
|
||||
- Move ``Updater``, ``Dispatcher`` and ``JobQueue`` to new ``telegram.ext`` submodule (thanks to @rahiel)
|
||||
- Add ``disable_notification`` parameter (thanks to @aidarbiktimirov)
|
||||
- Fix bug where commands sent by Telegram Web would not be recognized (thanks to @shelomentsevd)
|
||||
- Add option to skip old updates on bot startup
|
||||
- Send files from ``BufferedReader``
|
||||
|
||||
**2016-02-28**
|
||||
|
||||
*Released 3.3*
|
||||
|
||||
- Inline bots
|
||||
- Send any file by URL
|
||||
- Specialized exceptions: ``Unauthorized``, ``InvalidToken``, ``NetworkError`` and ``TimedOut``
|
||||
- Integration for botan.io (thanks to @ollmer)
|
||||
- HTML Parsemode (thanks to @jlmadurga)
|
||||
- Bugfixes and under-the-hood improvements
|
||||
|
||||
**Very special thanks to Noam Meltzer (@tsnoam) for all of his work!**
|
||||
|
||||
**2016-01-09**
|
||||
|
||||
*Released 3.3b1*
|
||||
|
||||
- Implement inline bots (beta)
|
||||
|
||||
**2016-01-05**
|
||||
|
||||
*Released 3.2.0*
|
||||
|
||||
- Introducing ``JobQueue`` (original author: @franciscod)
|
||||
- Streamlining all exceptions to ``TelegramError`` (Special thanks to @tsnoam)
|
||||
- Proper locking of ``Updater`` and ``Dispatcher`` ``start`` and ``stop`` methods
|
||||
- Small bugfixes
|
||||
|
||||
**2015-12-29**
|
||||
|
||||
*Released 3.1.2*
|
||||
|
||||
- Fix custom path for file downloads
|
||||
- Don't stop the dispatcher thread on uncaught errors in handlers
|
||||
|
||||
**2015-12-21**
|
||||
|
||||
*Released 3.1.1*
|
||||
|
||||
- Fix a bug where asynchronous handlers could not have additional arguments
|
||||
- Add ``groups`` and ``groupdict`` as additional arguments for regex-based handlers
|
||||
|
||||
**2015-12-16**
|
||||
|
||||
*Released 3.1.0*
|
||||
|
||||
- The ``chat``-field in ``Message`` is now of type ``Chat``. (API update Oct 8 2015)
|
||||
- ``Message`` now contains the optional fields ``supergroup_chat_created``, ``migrate_to_chat_id``, ``migrate_from_chat_id`` and ``channel_chat_created``. (API update Nov 2015)
|
||||
|
||||
**2015-12-08**
|
||||
|
||||
*Released 3.0.0*
|
||||
|
||||
- Introducing the ``Updater`` and ``Dispatcher`` classes
|
||||
|
||||
**2015-11-11**
|
||||
|
||||
*Released 2.9.2*
|
||||
|
||||
- Error handling on request timeouts has been improved
|
||||
|
||||
**2015-11-10**
|
||||
|
||||
*Released 2.9.1*
|
||||
|
||||
- Add parameter ``network_delay`` to Bot.getUpdates for slow connections
|
||||
|
||||
**2015-11-10**
|
||||
|
||||
*Released 2.9*
|
||||
|
||||
- Emoji class now uses ``bytes_to_native_str`` from ``future`` 3rd party lib
|
||||
- Make ``user_from`` optional to work with channels
|
||||
- Raise exception if Telegram times out on long-polling
|
||||
|
||||
*Special thanks to @jh0ker for all hard work*
|
||||
|
||||
|
||||
**2015-10-08**
|
||||
|
||||
*Released 2.8.7*
|
||||
|
||||
- Type as optional for ``GroupChat`` class
|
||||
|
||||
|
||||
**2015-10-08**
|
||||
|
||||
*Released 2.8.6*
|
||||
|
||||
- Adds type to ``User`` and ``GroupChat`` classes (pre-release Telegram feature)
|
||||
|
||||
|
||||
**2015-09-24**
|
||||
|
||||
*Released 2.8.5*
|
||||
|
||||
- Handles HTTP Bad Gateway (503) errors on request
|
||||
- Fixes regression on ``Audio`` and ``Document`` for unicode fields
|
||||
|
||||
|
||||
**2015-09-20**
|
||||
|
||||
*Released 2.8.4*
|
||||
|
||||
- ``getFile`` and ``File.download`` is now fully supported
|
||||
|
||||
|
||||
**2015-09-10**
|
||||
|
||||
*Released 2.8.3*
|
||||
|
||||
- Moved ``Bot._requestURL`` to its own class (``telegram.utils.request``)
|
||||
- Much better, such wow, Telegram Objects tests
|
||||
- Add consistency for ``str`` properties on Telegram Objects
|
||||
- Better design to test if ``chat_id`` is invalid
|
||||
- Add ability to set custom filename on ``Bot.sendDocument(..,filename='')``
|
||||
- Fix Sticker as ``InputFile``
|
||||
- Send JSON requests over urlencoded post data
|
||||
- Markdown support for ``Bot.sendMessage(..., parse_mode=ParseMode.MARKDOWN)``
|
||||
- Refactor of ``TelegramError`` class (no more handling ``IOError`` or ``URLError``)
|
||||
|
||||
|
||||
**2015-09-05**
|
||||
|
||||
*Released 2.8.2*
|
||||
|
||||
- Fix regression on Telegram ReplyMarkup
|
||||
- Add certificate to ``is_inputfile`` method
|
||||
|
||||
|
||||
**2015-09-05**
|
||||
|
||||
*Released 2.8.1*
|
||||
|
||||
- Fix regression on Telegram objects with thumb properties
|
||||
|
||||
|
||||
**2015-09-04**
|
||||
|
||||
*Released 2.8*
|
||||
|
||||
- TelegramError when ``chat_id`` is empty for send* methods
|
||||
- ``setWebhook`` now supports sending self-signed certificate
|
||||
- Huge redesign of existing Telegram classes
|
||||
- Added support for PyPy
|
||||
- Added docstring for existing classes
|
||||
|
||||
|
||||
**2015-08-19**
|
||||
|
||||
*Released 2.7.1*
|
||||
|
||||
- Fixed JSON serialization for ``message``
|
||||
|
||||
|
||||
**2015-08-17**
|
||||
|
||||
*Released 2.7*
|
||||
|
||||
- Added support for ``Voice`` object and ``sendVoice`` method
|
||||
- Due backward compatibility performer or/and title will be required for ``sendAudio``
|
||||
- Fixed JSON serialization when forwarded message
|
||||
|
||||
|
||||
**2015-08-15**
|
||||
|
||||
*Released 2.6.1*
|
||||
|
||||
- Fixed parsing image header issue on < Python 2.7.3
|
||||
|
||||
|
||||
**2015-08-14**
|
||||
|
||||
*Released 2.6.0*
|
||||
|
||||
- Depreciation of ``require_authentication`` and ``clearCredentials`` methods
|
||||
- Giving ``AUTHORS`` the proper credits for their contribution for this project
|
||||
- ``Message.date`` and ``Message.forward_date`` are now ``datetime`` objects
|
||||
|
||||
|
||||
**2015-08-12**
|
||||
|
||||
*Released 2.5.3*
|
||||
|
||||
- ``telegram.Bot`` now supports to be unpickled
|
||||
|
||||
|
||||
**2015-08-11**
|
||||
|
||||
*Released 2.5.2*
|
||||
|
||||
- New changes from Telegram Bot API have been applied
|
||||
- ``telegram.Bot`` now supports to be pickled
|
||||
- Return empty ``str`` instead ``None`` when ``message.text`` is empty
|
||||
|
||||
|
||||
**2015-08-10**
|
||||
|
||||
*Released 2.5.1*
|
||||
|
||||
- Moved from GPLv2 to LGPLv3
|
||||
|
||||
|
||||
**2015-08-09**
|
||||
|
||||
*Released 2.5*
|
||||
|
||||
- Fixes logging calls in API
|
||||
|
||||
|
||||
**2015-08-08**
|
||||
|
||||
*Released 2.4*
|
||||
|
||||
- Fixes ``Emoji`` class for Python 3
|
||||
- ``PEP8`` improvements
|
||||
|
||||
|
||||
**2015-08-08**
|
||||
|
||||
*Released 2.3*
|
||||
|
||||
- Fixes ``ForceReply`` class
|
||||
- Remove ``logging.basicConfig`` from library
|
||||
|
||||
|
||||
**2015-07-25**
|
||||
|
||||
*Released 2.2*
|
||||
|
||||
- Allows ``debug=True`` when initializing ``telegram.Bot``
|
||||
|
||||
|
||||
**2015-07-20**
|
||||
|
||||
*Released 2.1*
|
||||
|
||||
- Fix ``to_dict`` for ``Document`` and ``Video``
|
||||
|
||||
|
||||
**2015-07-19**
|
||||
|
||||
*Released 2.0*
|
||||
|
||||
- Fixes bugs
|
||||
- Improves ``__str__`` over ``to_json()``
|
||||
- Creates abstract class ``TelegramObject``
|
||||
|
||||
|
||||
**2015-07-15**
|
||||
|
||||
*Released 1.9*
|
||||
|
||||
- Python 3 officially supported
|
||||
- ``PEP8`` improvements
|
||||
|
||||
|
||||
**2015-07-12**
|
||||
|
||||
*Released 1.8*
|
||||
|
||||
- Fixes crash when replying an unicode text message (special thanks to JRoot3D)
|
||||
|
||||
|
||||
**2015-07-11**
|
||||
|
||||
*Released 1.7*
|
||||
|
||||
- Fixes crash when ``username`` is not defined on ``chat`` (special thanks to JRoot3D)
|
||||
|
||||
|
||||
**2015-07-10**
|
||||
|
||||
*Released 1.6*
|
||||
|
||||
- Improvements for GAE support
|
||||
|
||||
|
||||
**2015-07-10**
|
||||
|
||||
*Released 1.5*
|
||||
|
||||
- Fixes randomly unicode issues when using ``InputFile``
|
||||
|
||||
|
||||
**2015-07-10**
|
||||
|
||||
*Released 1.4*
|
||||
|
||||
- ``requests`` lib is no longer required
|
||||
- Google App Engine (GAE) is supported
|
||||
|
||||
|
||||
**2015-07-10**
|
||||
|
||||
*Released 1.3*
|
||||
|
||||
- Added support to ``setWebhook`` (special thanks to macrojames)
|
||||
|
||||
|
||||
**2015-07-09**
|
||||
|
||||
*Released 1.2*
|
||||
|
||||
- ``CustomKeyboard`` classes now available
|
||||
- Emojis available
|
||||
- ``PEP8`` improvements
|
||||
|
||||
|
||||
**2015-07-08**
|
||||
|
||||
*Released 1.1*
|
||||
|
||||
- PyPi package now available
|
||||
|
||||
|
||||
**2015-07-08**
|
||||
|
||||
*Released 1.0*
|
||||
|
||||
- Initial checkin of python-telegram-bot
|
||||
@@ -1,39 +0,0 @@
|
||||
How To Contribute
|
||||
=================
|
||||
|
||||
Every open source project lives from the generous help by contributors that sacrifice their time and ``python-telegram-bot`` is no different.
|
||||
|
||||
To make participation as pleasant as possible, this project adheres to the `Code of Conduct`_ by the Python Software Foundation.
|
||||
|
||||
Here are a few guidelines to get you started:
|
||||
|
||||
- Add yourself to the AUTHORS.rst_ file in an alphabetical fashion.
|
||||
Every contribution is valuable and shall be credited.
|
||||
- If your change is noteworthy, add an entry to the CHANGES_.
|
||||
- No contribution is too small; please submit as many fixes for typos and grammar bloopers as you can!
|
||||
- Don’t break backward compatibility.
|
||||
- *Always* add tests and docs for your code.
|
||||
This is a hard rule; patches with missing tests or documentation won’t be merged.
|
||||
If a feature is not tested or documented, it doesn’t exist.
|
||||
- Obey `PEP 8`_ and `PEP 257`_.
|
||||
- Follow `Google Python Style Guide`_ and `Google Python Style Docstrings`_.
|
||||
- Write `good commit messages`_.
|
||||
|
||||
.. note::
|
||||
If you have something great but aren’t sure whether it adheres -- or even can adhere -- to the rules above: **please submit a pull request anyway**!
|
||||
|
||||
In the best case, we can mold it into something, in the worst case the pull request gets politely closed.
|
||||
There’s absolutely nothing to fear.
|
||||
|
||||
Thank you for considering to contribute to ``python-telegram-bot``!
|
||||
If you have any question or concerns, feel free to reach out to me.
|
||||
|
||||
|
||||
.. _`PEP 8`: https://www.python.org/dev/peps/pep-0008/
|
||||
.. _`PEP 257`: https://www.python.org/dev/peps/pep-0257/
|
||||
.. _`good commit messages`: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
||||
.. _`Code of Conduct`: https://www.python.org/psf/codeofconduct/
|
||||
.. _`Google Python Style Guide`: https://google-styleguide.googlecode.com/svn/trunk/pyguide.html
|
||||
.. _`Google Python Style Docstrings`: http://sphinx-doc.org/latest/ext/example_google.html
|
||||
.. _CHANGES: https://github.com/leandrotoledo/python-telegram-bot/blob/master/CHANGES
|
||||
.. _AUTHORS.rst: https://github.com/leandrotoledo/python-telegram-bot/blob/master/AUTHORS.rst
|
||||
+1
-1
@@ -1 +1 @@
|
||||
include LICENSE LICENSE.lesser Makefile
|
||||
include LICENSE LICENSE.lesser Makefile requirements.txt
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
help:
|
||||
@echo " clean remove unwanted stuff"
|
||||
@echo " lint check style with flake8"
|
||||
@echo " test run tests"
|
||||
.DEFAULT_GOAL := help
|
||||
.PHONY: clean pep257 pep8 yapf lint test install
|
||||
|
||||
PYLINT := pylint
|
||||
NOSETESTS := nosetests
|
||||
PEP257 := pep257
|
||||
PEP8 := flake8
|
||||
YAPF := yapf
|
||||
PIP := pip
|
||||
|
||||
clean:
|
||||
rm -fr build
|
||||
@@ -9,9 +14,39 @@ clean:
|
||||
find . -name '*.pyc' -exec rm -f {} \;
|
||||
find . -name '*.pyo' -exec rm -f {} \;
|
||||
find . -name '*~' -exec rm -f {} \;
|
||||
find . -regex "./telegram.\(mp3\|mp4\|ogg\|png\|webp\)" -exec rm {} \;
|
||||
|
||||
pep257:
|
||||
$(PEP257) telegram
|
||||
|
||||
pep8:
|
||||
$(PEP8) telegram
|
||||
|
||||
yapf:
|
||||
$(YAPF) -r telegram
|
||||
|
||||
lint:
|
||||
flake8 --doctests --max-complexity 10 telegram
|
||||
$(PYLINT) -E telegram --disable=no-name-in-module,import-error
|
||||
|
||||
test:
|
||||
python telegram_test.py
|
||||
$(NOSETESTS) -v
|
||||
|
||||
install:
|
||||
$(PIP) install -r requirements.txt -r requirements-dev.txt
|
||||
|
||||
help:
|
||||
@echo "Available targets:"
|
||||
@echo "- clean Clean up the source directory"
|
||||
@echo "- pep257 Check docstring style with pep257"
|
||||
@echo "- pep8 Check style with flake8"
|
||||
@echo "- lint Check style with pylint"
|
||||
@echo "- yapf Check style with yapf"
|
||||
@echo "- test Run tests"
|
||||
@echo
|
||||
@echo "Available variables:"
|
||||
@echo "- PYLINT default: $(PYLINT)"
|
||||
@echo "- NOSETESTS default: $(NOSETESTS)"
|
||||
@echo "- PEP257 default: $(PEP257)"
|
||||
@echo "- PEP8 default: $(PEP8)"
|
||||
@echo "- YAPF default: $(YAPF)"
|
||||
@echo "- PIP default: $(PIP)"
|
||||
|
||||
+113
-195
@@ -1,36 +1,47 @@
|
||||
Python Telegram Bot
|
||||
.. image:: https://github.com/python-telegram-bot/logos/blob/master/logo-text/png/ptb-logo-text_768.png?raw=true
|
||||
:align: center
|
||||
:target: https://python-telegram-bot.org
|
||||
:alt: python-telegram-bot Logo
|
||||
|
||||
A Python wrapper around the Telegram Bot API.
|
||||
We have made you a wrapper you can't refuse
|
||||
|
||||
By `Leandro Toledo <leandrotoledodesouza@gmail.com>`_
|
||||
*Stay tuned for library updates and new releases on our* `Telegram Channel <https://telegram.me/pythontelegrambotchannel>`_.
|
||||
|
||||
.. image:: https://img.shields.io/pypi/v/python-telegram-bot.svg
|
||||
:target: https://pypi.python.org/pypi/python-telegram-bot
|
||||
:alt: PyPi Package Version
|
||||
|
||||
.. image:: https://img.shields.io/pypi/dm/python-telegram-bot.svg
|
||||
|
||||
.. image:: https://img.shields.io/pypi/pyversions/python-telegram-bot.svg
|
||||
:target: https://pypi.python.org/pypi/python-telegram-bot
|
||||
:alt: PyPi Package Monthly Download
|
||||
|
||||
.. image:: https://readthedocs.org/projects/python-telegram-bot/badge/?version=latest
|
||||
:target: https://readthedocs.org/projects/python-telegram-bot/?badge=latest
|
||||
:alt: Supported python versions
|
||||
|
||||
.. image:: https://img.shields.io/badge/docs-latest-af1a97.svg
|
||||
:target: https://pythonhosted.org/python-telegram-bot/
|
||||
:alt: Documentation Status
|
||||
|
||||
.. image:: https://img.shields.io/github/license/leandrotoledo/python-telegram-bot.svg
|
||||
:target: http://www.gnu.org/licenses/lgpl-3.0.html
|
||||
|
||||
.. image:: https://img.shields.io/pypi/l/python-telegram-bot.svg
|
||||
:target: https://www.gnu.org/licenses/lgpl-3.0.html
|
||||
:alt: LGPLv3 License
|
||||
|
||||
.. image:: https://travis-ci.org/leandrotoledo/python-telegram-bot.svg?branch=master
|
||||
:target: https://travis-ci.org/leandrotoledo/python-telegram-bot
|
||||
.. image:: https://travis-ci.org/python-telegram-bot/python-telegram-bot.svg?branch=master
|
||||
:target: https://travis-ci.org/python-telegram-bot/python-telegram-bot
|
||||
:alt: Travis CI Status
|
||||
|
||||
.. image:: https://codeclimate.com/github/leandrotoledo/python-telegram-bot/badges/gpa.svg
|
||||
:target: https://codeclimate.com/github/leandrotoledo/python-telegram-bot
|
||||
.. image:: https://codeclimate.com/github/python-telegram-bot/python-telegram-bot/badges/gpa.svg
|
||||
:target: https://codeclimate.com/github/python-telegram-bot/python-telegram-bot
|
||||
:alt: Code Climate
|
||||
|
||||
.. image:: https://coveralls.io/repos/leandrotoledo/python-telegram-bot/badge.svg?branch=master&service=github
|
||||
:target: https://coveralls.io/github/leandrotoledo/python-telegram-bot?branch=master
|
||||
|
||||
.. image:: https://coveralls.io/repos/python-telegram-bot/python-telegram-bot/badge.svg?branch=master&service=github
|
||||
:target: https://coveralls.io/github/python-telegram-bot/python-telegram-bot?branch=master
|
||||
:alt: Coveralls
|
||||
|
||||
.. image:: http://isitmaintained.com/badge/resolution/python-telegram-bot/python-telegram-bot.svg
|
||||
:target: http://isitmaintained.com/project/python-telegram-bot/python-telegram-bot
|
||||
:alt: Average time to resolve an issue
|
||||
|
||||
.. image:: https://img.shields.io/badge/Telegram-Group-blue.svg
|
||||
:target: https://telegram.me/pythontelegrambotgroup
|
||||
:alt: Telegram Group
|
||||
|
||||
=================
|
||||
Table of contents
|
||||
@@ -38,236 +49,143 @@ Table of contents
|
||||
|
||||
- `Introduction`_
|
||||
|
||||
- `Status`_
|
||||
|
||||
1. `Telegram API support`_
|
||||
|
||||
2. `Python Version support`_
|
||||
- `Telegram API support`_
|
||||
|
||||
- `Installing`_
|
||||
|
||||
- `Getting the code`_
|
||||
|
||||
- `Getting started`_
|
||||
|
||||
1. `API`_
|
||||
#. `Learning by example`_
|
||||
|
||||
2. `Logging`_
|
||||
#. `Logging`_
|
||||
|
||||
3. `Examples`_
|
||||
|
||||
4. `Documentation`_
|
||||
#. `Documentation`_
|
||||
|
||||
- `Getting help`_
|
||||
|
||||
- `Contributing`_
|
||||
|
||||
- `License`_
|
||||
|
||||
- `Contact`_
|
||||
============
|
||||
Introduction
|
||||
============
|
||||
|
||||
- `TODO`_
|
||||
This library provides a pure Python interface for the
|
||||
`Telegram Bot API <https://core.telegram.org/bots/api>`_.
|
||||
It's compatible with Python versions 2.7, 3.3+ and `PyPy <http://pypy.org/>`_.
|
||||
It also works with `Google App Engine <https://cloud.google.com/appengine>`_.
|
||||
|
||||
===============
|
||||
_`Introduction`
|
||||
===============
|
||||
In addition to the pure API implementation, this library features a number of high-level classes to
|
||||
make the development of bots easy and straightforward. These classes are contained in the
|
||||
``telegram.ext`` submodule.
|
||||
|
||||
This library provides a pure Python interface for the `Telegram Bot API <https://core.telegram.org/bots/api>`_. It works with Python versions from 2.6+. It also works with `Google App Engine <https://cloud.google.com/appengine>`_.
|
||||
====================
|
||||
Telegram API support
|
||||
====================
|
||||
|
||||
=========
|
||||
_`Status`
|
||||
=========
|
||||
As of **28. May 2016**, all types and methods of the Telegram Bot API are supported.
|
||||
|
||||
-----------------------
|
||||
_`Telegram API support`
|
||||
-----------------------
|
||||
==========
|
||||
Installing
|
||||
==========
|
||||
|
||||
========================= ============
|
||||
Telegram Bot API Method *Supported?*
|
||||
========================= ============
|
||||
getMe Yes
|
||||
sendMessage Yes
|
||||
forwardMessage Yes
|
||||
sendPhoto Yes
|
||||
sendAudio Yes
|
||||
sendDocument Yes
|
||||
sendSticker Yes
|
||||
sendVideo Yes
|
||||
sendVoice Yes
|
||||
sendLocation Yes
|
||||
sendChatAction Yes
|
||||
getUpdates Yes
|
||||
getUserProfilePhotos Yes
|
||||
setWebhook Yes
|
||||
========================= ============
|
||||
You can install or upgrade python-telegram-bot with:
|
||||
|
||||
-------------------------
|
||||
_`Python Version support`
|
||||
-------------------------
|
||||
|
||||
============== ============
|
||||
Python Version *Supported?*
|
||||
============== ============
|
||||
2.6 Yes
|
||||
2.7 Yes
|
||||
3.3 Yes
|
||||
3.4 Yes
|
||||
============== ============
|
||||
|
||||
=============
|
||||
_`Installing`
|
||||
=============
|
||||
|
||||
You can install python-telegram-bot using::
|
||||
|
||||
$ pip install python-telegram-bot
|
||||
|
||||
Or upgrade to the latest version::
|
||||
.. code:: shell
|
||||
|
||||
$ pip install python-telegram-bot --upgrade
|
||||
|
||||
===================
|
||||
_`Getting the code`
|
||||
===================
|
||||
Or you can install from source with:
|
||||
|
||||
The code is hosted at https://github.com/leandrotoledo/python-telegram-bot
|
||||
.. code:: shell
|
||||
|
||||
Check out the latest development version anonymously with::
|
||||
|
||||
$ git clone https://github.com/leandrotoledo/python-telegram-bot
|
||||
$ git clone https://github.com/python-telegram-bot/python-telegram-bot
|
||||
$ cd python-telegram-bot
|
||||
$ python setup.py install
|
||||
===============
|
||||
Getting started
|
||||
===============
|
||||
|
||||
Run tests:
|
||||
Our Wiki contains a lot of resources to get you started with ``python-telegram-bot``:
|
||||
|
||||
$ make test
|
||||
- `Introduction to the API <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Introduction-to-the-API>`_
|
||||
- Tutorial: `Your first Bot <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot>`_
|
||||
|
||||
To see other options available, run:
|
||||
Other references:
|
||||
|
||||
$ make help
|
||||
- `Telegram API documentation <https://core.telegram.org/bots/api>`_
|
||||
- `python-telegram-bot documentation <https://pythonhosted.org/python-telegram-bot/>`_
|
||||
|
||||
==================
|
||||
_`Getting started`
|
||||
==================
|
||||
-------------------
|
||||
Learning by example
|
||||
-------------------
|
||||
|
||||
View the last release API documentation at: https://core.telegram.org/bots/api
|
||||
We believe that the best way to learn and understand this simple package is by example. So here
|
||||
are some examples for you to review. Even if it's not your approach for learning, please take a
|
||||
look at ``echobot2``, it is de facto the base for most of the bots out there. Best of all,
|
||||
the code for these examples are released to the public domain, so you can start by grabbing the
|
||||
code and building on top of it.
|
||||
|
||||
------
|
||||
_`API`
|
||||
------
|
||||
Visit `this page <https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/README.md>`_ to discover the official examples or look at the examples on the `wiki <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Examples>`_ to see other bots the community has built.
|
||||
|
||||
The API is exposed via the ``telegram.Bot`` class.
|
||||
-------
|
||||
Logging
|
||||
-------
|
||||
|
||||
To generate an Access Token you have to talk to `BotFather <https://telegram.me/botfather>`_ and follow a few simple steps (described `here <https://core.telegram.org/bots#botfather>`_).
|
||||
This library uses the ``logging`` module. To set up logging to standard output, put:
|
||||
|
||||
For full details see the `Bots: An introduction for developers <https://core.telegram.org/bots>`_.
|
||||
.. code:: python
|
||||
|
||||
To create an instance of the ``telegram.Bot``::
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
>>> import telegram
|
||||
>>> bot = telegram.Bot(token='token')
|
||||
at the beginning of your script.
|
||||
|
||||
To see if your credentials are successful::
|
||||
You can also use logs in your application by calling ``logging.getLogger()`` and setting the log level you want:
|
||||
|
||||
>>> print bot.getMe()
|
||||
{"first_name": "Toledo's Palace Bot", "username": "ToledosPalaceBot"}
|
||||
.. code:: python
|
||||
|
||||
Bots can't initiate conversations with users. A user must either add them to a group or send them a message first. People can use ``telegram.me/<bot_username>`` links or username search to find your bot.
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
To fetch text messages sent to your Bot::
|
||||
If you want DEBUG logs instead:
|
||||
|
||||
>>> updates = bot.getUpdates()
|
||||
>>> print [u.message.text for u in updates]
|
||||
.. code:: python
|
||||
|
||||
To fetch images sent to your Bot::
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
>>> updates = bot.getUpdates()
|
||||
>>> print [u.message.photo for u in updates if u.message.photo]
|
||||
|
||||
To reply messages you'll always need the chat_id::
|
||||
=============
|
||||
Documentation
|
||||
=============
|
||||
|
||||
>>> chat_id = bot.getUpdates()[-1].message.chat_id
|
||||
``python-telegram-bot``'s documentation lives at `pythonhosted.org <https://pythonhosted.org/python-telegram-bot/>`_.
|
||||
|
||||
To post a text message::
|
||||
============
|
||||
Getting help
|
||||
============
|
||||
|
||||
>>> bot.sendMessage(chat_id=chat_id, text="I'm sorry Dave I'm afraid I can't do that.")
|
||||
You can get help in several ways:
|
||||
|
||||
To post an Emoji (special thanks to `Tim Whitlock <http://apps.timwhitlock.info/emoji/tables/unicode>`_)::
|
||||
1. We have a vibrant community of developers helping each other in our `Telegram group <https://telegram.me/pythontelegrambotgroup>`_. Join us!
|
||||
|
||||
>>> bot.sendMessage(chat_id=chat_id, text=telegram.Emoji.PILE_OF_POO)
|
||||
2. Our `Wiki pages <https://github.com/python-telegram-bot/python-telegram-bot/wiki/>`_ offer a growing amount of resources.
|
||||
|
||||
To post an image file via URL (right now only sendPhoto supports this)::
|
||||
3. You can ask for help on Stack Overflow using the `python-telegram-bot tag <https://stackoverflow.com/questions/tagged/python-telegram-bot>`_.
|
||||
|
||||
>>> bot.sendPhoto(chat_id=chat_id, photo='https://telegram.org/img/t_logo.png')
|
||||
4. As last resort, the developers are ready to help you with `serious issues <https://github.com/python-telegram-bot/python-telegram-bot/issues/new>`_.
|
||||
|
||||
To post a voice file::
|
||||
|
||||
>>> bot.sendVoice(chat_id=chat_id, voice=open('tests/telegram.ogg', 'rb'))
|
||||
============
|
||||
Contributing
|
||||
============
|
||||
|
||||
To tell the user that something is happening on bot's side::
|
||||
|
||||
>>> bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
To create `Custom Keyboards <https://core.telegram.org/bots#keyboards>`_::
|
||||
|
||||
>>> custom_keyboard = [[ telegram.Emoji.THUMBS_UP_SIGN, telegram.Emoji.THUMBS_DOWN_SIGN ]]
|
||||
>>> reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
|
||||
>>> bot.sendMessage(chat_id=chat_id, text="Stay here, I'll be back.", reply_markup=reply_markup)
|
||||
|
||||
To hide `Custom Keyboards <https://core.telegram.org/bots#keyboards>`_::
|
||||
|
||||
>>> reply_markup = telegram.ReplyKeyboardHide()
|
||||
>>> bot.sendMessage(chat_id=chat_id, text="I'm back.", reply_markup=reply_markup)
|
||||
|
||||
There are many more API methods, to read the full API documentation::
|
||||
|
||||
$ pydoc telegram.Bot
|
||||
|
||||
-----------
|
||||
_`Logging`
|
||||
-----------
|
||||
|
||||
You can get logs in your main application by calling `logging` and setting the log level you want::
|
||||
|
||||
>>> import logging
|
||||
>>> logger = logging.getLogger()
|
||||
>>> logger.setLevel(logging.INFO)
|
||||
|
||||
If you want DEBUG logs instead::
|
||||
|
||||
>>> logger.setLevel(logging.DEBUG)
|
||||
|
||||
-----------
|
||||
_`Examples`
|
||||
-----------
|
||||
|
||||
Here follows some examples to help you to get your own Bot up to speed:
|
||||
|
||||
- `echobot <https://github.com/leandrotoledo/python-telegram-bot/blob/master/examples/echobot.py>`_ replies back messages.
|
||||
|
||||
- `roboed <https://github.com/leandrotoledo/python-telegram-bot/blob/master/examples/roboed.py>`_ talks to `Robô Ed <http://www.ed.conpet.gov.br/br/converse.php>`_.
|
||||
|
||||
- `Simple-Echo-Telegram-Bot <https://github.com/sooyhwang/Simple-Echo-Telegram-Bot>`_ simple Python Telegram bot that echoes your input with Flask microframework, setWebhook method, and Google App Engine (optional) - by @sooyhwang.
|
||||
|
||||
- `DevOps Reaction Bot <https://github.com/leandrotoledo/gae-devops-reaction-telegram-bot>`_ sends latest or random posts from `DevOps Reaction <http://devopsreactions.tumblr.com/>`_. Running on `Google App Engine <https://cloud.google.com/appengine>`_ (billing has to be enabled for fully Socket API support).
|
||||
|
||||
================
|
||||
_`Documentation`
|
||||
================
|
||||
|
||||
``python-telegram-bot``'s documentation lives at `Read the Docs <http://python-telegram-bot.readthedocs.org/en/latest/>`_.
|
||||
|
||||
==========
|
||||
_`License`
|
||||
==========
|
||||
|
||||
You may copy, distribute and modify the software provided that modifications are described and licensed for free under `LGPL-3 <http://www.gnu.org/licenses/lgpl-3.0.html>`_. Derivatives works (including modifications or anything statically linked to the library) can only be redistributed under `LGPL-3 <http://www.gnu.org/licenses/lgpl-3.0.html>`_, but applications that use the library don't have to be.
|
||||
|
||||
==========
|
||||
_`Contact`
|
||||
==========
|
||||
|
||||
Feel free to join to our `Telegram group <https://telegram.me/joinchat/00b9c0f802509b949c1563d56eb053b0>`_.
|
||||
Contributions of all sizes are welcome. Please review our `contribution guidelines <https://github.com/python-telegram-bot/python-telegram-bot/blob/master/.github/CONTRIBUTING.rst>`_ to get started. You can also help by `reporting bugs <https://github.com/python-telegram-bot/python-telegram-bot/issues/new>`_.
|
||||
|
||||
=======
|
||||
_`TODO`
|
||||
License
|
||||
=======
|
||||
|
||||
Patches and bug reports are `welcome <https://github.com/leandrotoledo/python-telegram-bot/issues/new>`_, just please keep the style consistent with the original source.
|
||||
|
||||
- Add commands handler.
|
||||
You may copy, distribute and modify the software provided that modifications are described and licensed for free under `LGPL-3 <https://www.gnu.org/licenses/lgpl-3.0.html>`_. Derivatives works (including modifications or anything statically linked to the library) can only be redistributed under LGPL-3, but applications that use the library don't have to be.
|
||||
|
||||
+1
-1
@@ -189,4 +189,4 @@ xml:
|
||||
pseudoxml:
|
||||
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
|
||||
@echo
|
||||
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
|
||||
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
|
||||
+5
-4
@@ -15,6 +15,7 @@
|
||||
import sys
|
||||
import os
|
||||
import shlex
|
||||
import telegram
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
@@ -50,7 +51,7 @@ master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'Python Telegram Bot'
|
||||
copyright = u'2015, Leandro Toledo'
|
||||
copyright = u'2015-2016, Leandro Toledo'
|
||||
author = u'Leandro Toledo'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
@@ -58,9 +59,9 @@ author = u'Leandro Toledo'
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '2.5'
|
||||
version = telegram.__version__[:3]
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '2.5.1'
|
||||
release = telegram.__version__
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
@@ -270,7 +271,7 @@ man_pages = [
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'PythonTelegramBot', u'Python Telegram Bot Documentation',
|
||||
author, 'PythonTelegramBot', 'One line description of project.',
|
||||
author, 'PythonTelegramBot', 'Not just a Python wrapper around the Telegram Bot API',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ Welcome to Python Telegram Bot's documentation!
|
||||
===============================================
|
||||
|
||||
Contents:
|
||||
telegram
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
@@ -3,5 +3,4 @@ telegram.bot module
|
||||
|
||||
.. automodule:: telegram.bot
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
telegram.groupchat module
|
||||
telegram.chat module
|
||||
=========================
|
||||
|
||||
.. automodule:: telegram.groupchat
|
||||
.. automodule:: telegram.chat
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.choseninlineresult module
|
||||
==================================
|
||||
|
||||
.. automodule:: telegram.choseninlineresult
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.constants module
|
||||
=========================
|
||||
|
||||
.. automodule:: telegram.constants
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.contrib.botan module
|
||||
=============================
|
||||
|
||||
.. automodule:: telegram.contrib.botan
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -1,7 +0,0 @@
|
||||
telegram.emoji module
|
||||
=====================
|
||||
|
||||
.. automodule:: telegram.emoji
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.callbackqueryhandler module
|
||||
========================================
|
||||
|
||||
.. automodule:: telegram.ext.callbackqueryhandler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.choseninlineresulthandler module
|
||||
=============================================
|
||||
|
||||
.. automodule:: telegram.ext.choseninlineresulthandler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.commandhandler module
|
||||
==================================
|
||||
|
||||
.. automodule:: telegram.ext.commandhandler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.conversationhandler module
|
||||
=======================================
|
||||
|
||||
.. automodule:: telegram.ext.conversationhandler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.dispatcher module
|
||||
==============================
|
||||
|
||||
.. automodule:: telegram.ext.dispatcher
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.handler module
|
||||
===========================
|
||||
|
||||
.. automodule:: telegram.ext.handler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.inlinequeryhandler module
|
||||
======================================
|
||||
|
||||
.. automodule:: telegram.ext.inlinequeryhandler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.jobqueue module
|
||||
============================
|
||||
|
||||
.. automodule:: telegram.ext.jobqueue
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.messagehandler module
|
||||
==================================
|
||||
|
||||
.. automodule:: telegram.ext.messagehandler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.regexhandler module
|
||||
================================
|
||||
|
||||
.. automodule:: telegram.ext.regexhandler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,29 @@
|
||||
telegram.ext package
|
||||
====================
|
||||
|
||||
Submodules
|
||||
----------
|
||||
|
||||
.. toctree::
|
||||
|
||||
telegram.ext.updater
|
||||
telegram.ext.dispatcher
|
||||
telegram.ext.jobqueue
|
||||
telegram.ext.handler
|
||||
telegram.ext.choseninlineresulthandler
|
||||
telegram.ext.conversationhandler
|
||||
telegram.ext.commandhandler
|
||||
telegram.ext.inlinequeryhandler
|
||||
telegram.ext.messagehandler
|
||||
telegram.ext.regexhandler
|
||||
telegram.ext.stringcommandhandler
|
||||
telegram.ext.stringregexhandler
|
||||
telegram.ext.typehandler
|
||||
|
||||
Module contents
|
||||
---------------
|
||||
|
||||
.. automodule:: telegram.ext
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.stringcommandhandler module
|
||||
========================================
|
||||
|
||||
.. automodule:: telegram.ext.stringcommandhandler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.stringregexhandler module
|
||||
======================================
|
||||
|
||||
.. automodule:: telegram.ext.stringregexhandler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.typehandler module
|
||||
===============================
|
||||
|
||||
.. automodule:: telegram.ext.typehandler
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.ext.updater module
|
||||
===========================
|
||||
|
||||
.. automodule:: telegram.ext.updater
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinekeyboardbutton module
|
||||
===========================
|
||||
|
||||
.. automodule:: telegram.inlinekeyboardbutton
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinekeyboardmarkup module
|
||||
==========================
|
||||
|
||||
.. automodule:: telegram.inlinekeyboardmarkup
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequery module
|
||||
===========================
|
||||
|
||||
.. automodule:: telegram.inlinequery
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresult module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresult
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultarticle module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultarticle
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultaudio module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultaudio
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultcachedaudio module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultcachedaudio
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultcacheddocument module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultcacheddocument
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultcachedgif module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultcachedgif
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultcachedmpeg4gif module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultcachedmpeg4gif
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultcachedphoto module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultcachedphoto
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultcachedsticker module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultcachedsticker
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultcachedvideo module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultcachedvideo
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultcachedvoice module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultcachedvoice
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultcontact module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultcontact
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultdocument module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultdocument
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultgif module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultgif
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultlocation module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultlocation
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultmpeg4gif module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultmpeg4gif
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultphoto module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultphoto
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultvenue module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultvenue
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultvideo module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultvideo
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -0,0 +1,7 @@
|
||||
telegram.inlinequeryresultvoice module
|
||||
=================================
|
||||
|
||||
.. automodule:: telegram.inlinequeryresultvoice
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@@ -9,13 +9,38 @@ Submodules
|
||||
telegram.audio
|
||||
telegram.base
|
||||
telegram.bot
|
||||
telegram.ext
|
||||
telegram.inlinequery
|
||||
telegram.inlinequeryresult
|
||||
telegram.inlinekeyboardbutton
|
||||
telegram.inlinekeyboardmarkup
|
||||
telegram.inlinequeryresultarticle
|
||||
telegram.inlinequeryresultaudio
|
||||
telegram.inlinequeryresultcachedaudio
|
||||
telegram.inlinequeryresultcacheddocument
|
||||
telegram.inlinequeryresultcachedgif
|
||||
telegram.inlinequeryresultcachedmpeg4gif
|
||||
telegram.inlinequeryresultcachedphoto
|
||||
telegram.inlinequeryresultcachedsticker
|
||||
telegram.inlinequeryresultcachedvideo
|
||||
telegram.inlinequeryresultcachedvoice
|
||||
telegram.inlinequeryresultcontact
|
||||
telegram.inlinequeryresultdocument
|
||||
telegram.inlinequeryresultgif
|
||||
telegram.inlinequeryresultlocation
|
||||
telegram.inlinequeryresultmpeg4gif
|
||||
telegram.inlinequeryresultphoto
|
||||
telegram.inlinequeryresultvenue
|
||||
telegram.inlinequeryresultvideo
|
||||
telegram.inlinequeryresultvoice
|
||||
telegram.choseninlineresult
|
||||
telegram.chataction
|
||||
telegram.contact
|
||||
telegram.document
|
||||
telegram.emoji
|
||||
telegram.error
|
||||
telegram.forcereply
|
||||
telegram.groupchat
|
||||
telegram.chat
|
||||
telegram.inputfile
|
||||
telegram.location
|
||||
telegram.message
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
CC0 1.0 Universal
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator and
|
||||
subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for the
|
||||
purpose of contributing to a commons of creative, cultural and scientific
|
||||
works ("Commons") that the public can reliably and without fear of later
|
||||
claims of infringement build upon, modify, incorporate in other works, reuse
|
||||
and redistribute as freely as possible in any form whatsoever and for any
|
||||
purposes, including without limitation commercial purposes. These owners may
|
||||
contribute to the Commons to promote the ideal of a free culture and the
|
||||
further production of creative, cultural and scientific works, or to gain
|
||||
reputation or greater distribution for their Work in part through the use and
|
||||
efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any expectation
|
||||
of additional consideration or compensation, the person associating CC0 with a
|
||||
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
||||
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
||||
and publicly distribute the Work under its terms, with knowledge of his or her
|
||||
Copyright and Related Rights in the Work and the meaning and intended legal
|
||||
effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not limited
|
||||
to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
||||
and translate a Work;
|
||||
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
|
||||
iii. publicity and privacy rights pertaining to a person's image or likeness
|
||||
depicted in a Work;
|
||||
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data in
|
||||
a Work;
|
||||
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation thereof,
|
||||
including any amended or successor version of such directive); and
|
||||
|
||||
vii. other similar, equivalent or corresponding rights throughout the world
|
||||
based on applicable law or treaty, and any national implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
||||
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
||||
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
||||
and Related Rights and associated claims and causes of action, whether now
|
||||
known or unknown (including existing as well as future claims and causes of
|
||||
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
||||
duration provided by applicable law or treaty (including future time
|
||||
extensions), (iii) in any current or future medium and for any number of
|
||||
copies, and (iv) for any purpose whatsoever, including without limitation
|
||||
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
||||
the Waiver for the benefit of each member of the public at large and to the
|
||||
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
||||
shall not be subject to revocation, rescission, cancellation, termination, or
|
||||
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
||||
by the public as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason be
|
||||
judged legally invalid or ineffective under applicable law, then the Waiver
|
||||
shall be preserved to the maximum extent permitted taking into account
|
||||
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
||||
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
||||
non transferable, non sublicensable, non exclusive, irrevocable and
|
||||
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
||||
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
||||
provided by applicable law or treaty (including future time extensions), (iii)
|
||||
in any current or future medium and for any number of copies, and (iv) for any
|
||||
purpose whatsoever, including without limitation commercial, advertising or
|
||||
promotional purposes (the "License"). The License shall be deemed effective as
|
||||
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
||||
License for any reason be judged legally invalid or ineffective under
|
||||
applicable law, such partial invalidity or ineffectiveness shall not
|
||||
invalidate the remainder of the License, and in such case Affirmer hereby
|
||||
affirms that he or she will not (i) exercise any of his or her remaining
|
||||
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
||||
and causes of action with respect to the Work, in either case contrary to
|
||||
Affirmer's express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
|
||||
b. Affirmer offers the Work as-is and makes no representations or warranties
|
||||
of any kind concerning the Work, express, implied, statutory or otherwise,
|
||||
including without limitation warranties of title, merchantability, fitness
|
||||
for a particular purpose, non infringement, or the absence of latent or
|
||||
other defects, accuracy, or the present or absence of errors, whether or not
|
||||
discoverable, all to the greatest extent permissible under applicable law.
|
||||
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without limitation
|
||||
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
||||
disclaims responsibility for obtaining any necessary consents, permissions
|
||||
or other rights required for any use of the Work.
|
||||
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to this
|
||||
CC0 or use of the Work.
|
||||
|
||||
For more information, please see
|
||||
<http://creativecommons.org/publicdomain/zero/1.0/>
|
||||
@@ -0,0 +1,23 @@
|
||||
# Examples
|
||||
|
||||
The examples in this folder are small bots meant to show you how a bot that is written with `python-telegram-bot` looks like. Some bots focus on one specific aspect of the Telegram Bot API while others focus on one of the mechanics of this library. Except for the `echobot.py` example, they all use the high-level framework this library provides with the `telegram.ext` submodule.
|
||||
|
||||
All examples are licensed under the [CC0 License](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/LICENSE.txt) and are therefore fully dedicated to the public domain. You can use them as the base for your own bots without worrying about copyrights.
|
||||
|
||||
### [`echobot2.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/v5.0/examples/echobot2.py)
|
||||
This is probably the base for most of the bots made with `python-telegram-bot`. It simply replies to each text message with a message that contains the same text.
|
||||
|
||||
### [`timerbot.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/timerbot.py)
|
||||
This bot uses the [`JobQueue`](https://pythonhosted.org/python-telegram-bot/telegram.ext.jobqueue.html) class to send timed messages. The user sets a timer by using `/set` command with a specific time, for example `/set 30`. The bot then sets up a job to send a message to that user after 30 seconds. The user can also cancel the timer by sending `/unset`. To learn more about the `JobQueue`, read [this wiki article](https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-JobQueue).
|
||||
|
||||
### [`conversationbot.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/conversationbot.py)
|
||||
A common task for a bot is to ask information from the user. In v5.0 of this library, we introduced the [`ConversationHandler`](https://pythonhosted.org/python-telegram-bot/telegram.ext.conversationhandler.html) for that exact purpose. This example uses it to retrieve user-information in a conversation-like style.
|
||||
|
||||
### [`inlinekeyboard.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/inlinekeyboard.py)
|
||||
This example sheds some light on inline keyboards, callback queries and message editing.
|
||||
|
||||
### [`inlinebot.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/inlinebot.py)
|
||||
A basic example of an [inline bot](https://core.telegram.org/bots/inline). Don't forget to enable inline mode with [@BotFather](https://telegram.me/BotFather).
|
||||
|
||||
## Pure API
|
||||
The [`echobot.py`](https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/echobot.py) example uses only the pure, "bare-metal" API wrapper.
|
||||
@@ -0,0 +1,160 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Simple Bot to reply to Telegram messages
|
||||
# This program is dedicated to the public domain under the CC0 license.
|
||||
"""
|
||||
This Bot uses the Updater class to handle the bot.
|
||||
|
||||
First, a few callback functions are defined. Then, those functions are passed to
|
||||
the Dispatcher and registered at their respective places.
|
||||
Then, the bot is started and runs until we press Ctrl-C on the command line.
|
||||
|
||||
Usage:
|
||||
Example of a bot-user conversation using ConversationHandler.
|
||||
Send /start to initiate the conversation.
|
||||
Press Ctrl-C on the command line or send a signal to the process to stop the
|
||||
bot.
|
||||
"""
|
||||
|
||||
from telegram import (ReplyKeyboardMarkup)
|
||||
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, RegexHandler,
|
||||
ConversationHandler)
|
||||
|
||||
import logging
|
||||
|
||||
# Enable logging
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
GENDER, PHOTO, LOCATION, BIO = range(4)
|
||||
|
||||
|
||||
def start(bot, update):
|
||||
reply_keyboard = [['Boy', 'Girl', 'Other']]
|
||||
|
||||
bot.sendMessage(update.message.chat_id,
|
||||
text='Hi! My name is Professor Bot. I will hold a conversation with you. '
|
||||
'Send /cancel to stop talking to me.\n\n'
|
||||
'Are you a boy or a girl?',
|
||||
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
|
||||
|
||||
return GENDER
|
||||
|
||||
|
||||
def gender(bot, update):
|
||||
user = update.message.from_user
|
||||
logger.info("Gender of %s: %s" % (user.first_name, update.message.text))
|
||||
bot.sendMessage(update.message.chat_id,
|
||||
text='I see! Please send me a photo of yourself, '
|
||||
'so I know what you look like, or send /skip if you don\'t want to.')
|
||||
|
||||
return PHOTO
|
||||
|
||||
|
||||
def photo(bot, update):
|
||||
user = update.message.from_user
|
||||
photo_file = bot.getFile(update.message.photo[-1].file_id)
|
||||
photo_file.download('user_photo.jpg')
|
||||
logger.info("Photo of %s: %s" % (user.first_name, 'user_photo.jpg'))
|
||||
bot.sendMessage(update.message.chat_id, text='Gorgeous! Now, send me your location please, '
|
||||
'or send /skip if you don\'t want to.')
|
||||
|
||||
return LOCATION
|
||||
|
||||
|
||||
def skip_photo(bot, update):
|
||||
user = update.message.from_user
|
||||
logger.info("User %s did not send a photo." % user.first_name)
|
||||
bot.sendMessage(update.message.chat_id, text='I bet you look great! Now, send me your '
|
||||
'location please, or send /skip.')
|
||||
|
||||
return LOCATION
|
||||
|
||||
|
||||
def location(bot, update):
|
||||
user = update.message.from_user
|
||||
user_location = update.message.location
|
||||
logger.info("Location of %s: %f / %f"
|
||||
% (user.first_name, user_location.latitude, user_location.longitude))
|
||||
bot.sendMessage(update.message.chat_id, text='Maybe I can visit you sometime! '
|
||||
'At last, tell me something about yourself.')
|
||||
|
||||
return BIO
|
||||
|
||||
|
||||
def skip_location(bot, update):
|
||||
user = update.message.from_user
|
||||
logger.info("User %s did not send a location." % user.first_name)
|
||||
bot.sendMessage(update.message.chat_id, text='You seem a bit paranoid! '
|
||||
'At last, tell me something about yourself.')
|
||||
|
||||
return BIO
|
||||
|
||||
|
||||
def bio(bot, update):
|
||||
user = update.message.from_user
|
||||
logger.info("Bio of %s: %s" % (user.first_name, update.message.text))
|
||||
bot.sendMessage(update.message.chat_id,
|
||||
text='Thank you! I hope we can talk again some day.')
|
||||
|
||||
return ConversationHandler.END
|
||||
|
||||
|
||||
def cancel(bot, update):
|
||||
user = update.message.from_user
|
||||
logger.info("User %s canceled the conversation." % user.first_name)
|
||||
bot.sendMessage(update.message.chat_id,
|
||||
text='Bye! I hope we can talk again some day.')
|
||||
|
||||
return ConversationHandler.END
|
||||
|
||||
|
||||
def error(bot, update, error):
|
||||
logger.warn('Update "%s" caused error "%s"' % (update, error))
|
||||
|
||||
|
||||
def main():
|
||||
# Create the EventHandler and pass it your bot's token.
|
||||
updater = Updater("TOKEN")
|
||||
|
||||
# Get the dispatcher to register handlers
|
||||
dp = updater.dispatcher
|
||||
|
||||
# Add conversation handler with the states GENDER, PHOTO, LOCATION and BIO
|
||||
conv_handler = ConversationHandler(
|
||||
entry_points=[CommandHandler('start', start)],
|
||||
|
||||
states={
|
||||
GENDER: [RegexHandler('^(Boy|Girl|Other)$', gender)],
|
||||
|
||||
PHOTO: [MessageHandler([Filters.photo], photo),
|
||||
CommandHandler('skip', skip_photo)],
|
||||
|
||||
LOCATION: [MessageHandler([Filters.location], location),
|
||||
CommandHandler('skip', skip_location)],
|
||||
|
||||
BIO: [MessageHandler([Filters.text], bio)]
|
||||
},
|
||||
|
||||
fallbacks=[CommandHandler('cancel', cancel)]
|
||||
)
|
||||
|
||||
dp.add_handler(conv_handler)
|
||||
|
||||
# log all errors
|
||||
dp.add_error_handler(error)
|
||||
|
||||
# Start the Bot
|
||||
updater.start_polling()
|
||||
|
||||
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
|
||||
# SIGTERM or SIGABRT. This should be used most of the time, since
|
||||
# start_polling() is non-blocking and will stop the bot gracefully.
|
||||
updater.idle()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
+30
-46
@@ -1,68 +1,52 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Simple Bot to reply Telegram messages
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
|
||||
# Simple Bot to reply to Telegram messages. This is built on the API wrapper, see
|
||||
# echobot2.py to see the same example built on the telegram.ext bot framework.
|
||||
# This program is dedicated to the public domain under the CC0 license.
|
||||
import logging
|
||||
import telegram
|
||||
import time
|
||||
from telegram.error import NetworkError, Unauthorized
|
||||
from time import sleep
|
||||
|
||||
|
||||
LAST_UPDATE_ID = None
|
||||
|
||||
update_id = None
|
||||
|
||||
def main():
|
||||
global LAST_UPDATE_ID
|
||||
|
||||
logging.basicConfig(
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
global update_id
|
||||
# Telegram Bot Authorization Token
|
||||
bot = telegram.Bot('TOKEN')
|
||||
|
||||
# This will be our global variable to keep the latest update_id when requesting
|
||||
# for updates. It starts with the latest update_id if available.
|
||||
# get the first pending update_id, this is so we can skip over it in case
|
||||
# we get an "Unauthorized" exception.
|
||||
try:
|
||||
LAST_UPDATE_ID = bot.getUpdates()[-1].update_id
|
||||
update_id = bot.getUpdates()[0].update_id
|
||||
except IndexError:
|
||||
LAST_UPDATE_ID = None
|
||||
update_id = None
|
||||
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
while True:
|
||||
echo(bot)
|
||||
time.sleep(3)
|
||||
try:
|
||||
echo(bot)
|
||||
except NetworkError:
|
||||
sleep(1)
|
||||
except Unauthorized:
|
||||
# The user has removed or blocked the bot.
|
||||
update_id += 1
|
||||
|
||||
|
||||
def echo(bot):
|
||||
global LAST_UPDATE_ID
|
||||
global update_id
|
||||
# Request updates after the last update_id
|
||||
for update in bot.getUpdates(offset=update_id, timeout=10):
|
||||
# chat_id is required to reply to any message
|
||||
chat_id = update.message.chat_id
|
||||
update_id = update.update_id + 1
|
||||
|
||||
# Request updates from last updated_id
|
||||
for update in bot.getUpdates(offset=LAST_UPDATE_ID):
|
||||
if LAST_UPDATE_ID < update.update_id:
|
||||
# chat_id is required to reply any message
|
||||
chat_id = update.message.chat_id
|
||||
message = update.message.text.encode('utf-8')
|
||||
|
||||
if (message):
|
||||
# Reply the message
|
||||
bot.sendMessage(chat_id=chat_id,
|
||||
text=message)
|
||||
|
||||
# Updates global offset to get the new updates
|
||||
LAST_UPDATE_ID = update.update_id
|
||||
if update.message: # your bot can receive updates without messages
|
||||
# Reply to the message
|
||||
bot.sendMessage(chat_id=chat_id, text=update.message.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Simple Bot to reply to Telegram messages
|
||||
# This program is dedicated to the public domain under the CC0 license.
|
||||
"""
|
||||
This Bot uses the Updater class to handle the bot.
|
||||
|
||||
First, a few handler functions are defined. Then, those functions are passed to
|
||||
the Dispatcher and registered at their respective places.
|
||||
Then, the bot is started and runs until we press Ctrl-C on the command line.
|
||||
|
||||
Usage:
|
||||
Basic Echobot example, repeats messages.
|
||||
Press Ctrl-C on the command line or send a signal to the process to stop the
|
||||
bot.
|
||||
"""
|
||||
|
||||
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
|
||||
import logging
|
||||
|
||||
# Enable logging
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Define a few command handlers. These usually take the two arguments bot and
|
||||
# update. Error handlers also receive the raised TelegramError object in error.
|
||||
def start(bot, update):
|
||||
update.message.reply_text('Hi!')
|
||||
|
||||
|
||||
def help(bot, update):
|
||||
update.message.reply_text('Help!')
|
||||
|
||||
|
||||
def echo(bot, update):
|
||||
update.message.reply_text(update.message.text)
|
||||
|
||||
|
||||
def error(bot, update, error):
|
||||
logger.warn('Update "%s" caused error "%s"' % (update, error))
|
||||
|
||||
|
||||
def main():
|
||||
# Create the EventHandler and pass it your bot's token.
|
||||
updater = Updater("TOKEN")
|
||||
|
||||
# Get the dispatcher to register handlers
|
||||
dp = updater.dispatcher
|
||||
|
||||
# on different commands - answer in Telegram
|
||||
dp.add_handler(CommandHandler("start", start))
|
||||
dp.add_handler(CommandHandler("help", help))
|
||||
|
||||
# on noncommand i.e message - echo the message on Telegram
|
||||
dp.add_handler(MessageHandler([Filters.text], echo))
|
||||
|
||||
# log all errors
|
||||
dp.add_error_handler(error)
|
||||
|
||||
# Start the Bot
|
||||
updater.start_polling()
|
||||
|
||||
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
|
||||
# SIGTERM or SIGABRT. This should be used most of the time, since
|
||||
# start_polling() is non-blocking and will stop the bot gracefully.
|
||||
updater.idle()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Simple Bot to reply to Telegram messages
|
||||
# This program is dedicated to the public domain under the CC0 license.
|
||||
"""
|
||||
This Bot uses the Updater class to handle the bot.
|
||||
|
||||
First, a few handler functions are defined. Then, those functions are passed to
|
||||
the Dispatcher and registered at their respective places.
|
||||
Then, the bot is started and runs until we press Ctrl-C on the command line.
|
||||
|
||||
Usage:
|
||||
Basic inline bot example. Applies different text transformations.
|
||||
Press Ctrl-C on the command line or send a signal to the process to stop the
|
||||
bot.
|
||||
"""
|
||||
from uuid import uuid4
|
||||
|
||||
import re
|
||||
|
||||
from telegram import InlineQueryResultArticle, ParseMode, \
|
||||
InputTextMessageContent
|
||||
from telegram.ext import Updater, InlineQueryHandler, CommandHandler
|
||||
import logging
|
||||
|
||||
# Enable logging
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Define a few command handlers. These usually take the two arguments bot and
|
||||
# update. Error handlers also receive the raised TelegramError object in error.
|
||||
def start(bot, update):
|
||||
bot.sendMessage(update.message.chat_id, text='Hi!')
|
||||
|
||||
|
||||
def help(bot, update):
|
||||
bot.sendMessage(update.message.chat_id, text='Help!')
|
||||
|
||||
|
||||
def escape_markdown(text):
|
||||
"""Helper function to escape telegram markup symbols"""
|
||||
escape_chars = '\*_`\['
|
||||
return re.sub(r'([%s])' % escape_chars, r'\\\1', text)
|
||||
|
||||
|
||||
def inlinequery(bot, update):
|
||||
query = update.inline_query.query
|
||||
results = list()
|
||||
|
||||
results.append(InlineQueryResultArticle(id=uuid4(),
|
||||
title="Caps",
|
||||
input_message_content=InputTextMessageContent(
|
||||
query.upper())))
|
||||
|
||||
results.append(InlineQueryResultArticle(id=uuid4(),
|
||||
title="Bold",
|
||||
input_message_content=InputTextMessageContent(
|
||||
"*%s*" % escape_markdown(query),
|
||||
parse_mode=ParseMode.MARKDOWN)))
|
||||
|
||||
results.append(InlineQueryResultArticle(id=uuid4(),
|
||||
title="Italic",
|
||||
input_message_content=InputTextMessageContent(
|
||||
"_%s_" % escape_markdown(query),
|
||||
parse_mode=ParseMode.MARKDOWN)))
|
||||
|
||||
bot.answerInlineQuery(update.inline_query.id, results=results)
|
||||
|
||||
|
||||
def error(bot, update, error):
|
||||
logger.warn('Update "%s" caused error "%s"' % (update, error))
|
||||
|
||||
|
||||
def main():
|
||||
# Create the Updater and pass it your bot's token.
|
||||
updater = Updater("TOKEN")
|
||||
|
||||
# Get the dispatcher to register handlers
|
||||
dp = updater.dispatcher
|
||||
|
||||
# on different commands - answer in Telegram
|
||||
dp.add_handler(CommandHandler("start", start))
|
||||
dp.add_handler(CommandHandler("help", help))
|
||||
|
||||
# on noncommand i.e message - echo the message on Telegram
|
||||
dp.add_handler(InlineQueryHandler(inlinequery))
|
||||
|
||||
# log all errors
|
||||
dp.add_error_handler(error)
|
||||
|
||||
# Start the Bot
|
||||
updater.start_polling()
|
||||
|
||||
# Block until the user presses Ctrl-C or the process receives SIGINT,
|
||||
# SIGTERM or SIGABRT. This should be used most of the time, since
|
||||
# start_polling() is non-blocking and will stop the bot gracefully.
|
||||
updater.idle()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Basic example for a bot that uses inline keyboards.
|
||||
# This program is dedicated to the public domain under the CC0 license.
|
||||
|
||||
import logging
|
||||
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
|
||||
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO)
|
||||
|
||||
|
||||
def start(bot, update):
|
||||
keyboard = [[InlineKeyboardButton("Option 1", callback_data='1'),
|
||||
InlineKeyboardButton("Option 2", callback_data='2')],
|
||||
|
||||
[InlineKeyboardButton("Option 3", callback_data='3')]]
|
||||
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
||||
bot.sendMessage(update.message.chat_id, text="Please choose:", reply_markup=reply_markup)
|
||||
|
||||
|
||||
def button(bot, update):
|
||||
query = update.callback_query
|
||||
|
||||
bot.editMessageText(text="Selected option: %s" % query.data,
|
||||
chat_id=query.message.chat_id,
|
||||
message_id=query.message.message_id)
|
||||
|
||||
|
||||
def help(bot, update):
|
||||
bot.sendMessage(update.message.chat_id, text="Use /start to test this bot.")
|
||||
|
||||
|
||||
def error(bot, update, error):
|
||||
logging.warning('Update "%s" caused error "%s"' % (update, error))
|
||||
|
||||
|
||||
# Create the Updater and pass it your bot's token.
|
||||
updater = Updater("TOKEN")
|
||||
|
||||
updater.dispatcher.add_handler(CommandHandler('start', start))
|
||||
updater.dispatcher.add_handler(CallbackQueryHandler(button))
|
||||
updater.dispatcher.add_handler(CommandHandler('help', help))
|
||||
updater.dispatcher.add_error_handler(error)
|
||||
|
||||
# Start the Bot
|
||||
updater.start_polling()
|
||||
|
||||
# Run the bot until the user presses Ctrl-C or the process receives SIGINT,
|
||||
# SIGTERM or SIGABRT
|
||||
updater.idle()
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
#
|
||||
# Robô Ed Telegram Bot
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
|
||||
__author__ = 'leandrotoledodesouza@gmail.com'
|
||||
|
||||
import logging
|
||||
import telegram
|
||||
import urllib
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
bot = telegram.Bot('TOKEN') # Telegram Bot Authorization Token
|
||||
|
||||
LAST_UPDATE_ID = bot.getUpdates()[-1].update_id # Get lastest update
|
||||
|
||||
while True:
|
||||
for update in bot.getUpdates(offset=LAST_UPDATE_ID):
|
||||
text = update.message.text
|
||||
chat_id = update.message.chat.id
|
||||
update_id = update.update_id
|
||||
|
||||
if LAST_UPDATE_ID < update_id: # If newer than the initial
|
||||
# LAST_UPDATE_ID
|
||||
if text:
|
||||
roboed = ed(text) # Ask something to Robô Ed
|
||||
bot.sendMessage(chat_id=chat_id, text=roboed)
|
||||
LAST_UPDATE_ID = update_id
|
||||
|
||||
|
||||
def ed(text):
|
||||
url = 'http://www.ed.conpet.gov.br/mod_perl/bot_gateway.cgi?server=0.0.0.0%3A8085&charset_post=utf-8&charset=utf-8&pure=1&js=0&tst=1&msg=' + text
|
||||
data = urllib.urlopen(url).read()
|
||||
|
||||
return data.strip()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Simple Bot to send timed Telegram messages
|
||||
# This program is dedicated to the public domain under the CC0 license.
|
||||
"""
|
||||
This Bot uses the Updater class to handle the bot and the JobQueue to send
|
||||
timed messages.
|
||||
|
||||
First, a few handler functions are defined. Then, those functions are passed to
|
||||
the Dispatcher and registered at their respective places.
|
||||
Then, the bot is started and runs until we press Ctrl-C on the command line.
|
||||
|
||||
Usage:
|
||||
Basic Alarm Bot example, sends a message after a set time.
|
||||
Press Ctrl-C on the command line or send a signal to the process to stop the
|
||||
bot.
|
||||
"""
|
||||
|
||||
from telegram.ext import Updater, CommandHandler, Job
|
||||
import logging
|
||||
|
||||
# Enable logging
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.DEBUG)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
timers = dict()
|
||||
|
||||
|
||||
# Define a few command handlers. These usually take the two arguments bot and
|
||||
# update. Error handlers also receive the raised TelegramError object in error.
|
||||
def start(bot, update):
|
||||
bot.sendMessage(update.message.chat_id, text='Hi! Use /set <seconds> to ' 'set a timer')
|
||||
|
||||
|
||||
def alarm(bot, job):
|
||||
"""Function to send the alarm message"""
|
||||
bot.sendMessage(job.context, text='Beep!')
|
||||
|
||||
|
||||
def set(bot, update, args, job_queue):
|
||||
"""Adds a job to the queue"""
|
||||
chat_id = update.message.chat_id
|
||||
try:
|
||||
# args[0] should contain the time for the timer in seconds
|
||||
due = int(args[0])
|
||||
if due < 0:
|
||||
bot.sendMessage(chat_id, text='Sorry we can not go back to future!')
|
||||
return
|
||||
|
||||
# Add job to queue
|
||||
job = Job(alarm, due, repeat=False, context=chat_id)
|
||||
timers[chat_id] = job
|
||||
job_queue.put(job)
|
||||
|
||||
bot.sendMessage(chat_id, text='Timer successfully set!')
|
||||
|
||||
except (IndexError, ValueError):
|
||||
bot.sendMessage(chat_id, text='Usage: /set <seconds>')
|
||||
|
||||
|
||||
def unset(bot, update, job_queue):
|
||||
"""Removes the job if the user changed their mind"""
|
||||
chat_id = update.message.chat_id
|
||||
|
||||
if chat_id not in timers:
|
||||
bot.sendMessage(chat_id, text='You have no active timer')
|
||||
return
|
||||
|
||||
job = timers[chat_id]
|
||||
job.schedule_removal()
|
||||
del timers[chat_id]
|
||||
|
||||
bot.sendMessage(chat_id, text='Timer successfully unset!')
|
||||
|
||||
|
||||
def error(bot, update, error):
|
||||
logger.warn('Update "%s" caused error "%s"' % (update, error))
|
||||
|
||||
|
||||
def main():
|
||||
updater = Updater("TOKEN")
|
||||
|
||||
# Get the dispatcher to register handlers
|
||||
dp = updater.dispatcher
|
||||
|
||||
# on different commands - answer in Telegram
|
||||
dp.add_handler(CommandHandler("start", start))
|
||||
dp.add_handler(CommandHandler("help", start))
|
||||
dp.add_handler(CommandHandler("set", set, pass_args=True, pass_job_queue=True))
|
||||
dp.add_handler(CommandHandler("unset", unset, pass_job_queue=True))
|
||||
|
||||
# log all errors
|
||||
dp.add_error_handler(error)
|
||||
|
||||
# Start the Bot
|
||||
updater.start_polling()
|
||||
|
||||
# Block until the you presses Ctrl-C or the process receives SIGINT,
|
||||
# SIGTERM or SIGABRT. This should be used most of the time, since
|
||||
# start_polling() is non-blocking and will stop the bot gracefully.
|
||||
updater.idle()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,8 @@
|
||||
flake8
|
||||
nose
|
||||
pep257
|
||||
pylint
|
||||
flaky
|
||||
yapf
|
||||
pre-commit
|
||||
pre-commit-hooks
|
||||
@@ -0,0 +1,3 @@
|
||||
future>=0.15.2
|
||||
urllib3>=1.10
|
||||
certifi
|
||||
@@ -8,3 +8,12 @@ all_files = 1
|
||||
|
||||
[upload_sphinx]
|
||||
upload-dir = docs/build/html
|
||||
|
||||
[flake8]
|
||||
max-line-length = 99
|
||||
ignore = W503
|
||||
|
||||
[yapf]
|
||||
based_on_style = google
|
||||
split_before_logical_operator = True
|
||||
column_limit = 99
|
||||
|
||||
@@ -1,45 +1,56 @@
|
||||
#!/usr/bin/env python
|
||||
"""The setup and build script for the python-telegram-bot library."""
|
||||
|
||||
'''The setup and build script for the python-telegram-bot library.'''
|
||||
|
||||
import codecs
|
||||
import os
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
def read(*paths):
|
||||
"""Build a file path from *paths* and return the contents."""
|
||||
with open(os.path.join(*paths), 'r') as f:
|
||||
return f.read()
|
||||
def requirements():
|
||||
"""Build the requirements list for this project"""
|
||||
requirements_list = []
|
||||
|
||||
with open('requirements.txt') as requirements:
|
||||
for install in requirements:
|
||||
requirements_list.append(install.strip())
|
||||
|
||||
return requirements_list
|
||||
|
||||
|
||||
setup(
|
||||
name='python-telegram-bot',
|
||||
version='2.6.1',
|
||||
author='Leandro Toledo',
|
||||
author_email='leandrotoledodesouza@gmail.com',
|
||||
license='LGPLv3',
|
||||
url='https://github.com/leandrotoledo/python-telegram-bot',
|
||||
keywords='telegram bot api',
|
||||
description='A Python wrapper around the Telegram Bot API',
|
||||
long_description=(read('README.rst')),
|
||||
packages=find_packages(exclude=['tests*']),
|
||||
include_package_data=True,
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
|
||||
'Operating System :: OS Independent',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
'Topic :: Communications :: Chat',
|
||||
'Topic :: Internet',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2',
|
||||
'Programming Language :: Python :: 2.6',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.2',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
],
|
||||
)
|
||||
with codecs.open('README.rst', 'r', 'utf-8') as fd:
|
||||
fn = os.path.join('telegram', 'version.py')
|
||||
with open(fn) as fh:
|
||||
code = compile(fh.read(), fn, 'exec')
|
||||
exec(code)
|
||||
|
||||
setup(name='python-telegram-bot',
|
||||
version=__version__,
|
||||
author='Leandro Toledo',
|
||||
author_email='devs@python-telegram-bot.org',
|
||||
license='LGPLv3',
|
||||
url='https://python-telegram-bot.org/',
|
||||
keywords='python telegram bot api wrapper',
|
||||
description='Not just a Python wrapper around the Telegram Bot API',
|
||||
long_description=fd.read(),
|
||||
packages=find_packages(exclude=['tests*']),
|
||||
install_requires=requirements(),
|
||||
extras_require={
|
||||
'json': 'ujson',
|
||||
},
|
||||
include_package_data=True,
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
|
||||
'Operating System :: OS Independent',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
'Topic :: Communications :: Chat',
|
||||
'Topic :: Internet',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
],)
|
||||
|
||||
+70
-15
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
@@ -15,16 +16,14 @@
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""A library that provides a Python interface to the Telegram Bot API"""
|
||||
|
||||
|
||||
__author__ = 'leandrotoledodesouza@gmail.com'
|
||||
__version__ = '2.6.1'
|
||||
from sys import version_info
|
||||
|
||||
from .base import TelegramObject
|
||||
from .user import User
|
||||
from .message import Message
|
||||
from .update import Update
|
||||
from .groupchat import GroupChat
|
||||
from .chat import Chat
|
||||
from .chatmember import ChatMember
|
||||
from .photosize import PhotoSize
|
||||
from .audio import Audio
|
||||
from .voice import Voice
|
||||
@@ -33,21 +32,77 @@ from .sticker import Sticker
|
||||
from .video import Video
|
||||
from .contact import Contact
|
||||
from .location import Location
|
||||
from .venue import Venue
|
||||
from .chataction import ChatAction
|
||||
from .userprofilephotos import UserProfilePhotos
|
||||
from .keyboardbutton import KeyboardButton
|
||||
from .replymarkup import ReplyMarkup
|
||||
from .replykeyboardmarkup import ReplyKeyboardMarkup
|
||||
from .replykeyboardhide import ReplyKeyboardHide
|
||||
from .forcereply import ForceReply
|
||||
from .inputfile import InputFile
|
||||
from .error import TelegramError
|
||||
from .nullhandler import NullHandler
|
||||
from .inputfile import InputFile
|
||||
from .file import File
|
||||
from .emoji import Emoji
|
||||
from .parsemode import ParseMode
|
||||
from .messageentity import MessageEntity
|
||||
from .message import Message
|
||||
from .inputmessagecontent import InputMessageContent
|
||||
from .callbackquery import CallbackQuery
|
||||
from .choseninlineresult import ChosenInlineResult
|
||||
from .inlinekeyboardbutton import InlineKeyboardButton
|
||||
from .inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from .inlinequery import InlineQuery
|
||||
from .inlinequeryresult import InlineQueryResult
|
||||
from .inlinequeryresultarticle import InlineQueryResultArticle
|
||||
from .inlinequeryresultaudio import InlineQueryResultAudio
|
||||
from .inlinequeryresultcachedaudio import InlineQueryResultCachedAudio
|
||||
from .inlinequeryresultcacheddocument import InlineQueryResultCachedDocument
|
||||
from .inlinequeryresultcachedgif import InlineQueryResultCachedGif
|
||||
from .inlinequeryresultcachedmpeg4gif import InlineQueryResultCachedMpeg4Gif
|
||||
from .inlinequeryresultcachedphoto import InlineQueryResultCachedPhoto
|
||||
from .inlinequeryresultcachedsticker import InlineQueryResultCachedSticker
|
||||
from .inlinequeryresultcachedvideo import InlineQueryResultCachedVideo
|
||||
from .inlinequeryresultcachedvoice import InlineQueryResultCachedVoice
|
||||
from .inlinequeryresultcontact import InlineQueryResultContact
|
||||
from .inlinequeryresultdocument import InlineQueryResultDocument
|
||||
from .inlinequeryresultgif import InlineQueryResultGif
|
||||
from .inlinequeryresultlocation import InlineQueryResultLocation
|
||||
from .inlinequeryresultmpeg4gif import InlineQueryResultMpeg4Gif
|
||||
from .inlinequeryresultphoto import InlineQueryResultPhoto
|
||||
from .inlinequeryresultvenue import InlineQueryResultVenue
|
||||
from .inlinequeryresultvideo import InlineQueryResultVideo
|
||||
from .inlinequeryresultvoice import InlineQueryResultVoice
|
||||
from .inputtextmessagecontent import InputTextMessageContent
|
||||
from .inputlocationmessagecontent import InputLocationMessageContent
|
||||
from .inputvenuemessagecontent import InputVenueMessageContent
|
||||
from .inputcontactmessagecontent import InputContactMessageContent
|
||||
from .update import Update
|
||||
from .bot import Bot
|
||||
from .constants import (MAX_MESSAGE_LENGTH, MAX_CAPTION_LENGTH, SUPPORTED_WEBHOOK_PORTS,
|
||||
MAX_FILESIZE_DOWNLOAD, MAX_FILESIZE_UPLOAD,
|
||||
MAX_MESSAGES_PER_SECOND_PER_CHAT, MAX_MESSAGES_PER_SECOND,
|
||||
MAX_MESSAGES_PER_MINUTE_PER_GROUP)
|
||||
from .version import __version__ # flake8: noqa
|
||||
|
||||
__all__ = ['Bot', 'Emoji', 'TelegramError', 'InputFile', 'ReplyMarkup',
|
||||
'ForceReply', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup',
|
||||
'UserProfilePhotos', 'ChatAction', 'Location', 'Contact',
|
||||
'Video', 'Sticker', 'Document', 'Audio', 'PhotoSize', 'GroupChat',
|
||||
'Update', 'Message', 'User', 'TelegramObject', 'NullHandler',
|
||||
'Voice']
|
||||
__author__ = 'devs@python-telegram-bot.org'
|
||||
|
||||
__all__ = ['Audio', 'Bot', 'Chat', 'ChatMember', 'ChatAction', 'ChosenInlineResult',
|
||||
'CallbackQuery', 'Contact', 'Document', 'Emoji', 'File', 'ForceReply',
|
||||
'InlineKeyboardButton', 'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult',
|
||||
'InlineQueryResult', 'InlineQueryResultArticle', 'InlineQueryResultAudio',
|
||||
'InlineQueryResultCachedAudio', 'InlineQueryResultCachedDocument',
|
||||
'InlineQueryResultCachedGif', 'InlineQueryResultCachedMpeg4Gif',
|
||||
'InlineQueryResultCachedPhoto', 'InlineQueryResultCachedSticker',
|
||||
'InlineQueryResultCachedVideo', 'InlineQueryResultCachedVoice',
|
||||
'InlineQueryResultContact', 'InlineQueryResultDocument', 'InlineQueryResultGif',
|
||||
'InlineQueryResultLocation', 'InlineQueryResultMpeg4Gif', 'InlineQueryResultPhoto',
|
||||
'InlineQueryResultVenue', 'InlineQueryResultVideo', 'InlineQueryResultVoice',
|
||||
'InputContactMessageContent', 'InputFile', 'InputLocationMessageContent',
|
||||
'InputMessageContent', 'InputTextMessageContent', 'InputVenueMessageContent',
|
||||
'KeyboardButton', 'Location', 'Message', 'MessageEntity', 'ParseMode', 'PhotoSize',
|
||||
'ReplyKeyboardHide', 'ReplyKeyboardMarkup', 'ReplyMarkup', 'Sticker', 'TelegramError',
|
||||
'TelegramObject', 'Update', 'User', 'UserProfilePhotos', 'Venue', 'Video', 'Voice',
|
||||
'MAX_MESSAGE_LENGTH', 'MAX_CAPTION_LENGTH', 'SUPPORTED_WEBHOOK_PORTS',
|
||||
'MAX_FILESIZE_DOWNLOAD', 'MAX_FILESIZE_UPLOAD', 'MAX_MESSAGES_PER_SECOND_PER_CHAT',
|
||||
'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_MINUTE_PER_GROUP']
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import sys
|
||||
|
||||
import urllib3
|
||||
import certifi
|
||||
import future
|
||||
|
||||
from . import __version__ as telegram_ver
|
||||
|
||||
|
||||
def print_ver_info():
|
||||
print('python-telegram-bot {0}'.format(telegram_ver))
|
||||
print('urllib3 {0}'.format(urllib3.__version__))
|
||||
print('certifi {0}'.format(certifi.__version__))
|
||||
print('future {0}'.format(future.__version__))
|
||||
print('Python {0}'.format(sys.version.replace('\n', ' ')))
|
||||
|
||||
# main
|
||||
print_ver_info()
|
||||
+46
-34
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
@@ -15,44 +16,55 @@
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Telegram Audio."""
|
||||
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class Audio(TelegramObject):
|
||||
def __init__(self,
|
||||
file_id,
|
||||
duration,
|
||||
performer=None,
|
||||
title=None,
|
||||
mime_type=None,
|
||||
file_size=None):
|
||||
self.file_id = file_id
|
||||
self.duration = duration
|
||||
self.performer = performer
|
||||
self.title = title
|
||||
self.mime_type = mime_type
|
||||
self.file_size = file_size
|
||||
"""This object represents a Telegram Audio.
|
||||
|
||||
Attributes:
|
||||
file_id (str):
|
||||
duration (int):
|
||||
performer (str):
|
||||
title (str):
|
||||
mime_type (str):
|
||||
file_size (int):
|
||||
|
||||
Args:
|
||||
file_id (str):
|
||||
duration (int):
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
performer (Optional[str]):
|
||||
title (Optional[str]):
|
||||
mime_type (Optional[str]):
|
||||
file_size (Optional[int]):
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, duration, **kwargs):
|
||||
# Required
|
||||
self.file_id = str(file_id)
|
||||
self.duration = int(duration)
|
||||
# Optionals
|
||||
self.performer = kwargs.get('performer', '')
|
||||
self.title = kwargs.get('title', '')
|
||||
self.mime_type = str(kwargs.get('mime_type', ''))
|
||||
self.file_size = int(kwargs.get('file_size', 0))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
return Audio(file_id=data.get('file_id', None),
|
||||
duration=data.get('duration', None),
|
||||
performer=data.get('performer', None),
|
||||
title=data.get('title', None),
|
||||
mime_type=data.get('mime_type', None),
|
||||
file_size=data.get('file_size', None))
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
def to_dict(self):
|
||||
data = {'file_id': self.file_id,
|
||||
'duration': self.duration}
|
||||
if self.performer:
|
||||
data['performer'] = self.performer
|
||||
if self.title:
|
||||
data['title'] = self.title
|
||||
if self.mime_type:
|
||||
data['mime_type'] = self.mime_type
|
||||
if self.file_size:
|
||||
data['file_size'] = self.file_size
|
||||
return data
|
||||
Returns:
|
||||
telegram.Audio:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return Audio(**data)
|
||||
|
||||
+46
-8
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
@@ -15,14 +16,18 @@
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""Base class for Telegram Objects."""
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
except ImportError:
|
||||
import json
|
||||
|
||||
import json
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from abc import ABCMeta
|
||||
|
||||
|
||||
class TelegramObject(object):
|
||||
"""Base class for most telegram object"""
|
||||
"""Base class for most telegram objects."""
|
||||
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
@@ -33,12 +38,45 @@ class TelegramObject(object):
|
||||
return self.__dict__[item]
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
raise NotImplementedError
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
dict:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = data.copy()
|
||||
|
||||
return data
|
||||
|
||||
def to_json(self):
|
||||
"""
|
||||
Returns:
|
||||
str:
|
||||
"""
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@abstractmethod
|
||||
def to_dict(self):
|
||||
return
|
||||
"""
|
||||
Returns:
|
||||
dict:
|
||||
"""
|
||||
data = dict()
|
||||
|
||||
for key in iter(self.__dict__):
|
||||
if key == 'bot':
|
||||
continue
|
||||
|
||||
value = self.__dict__[key]
|
||||
if value is not None:
|
||||
if hasattr(value, 'to_dict'):
|
||||
data[key] = value.to_dict()
|
||||
else:
|
||||
data[key] = value
|
||||
|
||||
return data
|
||||
|
||||
+1050
-313
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents a Telegram
|
||||
CallbackQuery"""
|
||||
|
||||
from telegram import TelegramObject, Message, User
|
||||
|
||||
|
||||
class CallbackQuery(TelegramObject):
|
||||
"""This object represents a Telegram CallbackQuery."""
|
||||
|
||||
def __init__(self, id, from_user, data, bot=None, **kwargs):
|
||||
# Required
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
self.data = data
|
||||
# Optionals
|
||||
self.message = kwargs.get('message')
|
||||
self.inline_message_id = kwargs.get('inline_message_id', '')
|
||||
|
||||
self.bot = bot
|
||||
|
||||
@staticmethod
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.CallbackQuery:
|
||||
"""
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['from_user'] = User.de_json(data.get('from'), bot)
|
||||
data['message'] = Message.de_json(data.get('message'), bot)
|
||||
|
||||
return CallbackQuery(bot=bot, **data)
|
||||
|
||||
def to_dict(self):
|
||||
"""
|
||||
Returns:
|
||||
dict:
|
||||
"""
|
||||
data = super(CallbackQuery, self).to_dict()
|
||||
|
||||
# Required
|
||||
data['from'] = data.pop('from_user', None)
|
||||
return data
|
||||
|
||||
def answer(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.answerCallbackQuery(update.callback_query.id, *args, **kwargs)``"""
|
||||
return self.bot.answerCallbackQuery(self.id, *args, **kwargs)
|
||||
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python
|
||||
# pylint: disable=C0103,W0622
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents a Telegram Chat."""
|
||||
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class Chat(TelegramObject):
|
||||
"""This object represents a Telegram Chat.
|
||||
|
||||
Attributes:
|
||||
id (int):
|
||||
type (str): Can be 'private', 'group', 'supergroup' or 'channel'
|
||||
title (str): Title, for channels and group chats
|
||||
username (str): Username, for private chats and channels if available
|
||||
first_name (str): First name of the other party in a private chat
|
||||
last_name (str): Last name of the other party in a private chat
|
||||
|
||||
Args:
|
||||
id (int):
|
||||
type (str):
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
type (Optional[str]):
|
||||
bot (Optional[Bot]): The Bot to use for instance methods
|
||||
"""
|
||||
|
||||
PRIVATE = 'private'
|
||||
GROUP = 'group'
|
||||
SUPERGROUP = 'supergroup'
|
||||
CHANNEL = 'channel'
|
||||
|
||||
def __init__(self, id, type, bot=None, **kwargs):
|
||||
# Required
|
||||
self.id = int(id)
|
||||
self.type = type
|
||||
# Optionals
|
||||
self.title = kwargs.get('title', '')
|
||||
self.username = kwargs.get('username', '')
|
||||
self.first_name = kwargs.get('first_name', '')
|
||||
self.last_name = kwargs.get('last_name', '')
|
||||
|
||||
self.bot = bot
|
||||
|
||||
@staticmethod
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.Chat:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return Chat(bot=bot, **data)
|
||||
|
||||
def send_action(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendChatAction(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.sendChatAction(self.id, *args, **kwargs)
|
||||
|
||||
def leave(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.leaveChat(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.leaveChat(self.id, *args, **kwargs)
|
||||
|
||||
def get_administrators(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.getChatAdministrators(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.getChatAdministrators(self.id, *args, **kwargs)
|
||||
|
||||
def get_members_count(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.getChatMembersCount(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.getChatMembersCount(self.id, *args, **kwargs)
|
||||
|
||||
def get_member(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.getChatMember(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.getChatMember(self.id, *args, **kwargs)
|
||||
|
||||
def kick_member(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.kickChatMember(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.kickChatMember(self.id, *args, **kwargs)
|
||||
|
||||
def unban_member(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.unbanChatMember(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.unbanChatMember(self.id, *args, **kwargs)
|
||||
+10
-3
@@ -1,7 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
# pylint: disable=R0903
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
@@ -15,12 +17,17 @@
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents a Telegram ChatAction."""
|
||||
|
||||
|
||||
class ChatAction(object):
|
||||
"""This object represents a Telegram ChatAction."""
|
||||
|
||||
TYPING = 'typing'
|
||||
UPLOAD_PHOTO = 'upload_photo'
|
||||
RECORD_VIDEO = 'upload_video'
|
||||
RECORD_AUDIO = 'upload_audio'
|
||||
RECORD_VIDEO = 'record_video'
|
||||
UPLOAD_VIDEO = 'upload_video'
|
||||
RECORD_AUDIO = 'record_audio'
|
||||
UPLOAD_AUDIO = 'upload_audio'
|
||||
UPLOAD_DOCUMENT = 'upload_document'
|
||||
FIND_LOCATION = 'find_location'
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents a Telegram ChatMember."""
|
||||
|
||||
from telegram import User, TelegramObject
|
||||
|
||||
|
||||
class ChatMember(TelegramObject):
|
||||
"""This object represents a Telegram ChatMember.
|
||||
|
||||
Attributes:
|
||||
user (:class:`telegram.User`): Information about the user.
|
||||
status (str): The member's status in the chat. Can be 'creator', 'administrator', 'member',
|
||||
'left' or 'kicked'.
|
||||
|
||||
Args:
|
||||
user (:class:`telegram.User`):
|
||||
status (str):
|
||||
"""
|
||||
|
||||
CREATOR = 'creator'
|
||||
ADMINISTRATOR = 'administrator'
|
||||
MEMBER = 'member'
|
||||
LEFT = 'left'
|
||||
KICKED = 'kicked'
|
||||
|
||||
def __init__(self, user, status, **kwargs):
|
||||
# Required
|
||||
self.user = user
|
||||
self.status = status
|
||||
|
||||
@staticmethod
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.ChatMember:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['user'] = User.de_json(data.get('user'), bot)
|
||||
|
||||
return ChatMember(**data)
|
||||
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python
|
||||
# pylint: disable=R0902,R0912,R0913
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""
|
||||
This module contains a object that represents a Telegram ChosenInlineResult
|
||||
"""
|
||||
|
||||
from telegram import TelegramObject, User, Location
|
||||
|
||||
|
||||
class ChosenInlineResult(TelegramObject):
|
||||
"""This object represents a Telegram ChosenInlineResult.
|
||||
|
||||
Note:
|
||||
* In Python `from` is a reserved word, use `from_user` instead.
|
||||
|
||||
Attributes:
|
||||
result_id (str):
|
||||
from_user (:class:`telegram.User`):
|
||||
query (str):
|
||||
|
||||
Args:
|
||||
result_id (str):
|
||||
from_user (:class:`telegram.User`):
|
||||
query (str):
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
result_id,
|
||||
from_user,
|
||||
query,
|
||||
location=None,
|
||||
inline_message_id=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
self.result_id = result_id
|
||||
self.from_user = from_user
|
||||
self.query = query
|
||||
# Optionals
|
||||
self.location = location
|
||||
self.inline_message_id = inline_message_id
|
||||
|
||||
@staticmethod
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.ChosenInlineResult:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
# Required
|
||||
data['from_user'] = User.de_json(data.pop('from'), bot)
|
||||
# Optionals
|
||||
data['location'] = Location.de_json(data.get('location'), bot)
|
||||
|
||||
return ChosenInlineResult(**data)
|
||||
|
||||
def to_dict(self):
|
||||
"""
|
||||
Returns:
|
||||
dict:
|
||||
"""
|
||||
data = super(ChosenInlineResult, self).to_dict()
|
||||
|
||||
# Required
|
||||
data['from'] = data.pop('from_user', None)
|
||||
|
||||
return data
|
||||
@@ -0,0 +1,54 @@
|
||||
# python-telegram-bot - a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# by the python-telegram-bot contributors <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""Constants in the Telegram network.
|
||||
|
||||
Attributes:
|
||||
MAX_MESSAGE_LENGTH (int): from
|
||||
https://core.telegram.org/method/messages.sendMessage#return-errors
|
||||
MAX_CAPTION_LENGTH (int): from https://core.telegram.org/bots/api#sendphoto
|
||||
|
||||
The following constants were extracted from the
|
||||
`Telegram Bots FAQ <https://core.telegram.org/bots/faq>`_.
|
||||
|
||||
Attributes:
|
||||
SUPPORTED_WEBHOOK_PORTS (List[int])
|
||||
MAX_FILESIZE_DOWNLOAD (int): In bytes.
|
||||
MAX_FILESIZE_UPLOAD (int): Official limit, the actual limit can be a bit higher.
|
||||
MAX_MESSAGES_PER_SECOND_PER_CHAT (int): Telegram may allow short bursts that go over this
|
||||
limit, but eventually you'll begin receiving 429 errors.
|
||||
MAX_MESSAGES_PER_SECOND (int)
|
||||
MAX_MESSAGES_PER_MINUTE_PER_GROUP (int)
|
||||
|
||||
The following constant have been found by experimentation:
|
||||
|
||||
Attributes:
|
||||
MAX_MESSAGE_ENTITIES (int): Max number of entities that can be in a message.
|
||||
(Beyond this cap telegram will simply ignore further formatting styles)
|
||||
"""
|
||||
|
||||
MAX_MESSAGE_LENGTH = 4096
|
||||
MAX_CAPTION_LENGTH = 200
|
||||
|
||||
# constants above this line are tested
|
||||
|
||||
SUPPORTED_WEBHOOK_PORTS = [443, 80, 88, 8443]
|
||||
MAX_FILESIZE_DOWNLOAD = int(20E6) # (20MB)
|
||||
MAX_FILESIZE_UPLOAD = int(50E6) # (50MB)
|
||||
MAX_MESSAGES_PER_SECOND_PER_CHAT = 1
|
||||
MAX_MESSAGES_PER_SECOND = 30
|
||||
MAX_MESSAGES_PER_MINUTE_PER_GROUP = 20
|
||||
MAX_MESSAGE_ENTITIES = 100
|
||||
+39
-23
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
@@ -15,34 +16,49 @@
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Telegram Contact."""
|
||||
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class Contact(TelegramObject):
|
||||
def __init__(self,
|
||||
phone_number,
|
||||
first_name,
|
||||
last_name=None,
|
||||
user_id=None):
|
||||
self.phone_number = phone_number
|
||||
"""This object represents a Telegram Contact.
|
||||
|
||||
Attributes:
|
||||
phone_number (str):
|
||||
first_name (str):
|
||||
last_name (str):
|
||||
user_id (int):
|
||||
|
||||
Args:
|
||||
phone_number (str):
|
||||
first_name (str):
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
last_name (Optional[str]):
|
||||
user_id (Optional[int]):
|
||||
"""
|
||||
|
||||
def __init__(self, phone_number, first_name, **kwargs):
|
||||
# Required
|
||||
self.phone_number = str(phone_number)
|
||||
self.first_name = first_name
|
||||
self.last_name = last_name
|
||||
self.user_id = user_id
|
||||
# Optionals
|
||||
self.last_name = kwargs.get('last_name', '')
|
||||
self.user_id = int(kwargs.get('user_id', 0))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
return Contact(phone_number=data.get('phone_number', None),
|
||||
first_name=data.get('first_name', None),
|
||||
last_name=data.get('last_name', None),
|
||||
user_id=data.get('user_id', None))
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
def to_dict(self):
|
||||
data = {'phone_number': self.phone_number,
|
||||
'first_name': self.first_name}
|
||||
if self.last_name:
|
||||
data['last_name'] = self.last_name
|
||||
if self.user_id:
|
||||
data['user_id'] = self.user_id
|
||||
return data
|
||||
Returns:
|
||||
telegram.Contact:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return Contact(**data)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import logging
|
||||
|
||||
from future.moves.urllib.parse import quote
|
||||
from future.moves.urllib.error import HTTPError, URLError
|
||||
from future.moves.urllib.request import urlopen, Request
|
||||
|
||||
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||
|
||||
|
||||
class Botan(object):
|
||||
"""This class helps to send incoming events to your botan analytics account.
|
||||
See more: https://github.com/botanio/sdk#botan-sdk
|
||||
"""
|
||||
|
||||
token = ''
|
||||
url_template = 'https://api.botan.io/track?token={token}' \
|
||||
'&uid={uid}&name={name}&src=python-telegram-bot'
|
||||
|
||||
def __init__(self, token):
|
||||
self.token = token
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
def track(self, message, event_name='event'):
|
||||
try:
|
||||
uid = message.chat_id
|
||||
except AttributeError:
|
||||
self.logger.warn('No chat_id in message')
|
||||
return False
|
||||
data = message.to_json()
|
||||
try:
|
||||
url = self.url_template.format(
|
||||
token=str(self.token), uid=str(uid), name=quote(event_name))
|
||||
request = Request(
|
||||
url, data=data.encode(), headers={'Content-Type': 'application/json'})
|
||||
urlopen(request)
|
||||
return True
|
||||
except HTTPError as error:
|
||||
self.logger.warn('Botan track error ' + str(error.code) + ':' + error.read().decode(
|
||||
'utf-8'))
|
||||
return False
|
||||
except URLError as error:
|
||||
self.logger.warn('Botan track error ' + str(error.reason))
|
||||
return False
|
||||
+45
-36
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
@@ -15,46 +16,54 @@
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents a Telegram Document."""
|
||||
|
||||
|
||||
from telegram import TelegramObject
|
||||
from telegram import PhotoSize, TelegramObject
|
||||
|
||||
|
||||
class Document(TelegramObject):
|
||||
def __init__(self,
|
||||
file_id,
|
||||
thumb=None,
|
||||
file_name=None,
|
||||
mime_type=None,
|
||||
file_size=None):
|
||||
self.file_id = file_id
|
||||
self.thumb = thumb
|
||||
self.file_name = file_name
|
||||
self.mime_type = mime_type
|
||||
self.file_size = file_size
|
||||
"""This object represents a Telegram Document.
|
||||
|
||||
Attributes:
|
||||
file_id (str):
|
||||
thumb (:class:`telegram.PhotoSize`):
|
||||
file_name (str):
|
||||
mime_type (str):
|
||||
file_size (int):
|
||||
|
||||
Args:
|
||||
file_id (str):
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
thumb (Optional[:class:`telegram.PhotoSize`]):
|
||||
file_name (Optional[str]):
|
||||
mime_type (Optional[str]):
|
||||
file_size (Optional[int]):
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, **kwargs):
|
||||
# Required
|
||||
self.file_id = str(file_id)
|
||||
# Optionals
|
||||
self.thumb = kwargs.get('thumb')
|
||||
self.file_name = kwargs.get('file_name', '')
|
||||
self.mime_type = str(kwargs.get('mime_type', ''))
|
||||
self.file_size = int(kwargs.get('file_size', 0))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
if 'thumb' in data:
|
||||
from telegram import PhotoSize
|
||||
thumb = PhotoSize.de_json(data['thumb'])
|
||||
else:
|
||||
thumb = None
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
return Document(file_id=data.get('file_id', None),
|
||||
thumb=thumb,
|
||||
file_name=data.get('file_name', None),
|
||||
mime_type=data.get('mime_type', None),
|
||||
file_size=data.get('file_size', None))
|
||||
Returns:
|
||||
telegram.Document:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
def to_dict(self):
|
||||
data = {'file_id': self.file_id}
|
||||
if self.thumb:
|
||||
data['thumb'] = self.thumb.to_dict()
|
||||
if self.file_name:
|
||||
data['file_name'] = self.file_name
|
||||
if self.mime_type:
|
||||
data['mime_type'] = self.mime_type
|
||||
if self.file_size:
|
||||
data['file_size'] = self.file_size
|
||||
return data
|
||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||
|
||||
return Document(**data)
|
||||
|
||||
+878
-844
File diff suppressed because it is too large
Load Diff
+81
-6
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
@@ -15,12 +16,86 @@
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents a Telegram Error."""
|
||||
|
||||
|
||||
def _lstrip_str(in_s, lstr):
|
||||
"""
|
||||
Args:
|
||||
in_s (str): in string
|
||||
lstr (str): substr to strip from left side
|
||||
|
||||
Returns:
|
||||
str:
|
||||
|
||||
"""
|
||||
if in_s.startswith(lstr):
|
||||
res = in_s[len(lstr):]
|
||||
else:
|
||||
res = in_s
|
||||
return res
|
||||
|
||||
|
||||
class TelegramError(Exception):
|
||||
"""Base class for Telegram errors."""
|
||||
"""This object represents a Telegram Error."""
|
||||
|
||||
@property
|
||||
def message(self):
|
||||
'''Returns the first argument used to construct this error.'''
|
||||
return self.args[0]
|
||||
def __init__(self, message):
|
||||
"""
|
||||
Args:
|
||||
message (str):
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
super(TelegramError, self).__init__()
|
||||
|
||||
msg = _lstrip_str(message, 'Error: ')
|
||||
msg = _lstrip_str(msg, '[Error]: ')
|
||||
msg = _lstrip_str(msg, 'Bad Request: ')
|
||||
if msg != message:
|
||||
# api_error - capitalize the msg...
|
||||
msg = msg.capitalize()
|
||||
self.message = msg
|
||||
|
||||
def __str__(self):
|
||||
return '%s' % (self.message)
|
||||
|
||||
|
||||
class Unauthorized(TelegramError):
|
||||
|
||||
def __init__(self):
|
||||
super(Unauthorized, self).__init__('Unauthorized')
|
||||
|
||||
|
||||
class InvalidToken(TelegramError):
|
||||
|
||||
def __init__(self):
|
||||
super(InvalidToken, self).__init__('Invalid token')
|
||||
|
||||
|
||||
class NetworkError(TelegramError):
|
||||
pass
|
||||
|
||||
|
||||
class BadRequest(NetworkError):
|
||||
pass
|
||||
|
||||
|
||||
class TimedOut(NetworkError):
|
||||
|
||||
def __init__(self):
|
||||
super(TimedOut, self).__init__('Timed out')
|
||||
|
||||
|
||||
class ChatMigrated(TelegramError):
|
||||
|
||||
def __init__(self, new_chat_id):
|
||||
"""
|
||||
Args:
|
||||
new_chat_id (int):
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
super(ChatMigrated, self).__init__('Chat migrated')
|
||||
self.new_chat_id = new_chat_id
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""Extensions over the Telegram Bot API to facilitate bot making"""
|
||||
|
||||
from .dispatcher import Dispatcher
|
||||
from .jobqueue import JobQueue, Job
|
||||
from .updater import Updater
|
||||
from .callbackqueryhandler import CallbackQueryHandler
|
||||
from .choseninlineresulthandler import ChosenInlineResultHandler
|
||||
from .commandhandler import CommandHandler
|
||||
from .handler import Handler
|
||||
from .inlinequeryhandler import InlineQueryHandler
|
||||
from .messagehandler import MessageHandler, Filters
|
||||
from .regexhandler import RegexHandler
|
||||
from .stringcommandhandler import StringCommandHandler
|
||||
from .stringregexhandler import StringRegexHandler
|
||||
from .typehandler import TypeHandler
|
||||
from .conversationhandler import ConversationHandler
|
||||
|
||||
__all__ = ('Dispatcher', 'JobQueue', 'Job', 'Updater', 'CallbackQueryHandler',
|
||||
'ChosenInlineResultHandler', 'CommandHandler', 'Handler', 'InlineQueryHandler',
|
||||
'MessageHandler', 'Filters', 'RegexHandler', 'StringCommandHandler',
|
||||
'StringRegexHandler', 'TypeHandler', 'ConversationHandler')
|
||||
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
""" This module contains the CallbackQueryHandler class """
|
||||
|
||||
import re
|
||||
|
||||
from future.utils import string_types
|
||||
|
||||
from telegram import Update
|
||||
from telegram.utils.deprecate import deprecate
|
||||
from .handler import Handler
|
||||
|
||||
|
||||
class CallbackQueryHandler(Handler):
|
||||
"""
|
||||
Handler class to handle Telegram callback queries. Optionally based on a regex.
|
||||
Read the documentation of the ``re`` module for more information.
|
||||
|
||||
Args:
|
||||
callback (function): A function that takes ``bot, update`` as
|
||||
positional arguments. It will be called when the ``check_update``
|
||||
has determined that an update should be processed by this handler.
|
||||
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called
|
||||
``update_queue`` will be passed to the callback function. It will be the ``Queue``
|
||||
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can
|
||||
be used to insert updates. Default is ``False``.
|
||||
pass_job_queue (optional[bool]): If set to ``True``, a keyword argument called
|
||||
``job_queue`` will be passed to the callback function. It will be a ``JobQueue``
|
||||
instance created by the ``Updater`` which can be used to schedule new jobs.
|
||||
Default is ``False``.
|
||||
pattern (optional[str or Pattern]): Optional regex pattern. If not ``None`` ``re.match``
|
||||
is used to determine if an update should be handled by this handler.
|
||||
pass_groups (optional[bool]): If the callback should be passed the
|
||||
result of ``re.match(pattern, data).groups()`` as a keyword
|
||||
argument called ``groups``. Default is ``False``
|
||||
pass_groupdict (optional[bool]): If the callback should be passed the
|
||||
result of ``re.match(pattern, data).groupdict()`` as a keyword
|
||||
argument called ``groupdict``. Default is ``False``
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
callback,
|
||||
pass_update_queue=False,
|
||||
pass_job_queue=False,
|
||||
pattern=None,
|
||||
pass_groups=False,
|
||||
pass_groupdict=False):
|
||||
super(CallbackQueryHandler, self).__init__(
|
||||
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
|
||||
|
||||
if isinstance(pattern, string_types):
|
||||
pattern = re.compile(pattern)
|
||||
|
||||
self.pattern = pattern
|
||||
self.pass_groups = pass_groups
|
||||
self.pass_groupdict = pass_groupdict
|
||||
|
||||
def check_update(self, update):
|
||||
if isinstance(update, Update) and update.callback_query:
|
||||
if self.pattern:
|
||||
if update.callback_query.data:
|
||||
match = re.match(self.pattern, update.callback_query.data)
|
||||
return bool(match)
|
||||
else:
|
||||
return True
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
optional_args = self.collect_optional_args(dispatcher)
|
||||
if self.pattern:
|
||||
match = re.match(self.pattern, update.callback_query.data)
|
||||
|
||||
if self.pass_groups:
|
||||
optional_args['groups'] = match.groups()
|
||||
if self.pass_groupdict:
|
||||
optional_args['groupdict'] = match.groupdict()
|
||||
|
||||
return self.callback(dispatcher.bot, update, **optional_args)
|
||||
|
||||
# old non-PEP8 Handler methods
|
||||
m = "telegram.CallbackQueryHandler."
|
||||
checkUpdate = deprecate(check_update, m + "checkUpdate", m + "check_update")
|
||||
handleUpdate = deprecate(handle_update, m + "handleUpdate", m + "handle_update")
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
""" This module contains the ChosenInlineResultHandler class """
|
||||
|
||||
from .handler import Handler
|
||||
from telegram import Update
|
||||
from telegram.utils.deprecate import deprecate
|
||||
|
||||
|
||||
class ChosenInlineResultHandler(Handler):
|
||||
"""
|
||||
Handler class to handle Telegram updates that contain a chosen inline
|
||||
result.
|
||||
|
||||
Args:
|
||||
callback (function): A function that takes ``bot, update`` as
|
||||
positional arguments. It will be called when the ``check_update``
|
||||
has determined that an update should be processed by this handler.
|
||||
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called
|
||||
``update_queue`` will be passed to the callback function. It will be the ``Queue``
|
||||
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can
|
||||
be used to insert updates. Default is ``False``.
|
||||
pass_job_queue (optional[bool]): If set to ``True``, a keyword argument called
|
||||
``job_queue`` will be passed to the callback function. It will be a ``JobQueue``
|
||||
instance created by the ``Updater`` which can be used to schedule new jobs.
|
||||
Default is ``False``.
|
||||
"""
|
||||
|
||||
def __init__(self, callback, pass_update_queue=False, pass_job_queue=False):
|
||||
super(ChosenInlineResultHandler, self).__init__(
|
||||
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
|
||||
|
||||
def check_update(self, update):
|
||||
return isinstance(update, Update) and update.chosen_inline_result
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
optional_args = self.collect_optional_args(dispatcher)
|
||||
|
||||
return self.callback(dispatcher.bot, update, **optional_args)
|
||||
|
||||
# old non-PEP8 Handler methods
|
||||
m = "telegram.ChosenInlineResultHandler."
|
||||
checkUpdate = deprecate(check_update, m + "checkUpdate", m + "check_update")
|
||||
handleUpdate = deprecate(handle_update, m + "handleUpdate", m + "handle_update")
|
||||
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
""" This module contains the CommandHandler class """
|
||||
|
||||
from .handler import Handler
|
||||
from telegram import Update
|
||||
from telegram.utils.deprecate import deprecate
|
||||
|
||||
|
||||
class CommandHandler(Handler):
|
||||
"""
|
||||
Handler class to handle Telegram commands. Commands are Telegram messages
|
||||
that start with ``/``, optionally followed by an ``@`` and the bot's
|
||||
name and/or some additional text.
|
||||
|
||||
Args:
|
||||
command (str): The name of the command this handler should listen for.
|
||||
callback (function): A function that takes ``bot, update`` as
|
||||
positional arguments. It will be called when the ``check_update``
|
||||
has determined that an update should be processed by this handler.
|
||||
allow_edited (Optional[bool]): If the handler should also accept edited messages.
|
||||
Default is ``False``
|
||||
pass_args (optional[bool]): If the handler should be passed the
|
||||
arguments passed to the command as a keyword argument called `
|
||||
``args``. It will contain a list of strings, which is the text
|
||||
following the command split on single or consecutive whitespace characters.
|
||||
Default is ``False``
|
||||
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called
|
||||
``update_queue`` will be passed to the callback function. It will be the ``Queue``
|
||||
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can
|
||||
be used to insert updates. Default is ``False``.
|
||||
pass_job_queue (optional[bool]): If set to ``True``, a keyword argument called
|
||||
``job_queue`` will be passed to the callback function. It will be a ``JobQueue``
|
||||
instance created by the ``Updater`` which can be used to schedule new jobs.
|
||||
Default is ``False``.
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
command,
|
||||
callback,
|
||||
allow_edited=False,
|
||||
pass_args=False,
|
||||
pass_update_queue=False,
|
||||
pass_job_queue=False):
|
||||
super(CommandHandler, self).__init__(
|
||||
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
|
||||
self.command = command
|
||||
self.allow_edited = allow_edited
|
||||
self.pass_args = pass_args
|
||||
|
||||
def check_update(self, update):
|
||||
if (isinstance(update, Update)
|
||||
and (update.message or update.edited_message and self.allow_edited)):
|
||||
message = update.message or update.edited_message
|
||||
|
||||
return (message.text and message.text.startswith('/')
|
||||
and message.text[1:].split(' ')[0].split('@')[0] == self.command)
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
optional_args = self.collect_optional_args(dispatcher)
|
||||
|
||||
message = update.message or update.edited_message
|
||||
|
||||
if self.pass_args:
|
||||
optional_args['args'] = message.text.split()[1:]
|
||||
|
||||
return self.callback(dispatcher.bot, update, **optional_args)
|
||||
|
||||
# old non-PEP8 Handler methods
|
||||
m = "telegram.CommandHandler."
|
||||
checkUpdate = deprecate(check_update, m + "checkUpdate", m + "check_update")
|
||||
handleUpdate = deprecate(handle_update, m + "handleUpdate", m + "handle_update")
|
||||
@@ -0,0 +1,225 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
""" This module contains the ConversationHandler """
|
||||
|
||||
import logging
|
||||
|
||||
from telegram import Update
|
||||
from telegram.ext import Handler
|
||||
from telegram.utils.promise import Promise
|
||||
|
||||
|
||||
class ConversationHandler(Handler):
|
||||
"""
|
||||
A handler to hold a conversation with a user by managing four collections of other handlers.
|
||||
|
||||
The first collection, a ``list`` named ``entry_points``, is used to initiate the conversation,
|
||||
for example with a ``CommandHandler`` or ``RegexHandler``.
|
||||
|
||||
The second collection, a ``dict`` named ``states``, contains the different conversation steps
|
||||
and one or more associated handlers that should be used if the user sends a message when the
|
||||
conversation with them is currently in that state. You will probably use mostly
|
||||
``MessageHandler`` and ``RegexHandler`` here.
|
||||
|
||||
The third collection, a ``list`` named ``fallbacks``, is used if the user is currently in a
|
||||
conversation but the state has either no associated handler or the handler that is associated
|
||||
to the state is inappropriate for the update, for example if the update contains a command, but
|
||||
a regular text message is expected. You could use this for a ``/cancel`` command or to let the
|
||||
user know their message was not recognized.
|
||||
|
||||
The fourth, optional collection of handlers, a ``list`` named ``timed_out_behavior`` is used if
|
||||
the wait for ``run_async`` takes longer than defined in ``run_async_timeout``. For example,
|
||||
you can let the user know that they should wait for a bit before they can continue.
|
||||
|
||||
To change the state of conversation, the callback function of a handler must return the new
|
||||
state after responding to the user. If it does not return anything (returning ``None`` by
|
||||
default), the state will not change. To end the conversation, the callback function must
|
||||
return ``CallbackHandler.END`` or ``-1``.
|
||||
|
||||
Args:
|
||||
entry_points (list): A list of ``Handler`` objects that can trigger the start of the
|
||||
conversation. The first handler which ``check_update`` method returns ``True`` will be
|
||||
used. If all return ``False``, the update is not handled.
|
||||
states (dict): A ``dict[object: list[Handler]]`` that defines the different states of
|
||||
conversation a user can be in and one or more associated ``Handler`` objects that
|
||||
should be used in that state. The first handler which ``check_update`` method returns
|
||||
``True`` will be used.
|
||||
fallbacks (list): A list of handlers that might be used if the user is in a conversation,
|
||||
but every handler for their current state returned ``False`` on ``check_update``.
|
||||
The first handler which ``check_update`` method returns ``True`` will be used. If all
|
||||
return ``False``, the update is not handled.
|
||||
allow_reentry (Optional[bool]): If set to ``True``, a user that is currently in a
|
||||
conversation can restart the conversation by triggering one of the entry points.
|
||||
run_async_timeout (Optional[float]): If the previous handler for this user was running
|
||||
asynchronously using the ``run_async`` decorator, it might not be finished when the
|
||||
next message arrives. This timeout defines how long the conversation handler should
|
||||
wait for the next state to be computed. The default is ``None`` which means it will
|
||||
wait indefinitely.
|
||||
timed_out_behavior (Optional[list]): A list of handlers that might be used if
|
||||
the wait for ``run_async`` timed out. The first handler which ``check_update`` method
|
||||
returns ``True`` will be used. If all return ``False``, the update is not handled.
|
||||
|
||||
"""
|
||||
|
||||
END = -1
|
||||
|
||||
def __init__(self,
|
||||
entry_points,
|
||||
states,
|
||||
fallbacks,
|
||||
allow_reentry=False,
|
||||
run_async_timeout=None,
|
||||
timed_out_behavior=None):
|
||||
|
||||
self.entry_points = entry_points
|
||||
""":type: list[telegram.ext.Handler]"""
|
||||
|
||||
self.states = states
|
||||
""":type: dict[str: telegram.ext.Handler]"""
|
||||
|
||||
self.fallbacks = fallbacks
|
||||
""":type: list[telegram.ext.Handler]"""
|
||||
|
||||
self.allow_reentry = allow_reentry
|
||||
self.run_async_timeout = run_async_timeout
|
||||
|
||||
self.timed_out_behavior = timed_out_behavior
|
||||
""":type: list[telegram.ext.Handler]"""
|
||||
|
||||
self.conversations = dict()
|
||||
""":type: dict[(int, int): str]"""
|
||||
|
||||
self.current_conversation = None
|
||||
self.current_handler = None
|
||||
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
def check_update(self, update):
|
||||
|
||||
if not isinstance(update, Update):
|
||||
return False
|
||||
|
||||
user = None
|
||||
chat = None
|
||||
|
||||
if update.message:
|
||||
user = update.message.from_user
|
||||
chat = update.message.chat
|
||||
|
||||
elif update.edited_message:
|
||||
user = update.edited_message.from_user
|
||||
chat = update.edited_message.chat
|
||||
|
||||
elif update.inline_query:
|
||||
user = update.inline_query.from_user
|
||||
|
||||
elif update.chosen_inline_result:
|
||||
user = update.chosen_inline_result.from_user
|
||||
|
||||
elif update.callback_query:
|
||||
user = update.callback_query.from_user
|
||||
chat = update.callback_query.message.chat if update.callback_query.message else None
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
key = (chat.id, user.id) if chat else (None, user.id)
|
||||
state = self.conversations.get(key)
|
||||
|
||||
# Resolve promises
|
||||
if isinstance(state, tuple) and len(state) is 2 and isinstance(state[1], Promise):
|
||||
self.logger.debug('waiting for promise...')
|
||||
|
||||
old_state, new_state = state
|
||||
new_state.result(timeout=self.run_async_timeout)
|
||||
|
||||
if new_state.done.is_set():
|
||||
self.update_state(new_state.result(), key)
|
||||
state = self.conversations.get(key)
|
||||
|
||||
else:
|
||||
for candidate in (self.timed_out_behavior or []):
|
||||
if candidate.check_update(update):
|
||||
# Save the current user and the selected handler for handle_update
|
||||
self.current_conversation = key
|
||||
self.current_handler = candidate
|
||||
|
||||
return True
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
self.logger.debug('selecting conversation %s with state %s' % (str(key), str(state)))
|
||||
|
||||
handler = None
|
||||
|
||||
# Search entry points for a match
|
||||
if state is None or self.allow_reentry:
|
||||
for entry_point in self.entry_points:
|
||||
if entry_point.check_update(update):
|
||||
handler = entry_point
|
||||
break
|
||||
|
||||
else:
|
||||
if state is None:
|
||||
return False
|
||||
|
||||
# Get the handler list for current state, if we didn't find one yet and we're still here
|
||||
if state is not None and not handler:
|
||||
handlers = self.states.get(state)
|
||||
|
||||
for candidate in (handlers or []):
|
||||
if candidate.check_update(update):
|
||||
handler = candidate
|
||||
break
|
||||
|
||||
# Find a fallback handler if all other handlers fail
|
||||
else:
|
||||
for fallback in self.fallbacks:
|
||||
if fallback.check_update(update):
|
||||
handler = fallback
|
||||
break
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
# Save the current user and the selected handler for handle_update
|
||||
self.current_conversation = key
|
||||
self.current_handler = handler
|
||||
|
||||
return True
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
|
||||
new_state = self.current_handler.handle_update(update, dispatcher)
|
||||
|
||||
self.update_state(new_state, self.current_conversation)
|
||||
|
||||
def update_state(self, new_state, key):
|
||||
if new_state == self.END:
|
||||
if key in self.conversations:
|
||||
del self.conversations[key]
|
||||
else:
|
||||
pass
|
||||
|
||||
elif isinstance(new_state, Promise):
|
||||
self.conversations[key] = (self.conversations.get(key), new_state)
|
||||
|
||||
elif new_state is not None:
|
||||
self.conversations[key] = new_state
|
||||
@@ -0,0 +1,376 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the Dispatcher class."""
|
||||
|
||||
import logging
|
||||
import weakref
|
||||
from functools import wraps
|
||||
from threading import Thread, Lock, Event, current_thread, BoundedSemaphore
|
||||
from time import sleep
|
||||
from uuid import uuid4
|
||||
|
||||
from queue import Queue, Empty
|
||||
|
||||
from future.builtins import range
|
||||
|
||||
from telegram import TelegramError
|
||||
from telegram.ext.handler import Handler
|
||||
from telegram.utils.deprecate import deprecate
|
||||
from telegram.utils.promise import Promise
|
||||
|
||||
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||
""":type: set[Thread]"""
|
||||
DEFAULT_GROUP = 0
|
||||
|
||||
|
||||
def run_async(func):
|
||||
"""Function decorator that will run the function in a new thread.
|
||||
|
||||
Using this decorator is only possible when only a single Dispatcher exist in the system.
|
||||
|
||||
Args:
|
||||
func (function): The function to run in the thread.
|
||||
async_queue (Queue): The queue of the functions to be executed asynchronously.
|
||||
|
||||
Returns:
|
||||
function:
|
||||
|
||||
"""
|
||||
|
||||
@wraps(func)
|
||||
def async_func(*args, **kwargs):
|
||||
return Dispatcher.get_instance().run_async(func, *args, **kwargs)
|
||||
|
||||
return async_func
|
||||
|
||||
|
||||
class Dispatcher(object):
|
||||
"""
|
||||
This class dispatches all kinds of updates to its registered handlers.
|
||||
|
||||
Args:
|
||||
bot (telegram.Bot): The bot object that should be passed to the
|
||||
handlers
|
||||
update_queue (Queue): The synchronized queue that will contain the
|
||||
updates.
|
||||
job_queue (Optional[telegram.ext.JobQueue]): The ``JobQueue`` instance to pass onto handler
|
||||
callbacks
|
||||
workers (Optional[int]): Number of maximum concurrent worker threads for the ``@run_async``
|
||||
decorator
|
||||
|
||||
"""
|
||||
__singleton_lock = Lock()
|
||||
__singleton_semaphore = BoundedSemaphore()
|
||||
__singleton = None
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def __init__(self, bot, update_queue, workers=4, exception_event=None, job_queue=None):
|
||||
self.bot = bot
|
||||
self.update_queue = update_queue
|
||||
self.job_queue = job_queue
|
||||
|
||||
self.handlers = {}
|
||||
""":type: dict[int, list[Handler]"""
|
||||
self.groups = []
|
||||
""":type: list[int]"""
|
||||
self.error_handlers = []
|
||||
|
||||
self.running = False
|
||||
self.__stop_event = Event()
|
||||
self.__exception_event = exception_event or Event()
|
||||
self.__async_queue = Queue()
|
||||
self.__async_threads = set()
|
||||
|
||||
# For backward compatibility, we allow a "singleton" mode for the dispatcher. When there's
|
||||
# only one instance of Dispatcher, it will be possible to use the `run_async` decorator.
|
||||
with self.__singleton_lock:
|
||||
if self.__singleton_semaphore.acquire(blocking=0):
|
||||
self._set_singleton(self)
|
||||
else:
|
||||
self._set_singleton(None)
|
||||
|
||||
self._init_async_threads(uuid4(), workers)
|
||||
|
||||
@classmethod
|
||||
def _reset_singleton(cls):
|
||||
# NOTE: This method was added mainly for test_updater benefit and specifically pypy. Never
|
||||
# call it in production code.
|
||||
cls.__singleton_semaphore.release()
|
||||
|
||||
def _init_async_threads(self, base_name, workers):
|
||||
base_name = '{}_'.format(base_name) if base_name else ''
|
||||
|
||||
for i in range(workers):
|
||||
thread = Thread(target=self._pooled, name='{}{}'.format(base_name, i))
|
||||
self.__async_threads.add(thread)
|
||||
thread.start()
|
||||
|
||||
@classmethod
|
||||
def _set_singleton(cls, val):
|
||||
cls.logger.debug('Setting singleton dispatcher as %s', val)
|
||||
cls.__singleton = weakref.ref(val) if val else None
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls):
|
||||
"""Get the singleton instance of this class.
|
||||
|
||||
Returns:
|
||||
Dispatcher
|
||||
|
||||
"""
|
||||
if cls.__singleton is not None:
|
||||
return cls.__singleton()
|
||||
else:
|
||||
raise RuntimeError('{} not initialized or multiple instances exist'.format(
|
||||
cls.__name__))
|
||||
|
||||
def _pooled(self):
|
||||
"""
|
||||
A wrapper to run a thread in a thread pool
|
||||
"""
|
||||
thr_name = current_thread().getName()
|
||||
while 1:
|
||||
promise = self.__async_queue.get()
|
||||
|
||||
# If unpacking fails, the thread pool is being closed from Updater._join_async_threads
|
||||
if not isinstance(promise, Promise):
|
||||
self.logger.debug("Closing run_async thread %s/%d", thr_name,
|
||||
len(self.__async_threads))
|
||||
break
|
||||
|
||||
try:
|
||||
promise.run()
|
||||
|
||||
except:
|
||||
self.logger.exception("run_async function raised exception")
|
||||
|
||||
def run_async(self, func, *args, **kwargs):
|
||||
"""Queue a function (with given args/kwargs) to be run asynchronously.
|
||||
|
||||
Args:
|
||||
func (function): The function to run in the thread.
|
||||
args (Optional[tuple]): Arguments to `func`.
|
||||
kwargs (Optional[dict]): Keyword arguments to `func`.
|
||||
|
||||
Returns:
|
||||
Promise
|
||||
|
||||
"""
|
||||
# TODO: handle exception in async threads
|
||||
# set a threading.Event to notify caller thread
|
||||
promise = Promise(func, args, kwargs)
|
||||
self.__async_queue.put(promise)
|
||||
return promise
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Thread target of thread 'dispatcher'. Runs in background and processes
|
||||
the update queue.
|
||||
"""
|
||||
|
||||
if self.running:
|
||||
self.logger.warning('already running')
|
||||
return
|
||||
|
||||
if self.__exception_event.is_set():
|
||||
msg = 'reusing dispatcher after exception event is forbidden'
|
||||
self.logger.error(msg)
|
||||
raise TelegramError(msg)
|
||||
|
||||
self.running = True
|
||||
self.logger.debug('Dispatcher started')
|
||||
|
||||
while 1:
|
||||
try:
|
||||
# Pop update from update queue.
|
||||
update = self.update_queue.get(True, 1)
|
||||
except Empty:
|
||||
if self.__stop_event.is_set():
|
||||
self.logger.debug('orderly stopping')
|
||||
break
|
||||
elif self.__exception_event.is_set():
|
||||
self.logger.critical('stopping due to exception in another thread')
|
||||
break
|
||||
continue
|
||||
|
||||
self.logger.debug('Processing Update: %s' % update)
|
||||
self.process_update(update)
|
||||
|
||||
self.running = False
|
||||
self.logger.debug('Dispatcher thread stopped')
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops the thread
|
||||
"""
|
||||
if self.running:
|
||||
self.__stop_event.set()
|
||||
while self.running:
|
||||
sleep(0.1)
|
||||
self.__stop_event.clear()
|
||||
|
||||
# async threads must be join()ed only after the dispatcher thread was joined,
|
||||
# otherwise we can still have new async threads dispatched
|
||||
threads = list(self.__async_threads)
|
||||
total = len(threads)
|
||||
|
||||
# Stop all threads in the thread pool by put()ting one non-tuple per thread
|
||||
for i in range(total):
|
||||
self.__async_queue.put(None)
|
||||
|
||||
for i, thr in enumerate(threads):
|
||||
self.logger.debug('Waiting for async thread {0}/{1} to end'.format(i + 1, total))
|
||||
thr.join()
|
||||
self.__async_threads.remove(thr)
|
||||
self.logger.debug('async thread {0}/{1} has ended'.format(i + 1, total))
|
||||
|
||||
@property
|
||||
def has_running_threads(self):
|
||||
return self.running or bool(self.__async_threads)
|
||||
|
||||
def process_update(self, update):
|
||||
"""
|
||||
Processes a single update.
|
||||
|
||||
Args:
|
||||
update (object):
|
||||
"""
|
||||
|
||||
# An error happened while polling
|
||||
if isinstance(update, TelegramError):
|
||||
self.dispatch_error(None, update)
|
||||
|
||||
else:
|
||||
for group in self.groups:
|
||||
for handler in self.handlers[group]:
|
||||
try:
|
||||
if handler.check_update(update):
|
||||
handler.handle_update(update, self)
|
||||
break
|
||||
# Dispatch any errors
|
||||
except TelegramError as te:
|
||||
self.logger.warn('A TelegramError was raised while processing the '
|
||||
'Update.')
|
||||
|
||||
try:
|
||||
self.dispatch_error(update, te)
|
||||
except Exception:
|
||||
self.logger.exception('An uncaught error was raised while '
|
||||
'handling the error')
|
||||
finally:
|
||||
break
|
||||
|
||||
# Errors should not stop the thread
|
||||
except Exception:
|
||||
self.logger.exception('An uncaught error was raised while '
|
||||
'processing the update')
|
||||
break
|
||||
|
||||
def add_handler(self, handler, group=DEFAULT_GROUP):
|
||||
"""
|
||||
Register a handler.
|
||||
|
||||
TL;DR: Order and priority counts. 0 or 1 handlers per group will be
|
||||
used.
|
||||
|
||||
A handler must be an instance of a subclass of
|
||||
telegram.ext.Handler. All handlers are organized in groups with a
|
||||
numeric value. The default group is 0. All groups will be evaluated for
|
||||
handling an update, but only 0 or 1 handler per group will be used.
|
||||
|
||||
The priority/order of handlers is determined as follows:
|
||||
|
||||
* Priority of the group (lower group number == higher priority)
|
||||
|
||||
* The first handler in a group which should handle an update will be
|
||||
used. Other handlers from the group will not be used. The order in
|
||||
which handlers were added to the group defines the priority.
|
||||
|
||||
Args:
|
||||
handler (Handler): A Handler instance
|
||||
group (Optional[int]): The group identifier. Default is 0
|
||||
"""
|
||||
|
||||
if not isinstance(handler, Handler):
|
||||
raise TypeError('handler is not an instance of {0}'.format(Handler.__name__))
|
||||
if not isinstance(group, int):
|
||||
raise TypeError('group is not int')
|
||||
|
||||
if group not in self.handlers:
|
||||
self.handlers[group] = list()
|
||||
self.groups.append(group)
|
||||
self.groups = sorted(self.groups)
|
||||
|
||||
self.handlers[group].append(handler)
|
||||
|
||||
def remove_handler(self, handler, group=DEFAULT_GROUP):
|
||||
"""
|
||||
Remove a handler from the specified group
|
||||
|
||||
Args:
|
||||
handler (Handler): A Handler instance
|
||||
group (optional[object]): The group identifier. Default is 0
|
||||
"""
|
||||
if handler in self.handlers[group]:
|
||||
self.handlers[group].remove(handler)
|
||||
if not self.handlers[group]:
|
||||
del self.handlers[group]
|
||||
self.groups.remove(group)
|
||||
|
||||
def add_error_handler(self, callback):
|
||||
"""
|
||||
Registers an error handler in the Dispatcher.
|
||||
|
||||
Args:
|
||||
handler (function): A function that takes ``Bot, Update,
|
||||
TelegramError`` as arguments.
|
||||
"""
|
||||
|
||||
self.error_handlers.append(callback)
|
||||
|
||||
def remove_error_handler(self, callback):
|
||||
"""
|
||||
De-registers an error handler.
|
||||
|
||||
Args:
|
||||
handler (function):
|
||||
"""
|
||||
|
||||
if callback in self.error_handlers:
|
||||
self.error_handlers.remove(callback)
|
||||
|
||||
def dispatch_error(self, update, error):
|
||||
"""
|
||||
Dispatches an error.
|
||||
|
||||
Args:
|
||||
update (object): The update that caused the error
|
||||
error (telegram.TelegramError): The Telegram error that was raised.
|
||||
"""
|
||||
|
||||
for callback in self.error_handlers:
|
||||
callback(self.bot, update, error)
|
||||
|
||||
# old non-PEP8 Dispatcher methods
|
||||
m = "telegram.dispatcher."
|
||||
addHandler = deprecate(add_handler, m + "AddHandler", m + "add_handler")
|
||||
removeHandler = deprecate(remove_handler, m + "removeHandler", m + "remove_handler")
|
||||
addErrorHandler = deprecate(add_error_handler, m + "addErrorHandler", m + "add_error_handler")
|
||||
removeErrorHandler = deprecate(remove_error_handler, m + "removeErrorHandler",
|
||||
m + "remove_error_handler")
|
||||
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
""" This module contains the base class for handlers as used by the
|
||||
Dispatcher """
|
||||
|
||||
from telegram.utils.deprecate import deprecate
|
||||
|
||||
|
||||
class Handler(object):
|
||||
"""
|
||||
The base class for all update handlers. You can create your own handlers
|
||||
by inheriting from this class.
|
||||
|
||||
Args:
|
||||
callback (function): A function that takes ``bot, update`` as
|
||||
positional arguments. It will be called when the ``check_update``
|
||||
has determined that an update should be processed by this handler.
|
||||
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called
|
||||
``update_queue`` will be passed to the callback function. It will be the ``Queue``
|
||||
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can
|
||||
be used to insert updates. Default is ``False``.
|
||||
pass_job_queue (optional[bool]): If set to ``True``, a keyword argument called
|
||||
``job_queue`` will be passed to the callback function. It will be a ``JobQueue``
|
||||
instance created by the ``Updater`` which can be used to schedule new jobs.
|
||||
Default is ``False``.
|
||||
"""
|
||||
|
||||
def __init__(self, callback, pass_update_queue=False, pass_job_queue=False):
|
||||
self.callback = callback
|
||||
self.pass_update_queue = pass_update_queue
|
||||
self.pass_job_queue = pass_job_queue
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
This method is called to determine if an update should be handled by
|
||||
this handler instance. It should always be overridden.
|
||||
|
||||
Args:
|
||||
update (object): The update to be tested
|
||||
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
This method is called if it was determined that an update should indeed
|
||||
be handled by this instance. It should also be overridden, but in most
|
||||
cases call ``self.callback(dispatcher.bot, update)``, possibly along with
|
||||
optional arguments. To work with the ``ConversationHandler``, this method should return the
|
||||
value returned from ``self.callback``
|
||||
|
||||
Args:
|
||||
update (object): The update to be handled
|
||||
dispatcher (Dispatcher): The dispatcher to collect optional args
|
||||
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def collect_optional_args(self, dispatcher):
|
||||
"""
|
||||
Prepares the optional arguments that are the same for all types of
|
||||
handlers
|
||||
|
||||
Args:
|
||||
dispatcher (Dispatcher):
|
||||
"""
|
||||
optional_args = dict()
|
||||
if self.pass_update_queue:
|
||||
optional_args['update_queue'] = dispatcher.update_queue
|
||||
if self.pass_job_queue:
|
||||
optional_args['job_queue'] = dispatcher.job_queue
|
||||
|
||||
return optional_args
|
||||
|
||||
# old non-PEP8 Handler methods
|
||||
m = "telegram.Handler."
|
||||
checkUpdate = deprecate(check_update, m + "checkUpdate", m + "check_update")
|
||||
handleUpdate = deprecate(handle_update, m + "handleUpdate", m + "handle_update")
|
||||
collectOptionalArgs = deprecate(collect_optional_args, m + "collectOptionalArgs",
|
||||
m + "collect_optional_args")
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user