Comments (11)
Which Messaging Service are you using?
from botman.
Which Messaging Service are you using?
Are you talking about the driver? In that case it's web driver initially, next it will be Facebook messenger driver.
from botman.
Try using this example as starting point to make an instance working with the Web Driver:
from botman.
How do I pass the message to the user id or chat session?
from botman.
Almost all BotMan drivers send messages in response to an HTTP request. That request contains all the information that BotMan needs to send the response, including the user id or chat session. So, to answer a user message you only need:
$botman->hears('Hi', function (BotMan $bot) {
$bot->reply('Hello!');
});
from botman.
Sorry, I think I may have misunderstood. I need to respond to a message from another server via a web service. What would I need to respond in a specific conversation?
from botman.
Using the current version of the web widget you cannot send a message to the user outside an HTTP request initiated by the user. To implement an async functionality you could use a websocket server or some kind of pulling system.
With services like Telegram and Messenger you can do it as follows:
- Instantiate the driver with the correct configuration
- Build the payload accordingly to the service (i.e. check Messenger official documentation). The payload will include data such as the message, the session user ID, etc.
- Call the sendPayload() method on the driver instance.
from botman.
Thank you, I was using WebDriver for testing. I will use Facebook as you say
from botman.
2. Messenger official documentation
I have this code, but it'snot working:
Messenger official documentation
Using the current version of the web widget you cannot send a message to the user outside an HTTP request initiated by the user. To implement an async functionality you could use a websocket server or some kind of pulling system.
With services like Telegram and Messenger you can do it as follows:
- Instantiate the driver with the correct configuration
- Build the payload accordingly to the service (i.e. check Messenger official documentation). The payload will include data such as the message, the session user ID, etc.
- Call the sendPayload() method on the driver instance.
I have this code, but it's not working:
try {
$botman = app('botman');
$accessToken = '***';
$recipientId = '***';
$payload = [
'access_token' => $accessToken,
'recipient' => ['id' => $recipientId],
'message' => ['text' => 'Hello, world!']
];
$botman->sendPayload($payload);
Log::info('Payload sent successfully.');
return response()->json(['status' => 'success']);
} catch (\Exception $e) {
Log::error('Error sending payload: ' . $e->getMessage());
return response()->json(['status' => 'error', 'message' => $e->getMessage()], 500);
}
Laravel log doesn't show anything, only the successful sent message
from botman.
You are not following the provided instructions.
- You are not "instantiating the driver with the correct configuration", you are just creating an instance of the driver.
This is the driver you have to instantiate: https://github.com/botman/driver-facebook/blob/master/src/FacebookDriver.php
- Build the payload accordingly to the service
Here you can find an example of payload: https://github.com/botman/driver-facebook/blob/master/src/FacebookDriver.php#L370
As you can see, and as per Messenger documentation, you are missing fields like messaging_type.
- Call the sendPayload() method on the driver instance.
You are calling the sendPayload() method on BotMan not on the driver.
from botman.
using the driver instance, should it be something like this?:
public function handle()
{
try {
$botman = app('botman');
$facebookDriver = $botman->getDriver(\BotMan\Drivers\Facebook\FacebookDriver::class);
if ($facebookDriver && $facebookDriver instanceof FacebookDriver) {
$recipient = '1**';
$message = 'hello world';
$payload = [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => $recipient
],
'message' => [
'text' => $message
]
];
$facebookDriver->sendPayload($payload);
Log::info('Payload sent successfully to recipient: ' . $recipient);
return response()->json(['status' => 'success']);
} else {
Log::error('Failed to retrieve Facebook driver or driver is not an instance of FacebookDriver.');
return response()->json(['status' => 'error', 'message' => 'Failed to retrieve Facebook driver.'], 500);
}
} catch (\Exception $e) {
Log::error('Error sending payload: ' . $e->getMessage());
return response()->json(['status' => 'error', 'message' => $e->getMessage()], 500);
}
}
api.php:
Route::post('/botman', [BotManController::class, 'handle']);
from botman.
Related Issues (20)
- Invalid URL to access Slack channel HOT 2
- cURL error 60: SSL: no alternative certificate subject name matches target host name 'graph.facebook.co' HOT 7
- Bad Request: invalid user_id specified HOT 8
- Issue using botman commands with wit ai commands (intents)
- CallBackData button inline - Driver Telegram botman
- FacebookDriven verification error HOT 1
- Conversation lost when reload page HOT 5
- What are the limitations on Botman's regex capabilities? HOT 1
- Fatal error: Uncaught Error: Class "DriverManager" not found
- Is this package suite still maintained? HOT 1
- Need Laravel 11 Support HOT 1
- Telegram Bot Driver Issue HOT 3
- Sending message using a Facebook driver instance HOT 1
- Ubuntu Apache2 returns 408 HOT 6
- How many times BuildPayload method should be called? HOT 1
- Bot Commands Not Executing on First Attempt HOT 4
- Receive data back when use Botman->say HOT 3
- Is this project abandoned? HOT 5
- Handle answers in Inertia Vue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from botman.