This Post is based on NAV 2018 but it should be working as well in Business Central, you just need to change from using Http Web Request Mgt. to HttpClient. The sample is using Telegram API and this post will be part of article “Dynamics NAV Approval integration with telegram”.
The scenario for this sample is when user send approval , system will automatically send the PDF file contain the information of the document to the telegram message from Bot . You can check https://core.telegram.org/bots/api to learn more about telegram bot.
Before begin , you can read this article first to get more understanding about Multipart/Form Web Request.
First we will create one function SendRequestFile with DocumetNo Parameter to specify which document need to send. Using Form Data you need to set the Content Type to “multipart/form-data;boundary=myboundary”. Myboundary can be set to any string you want , this will be used as separator of each field inside the form.
Next you need to save the PDF Report to outstream , once it had been completed ,generate the InStream for this PDF to be included in the web request later.
Then Construct the message with –YourBoundaryName followed by Newline Character, to create a new line in this sample i am using TypeHelper codeunit . name=”document” is the field name of the field, this is based on the Telegram API Docs.
For the rest , you can just follow the screenshot for the complete string need to build. Next we copy the Stream of the PDF File using COPYSTREAM function to the request stream.
Final result will be like below . The PDF file will be sent to to the user together with approval notification. So you need to call SendDocument function right after you sent approval notification message.