DEV Community

Senthil Pitchappan V
Senthil Pitchappan V

Posted on

Viber API

Steps

  1. Login to your account using your mobile number Link
  2. Create a bot account
  3. After which, you will get a Private Token
  4. Go to your Viber on your mobile (the account where you created the bot)
  5. Verify your mail ID and have a profile picture in your account.
  6. More -> Settings -> My Bots -> Select your bot which you created -> Click publish.
  7. More -> Settings -> My Bots -> Select your bot which you created -> Message -> Select Viber Chat API.
  8. Set Webhook Link
curl --location --request POST 'https://chatapi.viber.com/pa/set_webhook' \
--header 'X-Viber-Auth-Token: VIBER_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
   "url":"WEBHOOK_URL"
}'
Enter fullscreen mode Exit fullscreen mode

Only when you set a webhook link, your bot will get activated.

Points to Note:

  1. Only when a user sends message to a bot, you will be able to reply.
  2. You can send message to a user only using user's id (not using user's mobile number)

Changes you should make

  1. VIBER_ACCESS_TOKEN - From Viber Admin Panel
  2. USER'S ID - Received From Webhook

Send Text Message

curl --location --request POST 'https://chatapi.viber.com/pa/send_message' \
--header 'X-Viber-Auth-Token: VIBER_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
   "receiver":"USERS_ID",
   "type":"text",
   "text":"Hello"
}'
Enter fullscreen mode Exit fullscreen mode

Send Picture

curl --location --request POST 'https://chatapi.viber.com/pa/send_message' \
--header 'X-Viber-Auth-Token: VIBER_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
   "receiver":"USERS_ID",
   "type":"picture",
   "text":"Photo description",
   "media":"http://www.images.com/img.jpg",
   "thumbnail":"http://www.images.com/thumb.jpg"
}'
Enter fullscreen mode Exit fullscreen mode

Send Video

curl --location --request POST 'https://chatapi.viber.com/pa/send_message' \
--header 'X-Viber-Auth-Token: VIBER_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
   "receiver":"USERS_ID",
   "type":"video",
   "media":"http://www.images.com/video.mp4",
   "thumbnail":"http://www.images.com/thumb.jpg",
   "size":10000
}'
Enter fullscreen mode Exit fullscreen mode

Send File

curl --location --request POST 'https://chatapi.viber.com/pa/send_message' \
--header 'X-Viber-Auth-Token: VIBER_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
   "receiver":"USERS_ID",
   "type":"file",
   "media":"http://www.images.com/file.doc",
   "size":10000,
   "file_name":"name_of_file.doc"
}'
Enter fullscreen mode Exit fullscreen mode

Send Contact

curl --location --request POST 'https://chatapi.viber.com/pa/send_message' \
--header 'X-Viber-Auth-Token: VIBER_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
   "receiver":"USERS_ID",
   "type":"contact",
   "contact":{
      "name":"Itamar",
      "phone_number":"+91965XXXXXX"
   }
}'
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️