Can you help me?
I don't know how to add reactions as like\dislike to any message in my telegram bot with written by Node.JS
The problem is I don't know how to change query.message.message_id because message_id every time is different on other chats.
How to count like\dislike I don't know yet too.
Can someone explain to me how to do it well?
Thanks
bot.on('callback_query', query => {
const chatID = query.message.chat.id
switch (query.data) {
case 'good':
console.log(query)
User.find({}).then(users => {
for(var i=0; i < users.length; i++){
var pars = users[i]
bot.editMessageReplyMarkup({
inline_keyboard: [
[
{
text: 'π1',
callback_data: 'good'
},
{
text: 'π',
callback_data: 'bad'
}
]
]
}, {chat_id: pars.telegramId, message_id: query.message.message_id}).catch(e => console.log(e))
}
})
break
case 'bad':
break
}
})
Here for you: π
const helpKeyboard = [[{
text: `back`,
callback_data: `back3`
}]]
bot.on('callback_query', msg => {
if (msg.data == `back3`) {
bot.editMessageText(`?`, {
parse_mode: 'Markdown',
message_id: msg.message.message_id,
chat_id: msg.message.chat.id,
reply_markup: {
inline_keyboard: [[{
text: `π`,
callback_data: `?`
}]]
}
})
}
}
Related
Right now I am able to fetch the data and show in the table in front side, but I need
help to implement the code for skip, limit, searching, sorting and pagination so everything will be a functional.
I looked over the internet but didn't find good source to implement, I hope this might
help others in future. Anyoneβs help will be appreciated.
**javascript code**
$(document).ready(function() {
let table = $('#exportable_table').DataTable({
"processing": true,
"searching": true,
"serverSide": true,
"ajax": {
url:"/employee/data-table/get-data",
error:(error)=>{
console.log(error);
}
},
'columns': [
{ data: '_id' },
{ data: 'employee_name' },
{ data: 'gender' },
{ data: 'email' },
{ data: 'mobile_number' },
{ data: 'salary' },
{ data: 'created_at' },
{ data: 'updated_at' },
{ data: '', "defaultContent": "<button class='btn btn-primary' onclick='edititem();'>Edit</button>" },
{ data: '', "defaultContent": "<button class='btn btn-danger' onclick='deleteitem();'>Delete</button>"}
],
});
});
**backend side logic**
employeeDataTableData: async (req, res) => {
let employeeData = await EmployeeService.getEmployee();
var response = {
"draw": parseInt(req.query.draw),
"iTotalRecords": employeeData.length,
"iTotalDisplayRecords": 2,
"data": employeeData
}
res.status(200).send(response);
}
**logic to fetch data from database**
exports.getEmployee = async () => {
try {
let employeeData = await EmployeeModel.find().lean();
if (!employeeData) return false;
return employeeData;
} catch (error) {
console.log("Error : ", error);
}
};
I have a Slack command which displays a button. When I click on this button I need to display a modal. For this, after clicking it I do this:
const dialog = {
callback_id: "submit-ticket",
elements: [
{
hint: "30 second summary of the problem",
label: "Title",
name: "title",
type: "text",
value: "teste"
},
{
label: "Description",
name: "description",
optional: true,
type: "textarea"
},
{
label: "Urgency",
name: "urgency",
options: [
{ label: "Low", value: "Low" },
{ label: "Medium", value: "Medium" },
{ label: "High", value: "High" }
],
type: "select"
}
],
submit_label: "Submit",
title: "Submit a helpdesk ticket"
};
const modalInfo = {
dialog: JSON.stringify(dialog),
token, // this is correct
trigger_id: actionJSONPayload.trigger_id
};
// This is what I get confused with...
// Method 1
slack.dialog.open(modalInfo).catch(err => {
console.log("ERROR: ", err);
});
// end method 1
// Method 2
sendMessageToSlackResponseURL(actionJSONPayload.response_url, modalInfo);
...
function sendMessageToSlackResponseURL(responseURL: any, JSONmessage: any) {
const postOptions = {
headers: {
"Content-type": "application/json"
},
json: JSONmessage,
method: "POST",
uri: responseURL
};
request(postOptions, (error: any, response: any, body: any) => {
if (error) {
console.log("----Error: ", error);
}
});
}
// end method 2
I get always Error: invalid_trigger using method1 when this trigger is something that my button is generating automatically.
Method 2 doesn't throw any error but doesn't open any modal/dialog either.
The official documentation is not quite clear and I don't know if I need to call dialog.open or views.open. Either way, the last one is not available from Slack package
This is also the button I'm displaying before anything:
const message = {
attachments: [
{
actions: [
{
name: "send_sms",
style: "danger",
text: "Yes",
type: "button",
value: "yes"
},
{
name: "no",
text: "No",
type: "button",
value: "no"
}
],
attachment_type: "default",
callback_id: "alert",
color: "#3AA3E3",
fallback: "We could not load the options. Try later",
text: "Do you want to alert by SMS about P1 error/fix?"
}
],
text: "P1 SMSs"
};
Copy a modal from here
const headers = {
headers: {
"Content-type": "application/json; charset=utf-8",
"Authorization": "Bearer " + token
}
};
const modalInfo = {
"token": token,
"trigger_id": reqBody.trigger_id,
"view": slack.modal
};
axios
.post("https://slack.com/api/views.open", modalInfo, headers)
.then(response => {
const data = response.data;
if (!data.ok) {
return data.error;
}
})
.catch(error => {
console.log("-Error: ", error);
});
But most importantly, when we do some changes to our app we need to reinstall it and also when we do it, the token changes and this is something I couldn't find on the documentation
I'm using Elasticsearch js to make a search engine, like so:
let jobs = await client.search({
index: 'index',
type: 'doc',
body: {
query: {
bool: {
must: [
{
match: {
title: 'test'
}
}
]
}
}
}
});
if the title has 'test' in it , it will show, but when it has something like 'hello this is/test' it wont show up, how do I fix it?
You can surround the string with *:
let jobs = await client.search({
index: 'index',
type: 'doc',
body: {
query: {
bool: {
must: [
{
match: {
title: '*test*'
}
}
]
}
}
}
});
i am new to botpress and trying to make simple order bot with botpress. but not using messenger,etc just trying to make simple question answer bot. in available example on github uses content.yml but it gives error
[Renderer] Renderer not defined (#welcome)
at /Applications/MAMP/htdocs/botpress-pro-nightly-2018-12-24-darwin-x64/pizza/node_modules/botpress/src/renderers/index.js:163:13
index.js
module.exports = bp => {
Object.keys(renderers).forEach(name => {
bp.renderers.register(name, renderers[name])
})
bp.hear(/GET_STARTED|hello|hi|test|hey|holla/i, (event, next) => {
console.log(event);
event.reply('#welcome')
var yes=event.welcome.quick_replies[0].payload;
bp.logger.info('answer:', yes);
})
}
so i use this type of code in renderers.js it works but not able to fetch reply
module.exports = {
text: data => {
return {text: data.text, typing: !!data.typing}
},
'#welcome': data => ({
typing: true,
text: 'Hey there! Would you like to order?',
quick_replies: [
{
content_type: 'text',
title: 'Yes',
payload: 'Y'
},
{
content_type: 'text',
title: 'No',
payload: 'N'
}
],
}) ,
'#askLocation': data => ({
typing: true,
text: 'Please click this button for me to know where you are!',
quick_replies: [
{
content_type: 'location',
title: 'location',
payload: 'location'
}
],
})
}
I can request user's one-time location using Telegraf framework:
bot.start(ctx =>
const keyboard = Extra.markup(markup =>
markup
.resize()
.keyboard([
markup.contactRequestButton('Give phone number'),
markup.locationRequestButton('Give location')
])
)
ctx.replyWithMarkdown('a message to user', keyboard)
)
Is there any way to request live location instead?
i hope it helps:
bot.onText(/^\/place_order/, function (msg, match) {
var option = {
"parse_mode": "Markdown",
"reply_markup": {
"one_time_keyboard": true,
"keyboard": [[{
text: "My phone number",
request_contact: true
}], ["Cancel"]]
}
};
bot.sendMessage(msg.chat.id, "How can we contact you?", option).then(() => {
bot.once("contact",(msg)=>{
var option = {
"parse_mode": "Markdown",
"reply_markup": {
"one_time_keyboard": true,
"keyboard": [[{
text: "My location",
request_location: true
}], ["Cancel"]]
}
};
bot.sendMessage(msg.chat.id,
util.format('Thank you %s with phone %s! And where are you?', msg.contact.first_name, msg.contact.phone_number),
option)
.then(() => {
bot.once("location",(msg)=>{
bot.sendMessage(msg.chat.id, "We will deliver your order to " + [msg.location.longitude,msg.location.latitude].join(";"));
})
})
})
})