{"id":298146,"date":"2020-02-03T21:00:10","date_gmt":"2020-02-03T21:00:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=298146"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=298146","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e Viberbot \u043d\u0430 Django 2 \u0438 Viber REST API. \u0427\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u0430\u044f \u2014 Webhook"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/486826\/\">\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Webhook \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b bot \u043d\u0430 viber \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u0435\u0440\u0432\u043e\u0433\u043e POST \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a backend \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0430<\/h3>\n<p>  \u041e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u0441\u0432\u043e\u0439 \u043e\u043f\u044b\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u0434 Viber \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u0445 \u043c\u043d\u0435\u043d\u0438\u0439, \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0443 viberbot. \u0414\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u044f \u043f\u043e\u043b\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u0432 \u0446\u0435\u043b\u043e\u043c, \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0447\u0438\u0441\u0442\u044b\u043c REST API VIBER, \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445 \u043b\u0438\u0431\u043e \u043e\u0431\u0435\u0440\u0442\u043e\u043a. <br \/>  <a href=\"https:\/\/botviber.ru\/radio\" rel=\"nofollow\">\u0420\u0430\u0434\u0438\u043e\u0432\u0430\u0439\u0431\u0435\u0440<\/a> \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0441\u0435\u0431\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432\u044b\u0439 \u0431\u043e\u0442 (<s>\u043a\u043e\u0438\u0445 \u043c\u043d\u043e\u0433\u043e \u0442\u044b\u0441\u044f\u0447 \u0440\u0430\u0437\u0432\u0435\u043b\u043e\u0441\u044c \u0432 telegram<\/s>). <br \/>  \u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0443\u0432\u0438\u0434\u0438\u043c \u0432\u0441\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 botviber \u0438 \u043f\u043e\u0439\u043c\u0435\u043c: \u0447\u0435\u043c\u0443 \u0432 \u0420\u043e\u0441\u0441\u0438\u0438 \u043b\u0435\u0433\u0447\u0435 \u0431\u044b\u0442\u044c \u2014 botviber VS bottelegram, \u0433\u043b\u0430\u0432\u043d\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0431\u043e\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u044d\u0442\u0438\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c.<\/p>\n<p>  \u0421\u0442\u0430\u0442\u044c\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0441c\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432, \u043a\u0442\u043e \u043d\u0435 \u0443\u0441\u043f\u0435\u043b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 REST API Viber.<\/p>\n<p>  \u0412 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0441\u044f\u0446\u0430 \u043f\u043e 1-2 tutorial \u0432 \u043d\u0435\u0434\u0435\u043b\u044e \u043a\u0442\u043e \u0437\u0430\u0445\u043e\u0447\u0435\u0442, \u0442\u043e\u0442 \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u0442\u044b \u043d\u0430 \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0435 Viber, \u0431\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c. <br \/>  \u0422\u0430\u043a\u0436\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u0443\u0447\u0430\u0442\u044c Django, \u043a\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u043d\u0430\u0447\u0430\u043b \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0432 develop \u0438 production \u0440\u0435\u0436\u0438\u043c\u0430\u0445.<\/p>\n<h4>\u041d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0431\u043e\u0442\u0430 \u2014 \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u0447\u043d\u0435\u043c:<\/h4>\n<p><a name=\"habracut\"><\/a><\/p>\n<p>  1. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c Django &gt;= 2.1 \u0438 Python &gt;=3.6.<br \/>   \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 myviberbot \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430 Django:<br \/>   python manage.py startapp myviberbot<\/p>\n<p>  \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u043d\u0435\u0441\u0442\u0438 \u0435\u0433\u043e \u0432 \u0444\u0430\u0439\u043b settings.py \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b:  <\/p>\n<pre><code class=\"python\"># \u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 settings.py   DEBUG = True  ALLOWED_HOSTS = ['*']  # Application definition  INSTALLED_APPS = [     'django.contrib.admin',     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.messages',     'django.contrib.staticfiles',     'myviberbot', # \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f ] # <\/code><\/pre>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u044f \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043b \u0441\u0432\u043e\u0439 HTTPS \u0434\u043e\u043c\u0435\u043d \u0438 \u0445\u043e\u0447\u0443 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c webhook \u0434\u043b\u044f viber-bot \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443:<br \/>  <a href=\"https:\/\/yourdomain.ru\/webhook2020\" rel=\"nofollow\">yourdomain.ru\/webhook2020<\/a> \u2014 \u0410 \u0432\u044b \u043c\u0435\u043d\u044f\u0439\u0442\u0435 yourdomain.ru \u043d\u0430 \u0441\u0432\u043e\u0439 \u0434\u043e\u043c\u0435\u043d \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u0418 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u0441\u0435\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0431\u0443\u0434\u0435\u043c \u0432\u0435\u0441\u0442\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 def trx_bot() \u0438\u0437 myviberbot.views \u2014 \u043d\u043e \u043e \u043d\u0435\u0439 \u0434\u0430\u043b\u0435\u0435\u2026<\/p>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u043d\u0435\u0441\u0451\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 \u0444\u0430\u0439\u043b urls.py \u0432 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 \u0435\u0433\u043e \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435:   <\/p>\n<pre><code class=\"python\"># urls.py from django.contrib import admin from django.urls import path from myviberbot.views import trx_bot from django.conf import settings from django.conf.urls.static import static  urlpatterns = [     path('admin\/', admin.site.urls),     path('webhook2020', trx_bot),     ] <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0435 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0438 Django \u2014 \u0442\u0443\u0442, \u0432 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435, \u043c\u044b \u043d\u0430\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b (request) \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 webhook2020 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e trx_bot, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0430 \u0432 \u043f\u0430\u043f\u043a\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 myviberbot \u0432 \u0444\u0430\u0439\u043b\u0435 views.py. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0433\u043e \u043d\u0438\u0436\u0435.<\/p>\n<pre><code class=\"python\"># views.py \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 myviberbot  from django.shortcuts import HttpResponse from django.views.decorators.csrf import csrf_exempt  @csrf_exempt def trx_bot(request):     if request.method == &quot;POST&quot;:         viber = json.loads(request.body.decode('utf-8'))         if viber['event'] == 'webhook':             print(viber)             print(&quot;Webhook \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d&quot;)             return HttpResponse(status=200)         else:             print(&quot;\u042d\u0442\u043e \u043d\u0435 Webhook - \u043f\u0440\u043e\u0431\u0443\u0439 \u0435\u0449\u0435 \u0440\u0430\u0437, \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 POSTMAN&quot;)              return HttpResponse(status=500)         return HttpResponse(status=200) <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f 200 \u041e\u041a \u043e\u0442 \u043d\u0430\u0441 \u2014 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 backend viber \u0433\u043e\u0442\u043e\u0432\u044b \u0441 \u043d\u0430\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. <br \/>  \u0412\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0430\u043c \u0432 \u043c\u0435\u0441\u0441\u0435\u0434\u0436\u0435\u0440 \u0432 \u0447\u0430\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430 (\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0438\u043b\u0438 Chat 1to1 added)<\/p>\n<p>  \u041d\u043e \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c POST-\u0437\u0430\u043f\u0440\u043e\u0441 \u043a backend Viber \u0438\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c Webhook \u2014 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0432\u043e\u043b\u043d\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u0438\u0445, \u043a\u0442\u043e \u043f\u0440\u0438\u0432\u044b\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 telegram, \u043c\u0435\u0442\u043e\u0434\u043e\u043c get, \u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0433\u043e \u2014 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0438\u0442\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435:<\/p>\n<p>  2. \u042f \u0443\u0432\u0435\u0440\u0435\u043d \u0447\u0442\u043e \u043a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443, \u0432\u044b \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0442\u043e\u043a\u0435\u043d \u0431\u043e\u0442\u0430 <a href=\"https:\/\/partners.viber.com\/login\" rel=\"nofollow\">\u0442\u0443\u0442<\/a> \u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 django \u043d\u0430 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435 (<a href=\"https:\/\/firstvds.ru\/?from=477602\" rel=\"nofollow\">VDS<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/beget.com\/p514592\" rel=\"nofollow\">Shared<\/a>) \u0438\u043b\u0438 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435 (\u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0442\u0443\u043d\u043d\u0435\u043b\u044c ngrok),<br \/>   a) \u0415\u0441\u043b\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435, \u0442\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430 \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u043c \u0435\u0433\u043e:<br \/>  python manage.py runserver<br \/>  \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0441\u0442\u0430\u0440\u0442\u0430 \u2014 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c ngrok.<\/p>\n<p>   \u0431) \u0410 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435 \u043d\u0443 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u2014 \u043b\u0438\u0447\u043d\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e passenger \u043d\u0430 beget. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 beget, \u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0432\u0435\u0440\u0441\u0438\u044e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0441 php5.6 \u043d\u0435 \u0432\u044b\u0448\u0435 \u2014 \u044d\u0442\u043e \u0441\u043e\u0432\u0435\u0442 \u043e\u0442 beget\u043e\u0432\u0446\u0435\u0432.<\/p>\n<h4>\u0418\u0442\u0430\u043a \u2014 \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u043e\u0441\u044c \u2014 \u0441\u0442\u0430\u0432\u0438\u043c webhook<br \/>  <\/h4>\n<p>  \u041a\u0442\u043e \u0443\u043c\u0435\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c POSTMAN \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f Chrome \u2014 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0430\u0431\u0437\u0430\u0446, \u0438 \u043f\u043e\u0441\u043b\u0430\u0442\u044c POST \u0434\u043b\u044f webhook \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430.<\/p>\n<p>  \u041c\u044b \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441 \u043b\u044e\u0431\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 sethook.py, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043f\u0440\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 requests (pip install requests)<\/p>\n<pre><code class=\"python\">#sethook import requests import json auth_token = 'xxxxxxxxx-ttttttttttttttttt-wwwwwwwwwwww' # \u0442\u0443\u0442 \u0432\u0430\u0448 \u0442\u043e\u043a\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 #\u043f.2 hook = 'https:\/\/chatapi.viber.com\/pa\/set_webhook' headers = {'X-Viber-Auth-Token': auth_token}   sen = dict(url='https:\/\/yourdomain.ru\/webhook2020',            event_types = ['unsubscribed', 'conversation_started', 'message', 'seen', 'delivered'])  #seen, delivered - \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u0430\u0440\u043a\u0435\u0442\u043e\u043b\u043e\u0433\u0438 \u0445\u043e\u0442\u044f\u0442 \u0437\u043d\u0430\u0442\u044c, #\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438 \u043a\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e  \u043f\u0440\u0438\u043d\u044f\u043b \u0438 \u043f\u043e\u0447\u0438\u0442\u0430\u043b \u0432\u0430\u0448\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439,  \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c)  r = requests.post(hook, json.dumps(sen), headers=headers)  print(r.json()) <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u0441 \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430:<br \/>  python sethook.py<\/p>\n<p>  \u0412\u043e\u0442 \u0438 \u0412\u0441\u0451! Webhook \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u043e\u043c POST. \u0412\u044b \u0432\u0438\u0434\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0430\u043c \u0432 \u0447\u0430\u0442 (\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430), \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e webhook \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d.<\/p>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442\u2026<\/p>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c event[\u00abconversation_started\u00bb], \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u0430 \u0441 \u043d\u0438\u043c\u0438, \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435 \u0447\u0442\u043e \u0432\u0430\u0448 viberbot \u0437\u043d\u0430\u0435\u0442 \u043e\u0431\u043e \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445 \u0438 \u0447\u0435\u0433\u043e \u043e\u043d \u043d\u0435 \u0437\u043d\u0430\u0435\u0442. <\/p>\n<p>  (\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e Viberbot \u043d\u0430 Django 2 \u0438 Viber REST API. \u0427\u0430\u0441\u0442\u044c \u0432\u0442\u043e\u0440\u0430\u044f \u2014 \u0421onversation_started)<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/486826\/\"> https:\/\/habr.com\/ru\/post\/486826\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/486826\/\">\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Webhook \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b bot \u043d\u0430 viber \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u0435\u0440\u0432\u043e\u0433\u043e POST \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a backend \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0430<\/h3>\n<p>  \u041e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u0441\u0432\u043e\u0439 \u043e\u043f\u044b\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u0434 Viber \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u0445 \u043c\u043d\u0435\u043d\u0438\u0439, \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0443 viberbot. \u0414\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u044f \u043f\u043e\u043b\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u0432 \u0446\u0435\u043b\u043e\u043c, \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0447\u0438\u0441\u0442\u044b\u043c REST API VIBER, \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445 \u043b\u0438\u0431\u043e \u043e\u0431\u0435\u0440\u0442\u043e\u043a. <br \/>  <a href=\"https:\/\/botviber.ru\/radio\" rel=\"nofollow\">\u0420\u0430\u0434\u0438\u043e\u0432\u0430\u0439\u0431\u0435\u0440<\/a> \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0441\u0435\u0431\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432\u044b\u0439 \u0431\u043e\u0442 (<s>\u043a\u043e\u0438\u0445 \u043c\u043d\u043e\u0433\u043e \u0442\u044b\u0441\u044f\u0447 \u0440\u0430\u0437\u0432\u0435\u043b\u043e\u0441\u044c \u0432 telegram<\/s>). <br \/>  \u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0443\u0432\u0438\u0434\u0438\u043c \u0432\u0441\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 botviber \u0438 \u043f\u043e\u0439\u043c\u0435\u043c: \u0447\u0435\u043c\u0443 \u0432 \u0420\u043e\u0441\u0441\u0438\u0438 \u043b\u0435\u0433\u0447\u0435 \u0431\u044b\u0442\u044c \u2014 botviber VS bottelegram, \u0433\u043b\u0430\u0432\u043d\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0431\u043e\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u044d\u0442\u0438\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c.<\/p>\n<p>  \u0421\u0442\u0430\u0442\u044c\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0441c\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432, \u043a\u0442\u043e \u043d\u0435 \u0443\u0441\u043f\u0435\u043b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 REST API Viber.<\/p>\n<p>  \u0412 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0441\u044f\u0446\u0430 \u043f\u043e 1-2 tutorial \u0432 \u043d\u0435\u0434\u0435\u043b\u044e \u043a\u0442\u043e \u0437\u0430\u0445\u043e\u0447\u0435\u0442, \u0442\u043e\u0442 \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u0442\u044b \u043d\u0430 \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0435 Viber, \u0431\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c. <br \/>  \u0422\u0430\u043a\u0436\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u0443\u0447\u0430\u0442\u044c Django, \u043a\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u043d\u0430\u0447\u0430\u043b \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0432 develop \u0438 production \u0440\u0435\u0436\u0438\u043c\u0430\u0445.<\/p>\n<h4>\u041d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0431\u043e\u0442\u0430 \u2014 \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u0447\u043d\u0435\u043c:<\/h4>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-298146","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=298146"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298146\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=298146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=298146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=298146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}