optimalstrategy / sms_forwarder_app

An app for forwarding SMS messages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not use Http Callback Forwarder

phontuan opened this issue · comments

Hi. I tried using "HTTP Callback Forwarder", I see the request to the link.
But I don't receive the message content. Can anyone help me?. Thanks

@phontuan If I understand correctly, you see the request on your backend, but there's no message content? Could you please share more information with me:

  1. Did you give the app the permission to read SMS messages?
  2. How is your HTTP fowrarder configured, are you using a POST/PUT request? If you're using GET, your HTTP client may be hiding the request body from you.
  3. If you go to the settings (the green gear icon) and click Send Test Message, does the HTTP Forwarder entry turn green or red? If it is green, do you still not see the message content?

@optimalstrategy Hi, Thank you for your help

  1. I have given the app permission to read SMS messages
  2. I use method POST
  3. I tried sending test message ( ins ettings "the green gear icon" ) I received a request, But I don't receive the message content. HTTP Forwarder entry turn green I still not see the message content
    You can check help me. Thanks

@phontuan The settings flash green only if the app receives a 2XX response from the endpoint, which means that your backend successfully receives the request, indeed.

What programming language and framework are you using on your backend? Is it Express.js by any chance? If that's the case, I believe this could be happening because I'm not setting the Content-Type header to application/json; instead, it's text/plain by default. I have two suggestions:

  1. First, you can override the Content-Type header by going to HTTP Callback Forwarder -> Headers and setting the key to Content-Type and the value to application/json. Don't forget to press save! This should override the header to make it work with most frameworks that attempt to parse request bodies automatically.
  2. Alternatively, if you're using Express, you could you try adding app.use(bodyParser.text()); as a workaround and manually parsing the body as JSON. Please see the below for an example.
import express from "express";
import bodyParser from "body-parser";

const app = express();

app.use(bodyParser.text()); // parse text/plain bodies

app.post('/', async (req, res) => {
    const textBody = req.body;
    const jsonBody = JSON.parse(textBody);
    console.log(jsonBody);
    res.send(jsonBody);
});

app.listen(3000);

If the solutions above don't work, could try installing WireShark or, if you're on Linux, tcpdump, and using it to monitor the traffic on the app's port? If you can see the request body, that means that the problem is likely in the header being set to text/plain. Here's example output from my local testing:

$ sudo tcpdump -A -vvv port 3000
01:08:22.125281 IP (tos 0x0, ttl 64, id 56484, offset 0, flags [DF], proto TCP (6), length 488)
    server.sunproxyadmin > 111.111.111.111.54160: Flags [P.], cksum 0x8341 (incorrect -> 0x3218), seq 1:437, ack 364, 
win 507, options [nop,nop,TS val 921669208 ecr 3434738436], length 436
E.....@.@......
..........7._..T.....A.....
6......qPOST /? HTTP/1.1
user-agent: Dart/2.14 (dart:io)
content-type: text/plain; charset=utf-8
accept-encoding: gzip
content-length: 200
host: 111.111.111.111:3000

{"id":"null","address":"SmsForwarder","body":"Test message","date":"1658898305188","dateSent":"null","read":"null","seen":"null","subject":"null","subscriptionId":"null","type":"null","status":"null"}

@optimalstrategy Hi. Thanks for your help I solved the problem. Thanks

@phontuan I'm glad I could help. Thanks for checking out the app.