Ivan Climov

Ivan Climov

  • 1k
  • 692
  • 22.6k

Viber-API. I get the error message "Bad receiver ID".

Jun 27 2019 10:30 AM
  1. Created an application.
    I try to get information on the "bot".
    I get the following information:

2. I try to send a message to user "members.1".
 
I use:
- language - C#;
- WinForm;
- recommendations - https://developers.viber.com/docs/api/rest-bot-api/#send-message;
- for "Receiver": "01234567890A =" I use "id" from item.1 -> picture 4 -> id

I use the code.
  1.    class ViberMessage  
  2. {  
  3.     public string Receiver { getset; }  
  4.     ///   
  5.     /// Minimum API version required by clients for this message (default 1)  
  6.     ///   
  7.     public int Min_api_version { getset; } = 1;  
  8.     public ViberSender Sender { getset; }  
  9.     public string Tracking_data { getset; }  
  10.     public string Type { getset; } = "text";  
  11.     public string Text { getset; }  
  12.   
  13. }  
  14.   
  15. public class ViberSender  
  16. {  
  17.     public string Name { getset; }  
  18.     public string Avatar { getset; }  
  19. }  
  20.   
  21.   
  22.   
  23. ///   
  24. ///  Send a message. Member Account.  
  25. ///   
  26. ///    
  27. ///    
  28. private void bt_SendMessMemb_Click(object sender, EventArgs e)  
  29. {     
  30.     string json = FillMember_2();  
  31.   
  32.     Encoding utf = Encoding.UTF8;  
  33.   
  34.     byte[] jsonUTF = utf.GetBytes(json);  
  35.     string jsonUTFstr = utf.GetString(jsonUTF);  
  36.   
  37.     MessageWork messageWork = new MessageWork();          
  38.     messageWork.ViberCall(jsonUTFstr);  
  39. }  
  40.   
  41.   
  42. public string FillMember_2()  
  43. {  
  44.     string json = "";  
  45.             var msg = new ViberMessage  
  46.         {  
  47.             Receiver = "?u7L???+wyD/?????????=="// text conditionally hidden  
  48.             Min_api_version = 1,  
  49.             Sender = new ViberSender  
  50.             {  
  51.                         Name = "?????",  
  52.                         Avatar = ""  
  53.             },  
  54.             Tracking_data = "tracking data",  
  55.             Type = "text",  
  56.             Text = "Test message - 1"  
  57.         };  
  58.   
  59.         json = JsonConvert.SerializeObject(msg);  
  60.     return json;  
  61. }  
  62.   
  63.   
  64.   
  65. class MessageWork  
  66. {  
  67.     public void ViberCall(string json)          
  68.     {  
  69.         var request = (HttpWebRequest)WebRequest.Create("https://chatapi.viber.com/pa/send_message");  
  70.         request.ContentType = "application/json";  
  71.         request.Method = "POST";                          
  72.         request.Headers.Add("X-Viber-Auth-Token""49c9a7b9a9e7d096-XXXXXXXXXXXX-XXXXXXXXX"); // text conditionally hidden  
  73.   
  74.         using (var streamWriter = new StreamWriter(request.GetRequestStream()))  
  75.         {  
  76.             streamWriter.Write(jsonN);  
  77.             streamWriter.Flush();  
  78.         }  
  79.   
  80.         string resultStr;  
  81.   
  82.         var response = (HttpWebResponse)request.GetResponse();  
  83.         using (var streamReader = new StreamReader(response.GetResponseStream()))  
  84.         {  
  85.             var result = streamReader.ReadToEnd();  
  86.   
  87.             resultStr = result.ToString();  
  88.         }  
  89.   
  90.         jsonN = jsonN + "/r/n "  + resultStr;         
  91.     }  
  92. }  
In the line "jsonN = jsonN +" \ r \ n "+ resultStr; " I get
  1. {"Receiver":"?u7L???+wyD/?????????==", // text conditionally hidden    
  2. "Min_api_version":1,    
  3. "Sender":{"Name":"?????","Avatar":""},    
  4. "Tracking_data":"tracking data","Type":"text",    
  5. "Text":"???????? ????????? - 1"}    
  6.     
  7.  {"status":999,    
  8.  "status_message":"Bad receiver ID",    
  9.  "message_token":5324763260407665007,    
  10.  "chat_hostname":"SN-CHAT-05_"}   
Question.
1. Why do I get the error "status_message": "Bad receiver ID"?
2. How to extinguish this error?