Home > OS >  How to send data in one message to a telegram bot?
How to send data in one message to a telegram bot?

Time:12-20

Now I'm making a method, after which the data is successfully sent from the telegram bot to the user. Now I have made this option. However, the problem is that all data is sent separately.

And if we assume we have 20 books in the matrix, we get 21 messages with customer data.

How can I make everything is sent in one message?

private void Form_DataAddAfter(ref SAPbouiCOM.BusinessObjectInfo pVal)
        {
            SAPbouiCOM.EditText oEdit_Customer = (SAPbouiCOM.EditText)this.GetItem("4").Specific;
            SAPbouiCOM.EditText oEdit_Name = (SAPbouiCOM.EditText)this.GetItem("54").Specific;
            SAPbouiCOM.EditText oEdit_PostingDate = (SAPbouiCOM.EditText)this.GetItem("10").Specific;
            SAPbouiCOM.EditText oEdit_Total = (SAPbouiCOM.EditText)this.GetItem("29").Specific;

            SendTextMessage(($"Return of the book!\n\nCustomer: {oEdit_Customer.Value}\nCustomer's name: {oEdit_Name.Value}\nReturn date: {oEdit_PostingDate.Value}\nTotal: {oEdit_Total.Value} "));
           
 for (int j = 1; j < Matrix0.RowCount-1; j  )
            {
                SAPbouiCOM.EditText cell_Description = (SAPbouiCOM.EditText)Matrix0.Columns.Item("1").Cells.Item(j).Specific;
                SAPbouiCOM.EditText cell_Quantity = (SAPbouiCOM.EditText)Matrix0.Columns.Item("U_inUseQuantity").Cells.Item(j).Specific;

                SendTextMessage(($"Book: {cell_Description.Value}\nQuantity: {cell_Quantity.Value}"));
            }
        }

CodePudding user response:

Not tested this code but should work. Store your "messages" in a string variable add the strings you are currently sending to it. You can then send the string "sendText" after the loop

    string sendText = "";
    for (int j = 1; j < Matrix0.RowCount-1; j  )
    {
        SAPbouiCOM.EditText cell_Description = (SAPbouiCOM.EditText)Matrix0.Columns.Item("1").Cells.Item(j).Specific;
        SAPbouiCOM.EditText cell_Quantity = (SAPbouiCOM.EditText)Matrix0.Columns.Item("U_inUseQuantity").Cells.Item(j).Specific;

        sendText  = $"Book: {cell_Description.Value}\nQuantity: {cell_Quantity.Value}\n";
    }
    SendTextMessage(sendText);
  • Related