First, you need to create the apiChatApi asynchronous function that will have two parameters: the method called, and the parameter object used to call the method. This is how it should look: module.exports = ` Ĭonst apiResponse = await fetch(url, options) Ĭonst jsonResponse = await apiResponse.json() Next, go to the config.js file and specify your URL for requests (in quotation marks) and your token - you can get them in your user account. Now use the npm install command to set the necessary dependencies (libraries) for your bot. Detailed instructions on how to upload a bot and get a Webhook can be found at the end of the guide.Ĭreate a messengersBot folder and clone (or simply download) files from the Git repository into it. Docker hosting is available to our customers free of charge. We added the code in the repository with the bot's docker deployment and a description of the docker files. Accordingly, for the bot to work, we need a server - which will receive and process this data. WebHook URL is a link where it will be sent by POST method, JSON data with information about incoming messages or notifications. For the server to call our script at new messages, it is necessary to specify WebHook URL. The Chat-Api service allows for setting up a webhook that will send information about new messages (and more) to your webserver. Then open messengers on your mobile phone, go to Settings -> messengers Web -> Scan QR Code. To do this, we go to a personal account and get a QR code there. In the beginning, let's link messengers with our script at once to check its work as we write the code. Sending GPS coordinates (latitude and longitude)Īn important note: For the bot to work, the phone must always be connected to the Internet and must not be used for messengers Web.Sending files of different formats (pdf, jpg, doc, mp3, etc.). Outputting the name of the user chatting with the bot.Outputting the current chat ID (in either private or group messages).In our example, we will try to cover the basic, most frequently used functionality, such as: The bot will respond to the commands it receives as normal messengers messages and respond to them. In this guide, we will explain how to develop a messengers bot on Node JS using our messengers API gateway. Now the Chat API offers the most accessible and automated messengers Business API on the market with Multi-Agent messengers Inbox, No-Code Chatbot Builder, ready-to-use apps integrations and other features. Please read the documentation before starting work. The functionality from this guide has been transferred to the messengers Business API, with which you can also make mailings, create chat bots and much more, but without the risk of being blocked.ĭue to changes in the working conditions of the API, this guide may partially use outdated information.
0 Comments
Leave a Reply. |